@things-factory/i18n-base 10.1.150 → 10.1.154
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -29,7 +29,13 @@ i18next_1.default.init({
|
|
|
29
29
|
fallbackLng: 'en',
|
|
30
30
|
interpolation: {
|
|
31
31
|
prefix: '{',
|
|
32
|
-
suffix: '}'
|
|
32
|
+
suffix: '}',
|
|
33
|
+
/*
|
|
34
|
+
* A sentence made here is plain text - a refusal, a stored line. i18next's default turns the values into
|
|
35
|
+
* HTML entities, so a refusal naming 'A&B' would say `A&B`. Whoever puts a sentence into HTML
|
|
36
|
+
* escapes it there.
|
|
37
|
+
*/
|
|
38
|
+
escapeValue: false
|
|
33
39
|
},
|
|
34
40
|
load: 'languageOnly',
|
|
35
41
|
keySeparator: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translator.js","sourceRoot":"","sources":["../server/translator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"translator.js","sourceRoot":"","sources":["../server/translator.ts"],"names":[],"mappings":";;;AAwCA,4CAOC;AAcD,sCAaC;;AA1ED,8DAA6B;AA4EpB,kBA5EF,iBAAO,CA4EE;AA1EhB,6CAAyD;AAEzD;;;;;;;;;;;GAWG;AACU,QAAA,SAAS,GAAG,cAAc,CAAA;AAEvC,iBAAO,CAAC,IAAI,CAAC;IACX,aAAa,EAAE,KAAK;IACpB,KAAK,EAAE,KAAK;IACZ,EAAE,EAAE,CAAC,iBAAS,CAAC;IACf,SAAS,EAAE,iBAAS;IACpB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IAC7C,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE;QACb,MAAM,EAAE,GAAG;QACX,MAAM,EAAE,GAAG;QACX;;;;WAIG;QACH,WAAW,EAAE,KAAK;KACnB;IACD,IAAI,EAAE,cAAc;IAC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cesContent":["import i18next from 'i18next'\n\nimport { collectTranslations } from '@things-factory/env'\n\n/**\n * The server's translations — loaded from the sources, not from the webpack output.\n *\n * ── What was wrong (2026-10-11) ──────────────────────────────────────────\n * The server read only `dist-app/translations`, which webpack writes. A test run never has it, and a\n * dev server has it only after its first webpack pass. Server code that froze a sentence before then\n * got the key back. The sources are every module's `translations/` folder and the application's own,\n * merged by the same rule the bundler uses (`collectTranslations` in env).\n *\n * This file is light on purpose — no routes, no entities — so server code and tests can take a\n * translator without loading the whole module (`@things-factory/i18n-base/translator`).\n */\nexport const NAMESPACE = 'translations'\n\ni18next.init({\n initImmediate: false,\n debug: false,\n ns: [NAMESPACE],\n defaultNS: NAMESPACE,\n preload: ['ko', 'en', 'ja', 'zh', 'ms', 'es'],\n fallbackLng: 'en',\n interpolation: {\n prefix: '{',\n suffix: '}',\n /*\n * A sentence made here is plain text - a refusal, a stored line. i18next's default turns the values into\n * HTML entities, so a refusal naming 'A&B' would say `A&B`. Whoever puts a sentence into HTML\n * escapes it there.\n */\n escapeValue: false\n },\n load: 'languageOnly',\n keySeparator: false\n})\n\n/** Load every locale from the sources. Called once here, and again when a dev build changes them. */\nexport function loadTranslations(): void {\n const all = collectTranslations(NAMESPACE)\n\n for (const lng of Object.keys(all)) {\n i18next.removeResourceBundle(lng, NAMESPACE)\n i18next.addResourceBundle(lng, NAMESPACE, all[lng], true, true)\n }\n}\n\nloadTranslations()\n\nexport type Translate = (key: string, options?: { [name: string]: unknown }) => string\n\n/**\n * A translator for one language that **does not fall back** to another.\n *\n * A request's translator falls back to English, which is right for a screen. A sentence the server\n * stores is not: an English sentence filed as the Korean one is wrong and nobody sees why. So a key\n * missing in this language — with its `context` form and without — answers `options.defaultValue`,\n * and the caller decides what that means.\n */\nexport function translatorFor(lng: string): Translate {\n const fixed = i18next.getFixedT(lng, NAMESPACE)\n const has = (key: string) => i18next.getResource(lng, NAMESPACE, key) !== undefined\n\n return (key, options = {}) => {\n const context = options.context === undefined || options.context === null ? '' : String(options.context)\n\n if ((context && has(`${key}_${context}`)) || has(key)) {\n return fixed(key, options as any) as string\n }\n\n return (options.defaultValue as string) ?? key\n }\n}\n\nexport { i18next }\n"]}
|