From 89ae8d37a9658da0be528e822a6e8116074334fb Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 May 2022 21:06:32 -0300 Subject: inherited strings --- src/data/things.js | 33 +++++++++++++++++++++++++++------ 1 file 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 @@ -1417,6 +1417,23 @@ Language.propertyDescriptors = { // Mapping of translation keys to values (strings). Generally, don't // 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)])); } } -- cgit 1.3.0-6-gf8a5