« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/misc-templates.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc-templates.js')
-rw-r--r--src/misc-templates.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/misc-templates.js b/src/misc-templates.js
index 578c4e59..090c437d 100644
--- a/src/misc-templates.js
+++ b/src/misc-templates.js
@@ -375,3 +375,33 @@ export function generatePreviousNextLinks(current, {
         })
     ].filter(Boolean).join(', ');
 }
+
+// Footer stuff
+
+export function getFooterLocalizationLinks(pathname, {
+    languages,
+    paths,
+    strings,
+    to
+}) {
+    const { toPath } = paths;
+    const keySuffix = toPath[0].replace(/^localized\./, '.');
+    const toArgs = toPath.slice(1);
+
+    const links = Object.entries(languages)
+        .filter(([ code ]) => code !== 'default')
+        .map(([ code, strings ]) => strings)
+        .sort((
+            { json: { 'meta.languageName': a } },
+            { json: { 'meta.languageName': b } }
+        ) => a < b ? -1 : a > b ? 1 : 0)
+        .map(strings => html.tag('span', html.tag('a', {
+            href: (strings.code === languages.default.code
+                ? to('localizedDefaultLanguage' + keySuffix, ...toArgs)
+                : to('localizedWithBaseDirectory' + keySuffix, strings.code, ...toArgs))
+        }, strings.json['meta.languageName'])));
+
+    return html.tag('div',
+        {class: 'footer-localization-links'},
+        strings('misc.uiLanguage', {languages: links.join('\n')}));
+}