Skip to content

Commit 4401876

Browse files
committed
Support for multilanguage installations
1 parent c14347e commit 4401876

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Alt Text Review",
44
"license": "MIT",
55
"type": "kirby-plugin",
6-
"version": "1.0.0",
6+
"version": "1.1.0",
77
"authors": [
88
{
99
"name": "Thomas Günther",

index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,37 @@
4444
$page = (int)$request->get('page', 1);
4545
$limit = 100; // Fixed limit as requested
4646

47+
// Get current language from panel
48+
$currentLanguage = kirby()->language();
49+
$languageCode = $currentLanguage ? $currentLanguage->code() : null;
50+
4751
// Collect all images
4852
$allImages = [];
4953
$pages = site()->index();
5054

5155
foreach ($pages as $sitePage) {
5256
if ($sitePage->hasImages()) {
5357
foreach ($sitePage->images() as $image) {
58+
// Get alt text for current language
59+
$altText = '';
60+
if ($languageCode) {
61+
$altText = $image->alt()->translation($languageCode)->value() ?? '';
62+
} else {
63+
$altText = $image->alt()->value() ?? '';
64+
}
65+
5466
$allImages[] = [
5567
'id' => $image->id(),
5668
'url' => $image->url(),
5769
'filename' => $image->filename(),
58-
'alt' => $image->alt()->value() ?? '',
70+
'alt' => $altText,
5971
'alt_reviewed' => $image->alt_reviewed()->toBool(),
6072
'panelUrl' => $image->panel()->url(),
6173
'pageUrl' => $image->page()->url(),
6274
'pageTitle' => $sitePage->title()->value(),
6375
'pageId' => $sitePage->id(),
6476
'pagePanelUrl' => $sitePage->panel()->url(),
77+
'language' => $languageCode,
6578
];
6679
}
6780
}
@@ -99,7 +112,6 @@
99112
$field = $request->body()->get('field');
100113
$value = $request->body()->get('value');
101114

102-
103115
if (!in_array($field, ['alt', 'alt_reviewed'])) {
104116
return ['error' => t('medienbaecker.alt-text-review.invalidField')];
105117
}
@@ -110,7 +122,17 @@
110122
return ['error' => t('medienbaecker.alt-text-review.imageNotFound')];
111123
}
112124

113-
$image->update([$field => $value]);
125+
// Get current language for saving
126+
$currentLanguage = kirby()->language();
127+
$languageCode = $currentLanguage ? $currentLanguage->code() : null;
128+
129+
// Save to specific language if multilingual site
130+
if ($languageCode && $field === 'alt') {
131+
$image->update([$field => $value], $languageCode);
132+
} else {
133+
$image->update([$field => $value]);
134+
}
135+
114136
return ['success' => true, 'message' => t('medienbaecker.alt-text-review.success')];
115137
} catch (Exception $e) {
116138
return ['error' => $e->getMessage()];

src/components/AltTextReview.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
:theme="isComplete ? 'positive' : null">
1212
{{ `${reviewedImagesCount}/${totalImagesCount}` }}
1313
</k-button>
14+
<k-button v-if="currentLanguage" element="span" variant="filled" size="sm">
15+
{{ currentLanguage.toUpperCase() }}
16+
</k-button>
1417
</template>
1518
</k-header>
1619

@@ -94,13 +97,33 @@ export default {
9497
9598
hasAnyChanges() {
9699
return Object.keys(this.currentImages).some(imageId => this.hasChanges(imageId));
100+
},
101+
102+
currentLanguage() {
103+
// Get current language from panel
104+
return this.$panel.language ? this.$panel.language.code : null;
97105
}
98106
},
99107
100108
watch: {
101109
page(newPage) {
102110
// Load images when the page prop changes (from route)
103111
this.loadImages(newPage);
112+
},
113+
114+
currentLanguage(newLanguage, oldLanguage) {
115+
// Reload images when language changes
116+
if (newLanguage !== oldLanguage && oldLanguage !== undefined) {
117+
const hasUnsaved = Object.keys(this.currentImages).some(imageId => this.hasChanges(imageId));
118+
119+
if (hasUnsaved) {
120+
if (!confirm(this.$t('medienbaecker.alt-text-review.unsavedChanges'))) {
121+
return;
122+
}
123+
}
124+
125+
this.loadImages(this.page);
126+
}
104127
}
105128
},
106129

0 commit comments

Comments
 (0)