« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--static/client.js35
-rwxr-xr-xupd8.js3
2 files changed, 35 insertions, 3 deletions
diff --git a/static/client.js b/static/client.js
index b79539e..96d227f 100644
--- a/static/client.js
+++ b/static/client.js
@@ -12,6 +12,38 @@ let officialAlbumData, fandomAlbumData, artistNames;
 
 let ready = false;
 
+// Localiz8tion nonsense ----------------------------------
+
+const language = document.documentElement.getAttribute('lang');
+
+let list;
+if (
+    typeof Intl === 'object' &&
+    typeof Intl.ListFormat === 'function'
+) {
+    const getFormat = type => {
+        const formatter = new Intl.ListFormat(language, {type});
+        return formatter.format.bind(formatter);
+    };
+
+    list = {
+        conjunction: getFormat('conjunction'),
+        disjunction: getFormat('disjunction'),
+        unit: getFormat('unit')
+    };
+} else {
+    // Not a gr8 mock we've got going here, 8ut it's *mostly* language-free.
+    // We use the same mock for every list 'cuz we don't have any of the
+    // necessary CLDR info to appropri8tely distinguish 8etween them.
+    const arbitraryMock = array => array.join(', ');
+
+    list = {
+        conjunction: arbitraryMock,
+        disjunction: arbitraryMock,
+        unit: arbitraryMock
+    };
+}
+
 // Miscellaneous helpers ----------------------------------
 
 function rebase(href, rebaseKey = 'rebaseLocalized') {
@@ -251,9 +283,8 @@ const infoCard = (() => {
             imgLink.href = rebase(data.cover.paths.original, 'rebaseMedia');
 
             if (containerShow === containerReveal) {
-                // TODO: List localiz8tion?
                 const cw = containerShow.querySelector('.info-card-art-warnings');
-                cw.innerText = data.cover.warnings.join(', ');
+                cw.innerText = list.unit(data.cover.warnings);
 
                 const reveal = containerShow.querySelector('.reveal');
                 reveal.classList.remove('revealed');
diff --git a/upd8.js b/upd8.js
index 445ff8d..61be4b0 100755
--- a/upd8.js
+++ b/upd8.js
@@ -2451,6 +2451,7 @@ writePage.html = (pageFn, {paths, strings, to}) => {
     return filterEmptyLines(fixWS`
         <!DOCTYPE html>
         <html ${attributes({
+            lang: strings.code,
             'data-rebase-localized': to('localized.root'),
             'data-rebase-shared': to('shared.root'),
             'data-rebase-media': to('media.root'),
@@ -2850,7 +2851,7 @@ function getRevealStringFromWarnings(warnings, {strings}) {
 
 function getRevealStringFromTags(tags, {strings}) {
     return tags && tags.some(tag => tag.isCW) && (
-        getRevealStringFromWarnings(tags.filter(tag => tag.isCW).map(tag => tag.name).join(', '), {strings}));
+        getRevealStringFromWarnings(strings.list.unit(tags.filter(tag => tag.isCW).map(tag => tag.name).join(', '), {strings})));
 }
 
 function generateCoverLink({