Skip to content

Commit 2936b5f

Browse files
committed
refactor: add translation strings
1 parent 7160bac commit 2936b5f

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Adds default alt text to images that don't have one
33
*/
44
function addAltTextToImages() {
5+
56
const articleBody = document.querySelector(".article-body");
67
const postBody = document.querySelectorAll(".post-body");
78

@@ -13,7 +14,7 @@ function addAltTextToImages() {
1314

1415
imagesWithoutAlt.forEach((img) => {
1516
const position = Array.from(allImages).indexOf(img) + 1;
16-
const altText = "Image " + position + " in article";
17+
const altText = window.articleImageAltText.replace("{{position}}", position);
1718
img.setAttribute("alt", altText);
1819
});
1920
}
@@ -27,7 +28,7 @@ function addAltTextToImages() {
2728

2829
imagesWithoutAlt.forEach((img) => {
2930
const position = Array.from(allImages).indexOf(img) + 1;
30-
const altText = "Image " + position + " in post";
31+
const altText = window.postImageAltText.replace("{{position}}", position);
3132
img.setAttribute("alt", altText);
3233
});
3334
}

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)