« get me outta code hell

inherited strings - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-05-10 21:06:32 -0300
committer(quasar) nebula <qznebula@protonmail.com>2022-05-10 21:06:32 -0300
commit89ae8d37a9658da0be528e822a6e8116074334fb (patch)
treed031ef29322d4a9ad4456d4e95ca5c8a39947370
parent22bf1734e08f638c4b147553668954bda315b054 (diff)
inherited strings
-rw-r--r--src/data/things.js33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/data/things.js b/src/data/things.js
index f234dbbd..aa761356 100644
--- a/src/data/things.js
+++ b/src/data/things.js
@@ -1418,6 +1418,23 @@ Language.propertyDescriptors = {
     // access this object directly - use methods instead.
     strings: {
         flags: {update: true, expose: true},
+        update: {validate: t => typeof t === 'object'},
+        expose: {
+            dependencies: ['inheritedStrings'],
+            transform(strings, { inheritedStrings }) {
+                if (strings || inheritedStrings) {
+                    return {...strings ?? {}, ...inheritedStrings ?? {}};
+                } else {
+                    return null;
+                }
+            }
+        }
+    },
+
+    // May be provided to specify "default" strings, generally (but not
+    // necessarily) inherited from another Language object.
+    inheritedStrings: {
+        flags: {update: true, expose: true},
         update: {validate: t => typeof t === 'object'}
     },
 
@@ -1439,18 +1456,22 @@ Language.propertyDescriptors = {
         flags: {expose: true},
 
         expose: {
-            dependencies: ['strings'],
-            compute: ({ strings }) => strings ? Object.keys(strings) : []
+            dependencies: ['strings', 'inheritedStrings'],
+            compute: ({ strings, inheritedStrings }) => Array.from(new Set([
+                ...Object.keys(strings ?? {}),
+                ...Object.keys(inheritedStrings ?? {})
+            ]))
         }
     },
 
     strings_htmlEscaped: {
         flags: {expose: true},
         expose: {
-            dependencies: ['strings', 'escapeHTML'],
-            compute({ strings, escapeHTML }) {
-                if (!strings || !escapeHTML) return null;
-                return Object.fromEntries(Object.entries(strings)
+            dependencies: ['strings', 'inheritedStrings', 'escapeHTML'],
+            compute({ strings, inheritedStrings, escapeHTML }) {
+                if (!(strings || inheritedStrings) || !escapeHTML) return null;
+                const allStrings = {...strings ?? {}, ...inheritedStrings ?? {}};
+                return Object.fromEntries(Object.entries(allStrings)
                     .map(([ k, v ]) => [k, escapeHTML(v)]));
             }
         }