Skip to content

Commit e0b88d0

Browse files
committed
update lang code
1 parent 9e35d73 commit e0b88d0

File tree

6 files changed

+103
-2
lines changed

6 files changed

+103
-2
lines changed

.changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# - Fixed error in Bat section of Upgrade Guide (bsc#1234567)
55
# For guidelines: https://en.opensuse.org/openSUSE:Creating_a_changes_file_(RPM)#Changelog_section_.28.25changelog.29
66

7+
- Added lang support for new shared header to html outputs
78
- Added shared header styles for documentation.suse.com
89
- Removed Ubuntu 20.04 from the list supported clients in Client
910
Configuration Guide (bsc#1238481)

Makefile.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ prepare-antora-suma-{{ langcode }}: copy-branding-{{ langcode }} set-html-langua
3333
s/\-\ url\:\ \./\-\ url\:\ \.\.\/\.\.\//;\
3434
s/start_path\:\ \./\start_path\:\ translations\/{{ langcode }}/;\
3535
s/dir:\ \.\/build\/en/dir:\ \.\.\/\.\.\/build\/{{ langcode }}/;" site.yml > translations/{{ langcode }}/suma-site.yml && \
36+
find translations/{{ langcode }}/branding/supplemental-ui -name "*.hbs" -exec sed -i 's/LANG_PLACEHOLDER/{{ langcode }}/g' {} \; && \
3637
cp -a $(current_dir)/modules $(current_dir)/translations/en/
3738
find modules/ -maxdepth 1 -name "*" -type d -exec mkdir -p $(current_dir)/translations/{{ langcode }}/{} \; && \
3839
mkdir -p $(current_dir)/translations/{{ langcode }}/modules/ROOT/pages/
@@ -71,6 +72,7 @@ prepare-antora-uyuni-{{ langcode }}: copy-branding-{{ langcode }} set-html-langu
7172
s/\-\ url\:\ \./\-\ url\:\ \.\.\/\.\.\//;\
7273
s/start_path\:\ \./\start_path\:\ translations\/{{ langcode }}/;\
7374
s/dir:\ \.\/build\/en/dir:\ \.\.\/\.\.\/build\/{{ langcode }}/;" site.yml > translations/{{ langcode }}/uyuni-site.yml && \
75+
find translations/{{ langcode }}/branding/supplemental-ui -name "*.hbs" -exec sed -i 's/LANG_PLACEHOLDER/{{ langcode }}/g' {} \; && \
7476
cp -a $(current_dir)/modules $(current_dir)/translations/en/
7577
find modules/ -maxdepth 1 -name "*" -type d -exec mkdir -p $(current_dir)/translations/{{ langcode }}/{} \; && \
7678
mkdir -p $(current_dir)/translations/{{ langcode }}/modules/ROOT/pages/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* 'use strict'
2+
const get_lang = (url) => {
3+
if (!url) return 'en';
4+
const parts = url.split('/').filter(Boolean); // remove empty strings
5+
// Look for known language codes in the path
6+
const knownLangs = ['en', 'de', 'fr', 'es', 'ja', 'pt_br', 'zh', 'zh_cn', 'ko'];
7+
const match = parts.find(p => knownLangs.includes(p.toLowerCase()));
8+
return match ? match.toLowerCase() : 'en';
9+
};
10+
const langToHreflangMapping = {
11+
"en": "en-US",
12+
"de": "de-DE",
13+
"fr": "fr-FR",
14+
"es": "es-ES",
15+
"ja": "ja-JP",
16+
"pt_br": "pt-BR",
17+
"zh": "zh-CN",
18+
"zh_cn": "zh-CN",
19+
"ko": "ko-KR",
20+
};
21+
module.exports = (pageurl, type, nav) => {
22+
if (nav.page.layout === '404') return null;
23+
const lang = get_lang(pageurl);
24+
if (type === 'hreflang') {
25+
return langToHreflangMapping[lang] || 'en-US';
26+
} else {
27+
return lang;
28+
}
29+
}; */
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Find all alternate hreflang link elements
2+
const hreflangLinks = document.querySelectorAll('link[rel="alternate"]');
3+
4+
const hreflangToLangMapping = {
5+
"en-us": "en",
6+
"de-de": "de",
7+
"fr-fr": "fr",
8+
"es-es": "es",
9+
"ja-jp": "ja",
10+
"pt-br": "pt_BR",
11+
"zh-cn": "zh_CN",
12+
"ko-kr": "ko_KR",
13+
};
14+
15+
// Create an object to hold the languages
16+
const languages = {};
17+
18+
hreflangLinks.forEach((link) => {
19+
const hreflang = link.getAttribute("hreflang");
20+
const href = link.getAttribute("href");
21+
22+
if (hreflang && hreflang !== "x-default") {
23+
let label;
24+
switch (hreflang.toLowerCase()) {
25+
case "en-us":
26+
label = "English";
27+
break;
28+
case "de-de":
29+
label = "Deutsch";
30+
break;
31+
case "fr-fr":
32+
label = "Français";
33+
break;
34+
case "es-es":
35+
label = "Español";
36+
break;
37+
case "zh-cn":
38+
label = "中文";
39+
break;
40+
case "ja-jp":
41+
label = "日本語";
42+
break;
43+
case "ko-kr":
44+
label = "한국어";
45+
break;
46+
case "pt-br":
47+
label = "Português Brasileiro";
48+
break;
49+
}
50+
51+
let lang = hreflangToLangMapping[hreflang.toLowerCase()];
52+
languages[lang] = {
53+
label: label,
54+
url: href,
55+
};
56+
}
57+
});
58+
59+
// Get the current language
60+
const currentLang = document.documentElement.lang || "en";
61+
62+
// Update the <shared-header> element
63+
const sharedHeader = document.querySelector("shared-header");
64+
if (sharedHeader) {
65+
sharedHeader.setAttribute("language", currentLang);
66+
sharedHeader.setAttribute("languages", JSON.stringify(languages));
67+
}

branding/supplemental-ui/suma/susecom-2025/layouts/default.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html>
2+
<html lang="LANG_PLACEHOLDER">
33
<head>
44
{{> head defaultPageTitle='Untitled'}}
55
</head>

site.yml.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
{{ entity.attribute }}: {{ entity.value}}
44
{% endfilter %}
55
{% endfor %}
6+
67
site:
78
{% for i in site -%}
89
{% filter indent(0,true) %}
9-
{{ i.attribute }}: {{ i.value}}
10+
{{ i.attribute }}: {{ i.value }}
1011
{% endfilter %}
1112
{% endfor %}
13+
1214
ui:
1315
bundle:
1416
{% for i in ui.bundle -%}

0 commit comments

Comments
 (0)