Skip to content

Commit c4c983e

Browse files
committed
refactor: add translation strings
1 parent 74bd2e4 commit c4c983e

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

script.js

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/imageAltText.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ function addAltTextToImages() {
1313

1414
imagesWithoutAlt.forEach((img) => {
1515
const position = Array.from(allImages).indexOf(img) + 1;
16-
const altText = "Image " + position + " in article";
16+
const altText = window.articleImageAltText.replace(
17+
"{{position}}",
18+
position
19+
);
1720
img.setAttribute("alt", altText);
1821
});
1922
}
@@ -27,7 +30,7 @@ function addAltTextToImages() {
2730

2831
imagesWithoutAlt.forEach((img) => {
2932
const position = Array.from(allImages).indexOf(img) + 1;
30-
const altText = "Image " + position + " in post";
33+
const altText = window.postImageAltText.replace("{{position}}", position);
3134
img.setAttribute("alt", altText);
3235
});
3336
}

templates/document_head.hbs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
22
<!-- Make the translated search clear button label available for use in JS -->
33
<!-- See buildClearSearchButton() in script.js -->
4-
<script type="text/javascript">window.searchClearButtonLabelLocalized = "{{t 'search_clear'}}";</script>
4+
<script type="text/javascript">
5+
window.searchClearButtonLabelLocalized = "{{t 'search_clear'}}";
6+
window.articleImageAltText = "{{t 'article_image_alt_text' position=0}}";
7+
window.postImageAltText = "{{t 'post_image_alt_text' position=0}}";
8+
</script>
59
<script type="text/javascript">
610
// Load ES module polyfill only for browsers that don't support ES modules
711
if (!(HTMLScriptElement.supports && HTMLScriptElement.supports('importmap'))) {

translations/en-us.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"article_image_alt_text": "Image {{position}} in article",
3+
"post_image_alt_text": "Image {{position}} in post",
24
"article_author_description": "Show author image and name",
35
"article_author_label": "Author",
46
"article_comments_description": "Show comments on articles",

0 commit comments

Comments
 (0)