@digitaldefiance/i18n-lib 3.8.2 → 3.8.4
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.
- package/package.json +8 -7
- package/src/{active-context.ts → active-context.d.ts} +1 -0
- package/src/active-context.d.ts.map +1 -0
- package/src/active-context.js +3 -0
- package/src/active-context.js.map +1 -0
- package/src/builders/i18n-builder.d.ts +26 -0
- package/src/builders/i18n-builder.d.ts.map +1 -0
- package/src/builders/i18n-builder.js +70 -0
- package/src/builders/i18n-builder.js.map +1 -0
- package/src/builders/{index.ts → index.d.ts} +1 -1
- package/src/builders/index.d.ts.map +1 -0
- package/src/builders/index.js +8 -0
- package/src/builders/index.js.map +1 -0
- package/src/component-definition.d.ts +12 -0
- package/src/component-definition.d.ts.map +1 -0
- package/src/component-definition.js +3 -0
- package/src/component-definition.js.map +1 -0
- package/src/component-registration.d.ts +22 -0
- package/src/component-registration.d.ts.map +1 -0
- package/src/component-registration.js +3 -0
- package/src/component-registration.js.map +1 -0
- package/src/component-registry.d.ts +102 -0
- package/src/component-registry.d.ts.map +1 -0
- package/src/component-registry.js +282 -0
- package/src/component-registry.js.map +1 -0
- package/src/context-error-type.d.ts +8 -0
- package/src/context-error-type.d.ts.map +1 -0
- package/src/context-error-type.js +12 -0
- package/src/context-error-type.js.map +1 -0
- package/src/core/component-store.d.ts +93 -0
- package/src/core/component-store.d.ts.map +1 -0
- package/src/core/component-store.js +198 -0
- package/src/core/component-store.js.map +1 -0
- package/src/core/context-manager.d.ts +72 -0
- package/src/core/context-manager.d.ts.map +1 -0
- package/src/core/context-manager.js +98 -0
- package/src/core/context-manager.js.map +1 -0
- package/src/core/enum-registry.d.ts +48 -0
- package/src/core/enum-registry.d.ts.map +1 -0
- package/src/core/enum-registry.js +85 -0
- package/src/core/enum-registry.js.map +1 -0
- package/src/core/i18n-engine.d.ts +241 -0
- package/src/core/i18n-engine.d.ts.map +1 -0
- package/src/core/i18n-engine.js +568 -0
- package/src/core/i18n-engine.js.map +1 -0
- package/src/core/{index.ts → index.d.ts} +1 -4
- package/src/core/index.d.ts.map +1 -0
- package/src/core/index.js +21 -0
- package/src/core/index.js.map +1 -0
- package/src/core/language-registry.d.ts +180 -0
- package/src/core/language-registry.d.ts.map +1 -0
- package/src/core/language-registry.js +298 -0
- package/src/core/language-registry.js.map +1 -0
- package/src/{core-component-id.ts → core-component-id.d.ts} +2 -1
- package/src/core-component-id.d.ts.map +1 -0
- package/src/core-component-id.js +9 -0
- package/src/core-component-id.js.map +1 -0
- package/src/core-i18n.d.ts +69 -0
- package/src/core-i18n.d.ts.map +1 -0
- package/src/core-i18n.js +219 -0
- package/src/core-i18n.js.map +1 -0
- package/src/core-plugin-factory.d.ts +28 -0
- package/src/core-plugin-factory.d.ts.map +1 -0
- package/src/core-plugin-factory.js +80 -0
- package/src/core-plugin-factory.js.map +1 -0
- package/src/core-string-key.d.ts +52 -0
- package/src/core-string-key.d.ts.map +1 -0
- package/src/core-string-key.js +61 -0
- package/src/core-string-key.js.map +1 -0
- package/src/create-translation-adapter.d.ts +33 -0
- package/src/create-translation-adapter.d.ts.map +1 -0
- package/src/create-translation-adapter.js +72 -0
- package/src/create-translation-adapter.js.map +1 -0
- package/src/enum-registry.d.ts +65 -0
- package/src/enum-registry.d.ts.map +1 -0
- package/src/enum-registry.js +123 -0
- package/src/enum-registry.js.map +1 -0
- package/src/errors/{base.ts → base.d.ts} +1 -1
- package/src/errors/base.d.ts.map +1 -0
- package/src/errors/base.js +11 -0
- package/src/errors/base.js.map +1 -0
- package/src/errors/context-error.d.ts +50 -0
- package/src/errors/context-error.d.ts.map +1 -0
- package/src/errors/context-error.js +93 -0
- package/src/errors/context-error.js.map +1 -0
- package/src/errors/enhanced-error-base.d.ts +125 -0
- package/src/errors/enhanced-error-base.d.ts.map +1 -0
- package/src/errors/enhanced-error-base.js +165 -0
- package/src/errors/enhanced-error-base.js.map +1 -0
- package/src/errors/handleable.d.ts +83 -0
- package/src/errors/handleable.d.ts.map +1 -0
- package/src/errors/handleable.js +136 -0
- package/src/errors/handleable.js.map +1 -0
- package/src/errors/i18n-error.d.ts +211 -0
- package/src/errors/i18n-error.d.ts.map +1 -0
- package/src/errors/i18n-error.js +358 -0
- package/src/errors/i18n-error.js.map +1 -0
- package/src/errors/{index.ts → index.d.ts} +1 -4
- package/src/errors/index.d.ts.map +1 -0
- package/src/errors/index.js +17 -0
- package/src/errors/index.js.map +1 -0
- package/src/errors/simple-typed-error.d.ts +53 -0
- package/src/errors/simple-typed-error.d.ts.map +1 -0
- package/src/errors/simple-typed-error.js +51 -0
- package/src/errors/simple-typed-error.js.map +1 -0
- package/src/errors/{translatable-exports.ts → translatable-exports.d.ts} +1 -1
- package/src/errors/translatable-exports.d.ts.map +1 -0
- package/src/errors/translatable-exports.js +15 -0
- package/src/errors/translatable-exports.js.map +1 -0
- package/src/errors/translatable-generic.d.ts +87 -0
- package/src/errors/translatable-generic.d.ts.map +1 -0
- package/src/errors/translatable-generic.js +139 -0
- package/src/errors/translatable-generic.js.map +1 -0
- package/src/errors/translatable-handleable-generic.d.ts +116 -0
- package/src/errors/translatable-handleable-generic.d.ts.map +1 -0
- package/src/errors/translatable-handleable-generic.js +121 -0
- package/src/errors/translatable-handleable-generic.js.map +1 -0
- package/src/errors/translatable.d.ts +63 -0
- package/src/errors/translatable.d.ts.map +1 -0
- package/src/errors/translatable.js +85 -0
- package/src/errors/translatable.js.map +1 -0
- package/src/errors/typed-handleable.d.ts +62 -0
- package/src/errors/typed-handleable.d.ts.map +1 -0
- package/src/errors/typed-handleable.js +108 -0
- package/src/errors/typed-handleable.js.map +1 -0
- package/src/errors/typed.d.ts +206 -0
- package/src/errors/typed.d.ts.map +1 -0
- package/src/errors/typed.js +458 -0
- package/src/errors/typed.js.map +1 -0
- package/src/gender/{gender-categories.ts → gender-categories.d.ts} +2 -6
- package/src/gender/gender-categories.d.ts.map +1 -0
- package/src/gender/gender-categories.js +15 -0
- package/src/gender/gender-categories.js.map +1 -0
- package/src/gender/gender-resolver.d.ts +14 -0
- package/src/gender/gender-resolver.d.ts.map +1 -0
- package/src/gender/gender-resolver.js +35 -0
- package/src/gender/gender-resolver.js.map +1 -0
- package/src/gender/{index.ts → index.d.ts} +1 -0
- package/src/gender/index.d.ts.map +1 -0
- package/src/gender/index.js +6 -0
- package/src/gender/index.js.map +1 -0
- package/src/global-active-context.d.ts +50 -0
- package/src/global-active-context.d.ts.map +1 -0
- package/src/global-active-context.js +185 -0
- package/src/global-active-context.js.map +1 -0
- package/src/icu/ast.d.ts +48 -0
- package/src/icu/ast.d.ts.map +1 -0
- package/src/icu/ast.js +16 -0
- package/src/icu/ast.js.map +1 -0
- package/src/icu/compiler.d.ts +16 -0
- package/src/icu/compiler.d.ts.map +1 -0
- package/src/icu/compiler.js +87 -0
- package/src/icu/compiler.js.map +1 -0
- package/src/icu/formatter-registry.d.ts +10 -0
- package/src/icu/formatter-registry.d.ts.map +1 -0
- package/src/icu/formatter-registry.js +34 -0
- package/src/icu/formatter-registry.js.map +1 -0
- package/src/icu/formatters/base-formatter.d.ts +8 -0
- package/src/icu/formatters/base-formatter.d.ts.map +1 -0
- package/src/icu/formatters/base-formatter.js +3 -0
- package/src/icu/formatters/base-formatter.js.map +1 -0
- package/src/icu/formatters/date-formatter.d.ts +5 -0
- package/src/icu/formatters/date-formatter.d.ts.map +1 -0
- package/src/icu/formatters/date-formatter.js +31 -0
- package/src/icu/formatters/date-formatter.js.map +1 -0
- package/src/icu/formatters/number-formatter.d.ts +5 -0
- package/src/icu/formatters/number-formatter.d.ts.map +1 -0
- package/src/icu/formatters/number-formatter.js +33 -0
- package/src/icu/formatters/number-formatter.js.map +1 -0
- package/src/icu/formatters/plural-formatter.d.ts +5 -0
- package/src/icu/formatters/plural-formatter.d.ts.map +1 -0
- package/src/icu/formatters/plural-formatter.js +15 -0
- package/src/icu/formatters/plural-formatter.js.map +1 -0
- package/src/icu/formatters/select-formatter.d.ts +5 -0
- package/src/icu/formatters/select-formatter.d.ts.map +1 -0
- package/src/icu/formatters/select-formatter.js +10 -0
- package/src/icu/formatters/select-formatter.js.map +1 -0
- package/src/icu/formatters/selectordinal-formatter.d.ts +5 -0
- package/src/icu/formatters/selectordinal-formatter.d.ts.map +1 -0
- package/src/icu/formatters/selectordinal-formatter.js +22 -0
- package/src/icu/formatters/selectordinal-formatter.js.map +1 -0
- package/src/icu/formatters/time-formatter.d.ts +5 -0
- package/src/icu/formatters/time-formatter.d.ts.map +1 -0
- package/src/icu/formatters/time-formatter.js +31 -0
- package/src/icu/formatters/time-formatter.js.map +1 -0
- package/src/icu/helpers.d.ts +9 -0
- package/src/icu/helpers.d.ts.map +1 -0
- package/src/icu/helpers.js +31 -0
- package/src/icu/helpers.js.map +1 -0
- package/src/icu/parser.d.ts +31 -0
- package/src/icu/parser.d.ts.map +1 -0
- package/src/icu/parser.js +203 -0
- package/src/icu/parser.js.map +1 -0
- package/src/icu/runtime.d.ts +10 -0
- package/src/icu/runtime.d.ts.map +1 -0
- package/src/icu/runtime.js +33 -0
- package/src/icu/runtime.js.map +1 -0
- package/src/icu/tokenizer.d.ts +37 -0
- package/src/icu/tokenizer.d.ts.map +1 -0
- package/src/icu/tokenizer.js +187 -0
- package/src/icu/tokenizer.js.map +1 -0
- package/src/icu/validator.d.ts +11 -0
- package/src/icu/validator.d.ts.map +1 -0
- package/src/icu/validator.js +140 -0
- package/src/icu/validator.js.map +1 -0
- package/src/{index.ts → index.d.ts} +6 -38
- package/src/index.d.ts.map +1 -0
- package/src/index.js +76 -0
- package/src/index.js.map +1 -0
- package/src/interfaces/active-context.interface.d.ts +36 -0
- package/src/interfaces/active-context.interface.d.ts.map +1 -0
- package/src/interfaces/active-context.interface.js +3 -0
- package/src/interfaces/active-context.interface.js.map +1 -0
- package/src/interfaces/component-config.interface.d.ts +16 -0
- package/src/interfaces/component-config.interface.d.ts.map +1 -0
- package/src/interfaces/component-config.interface.js +6 -0
- package/src/interfaces/component-config.interface.js.map +1 -0
- package/src/interfaces/engine-config.interface.d.ts +22 -0
- package/src/interfaces/engine-config.interface.d.ts.map +1 -0
- package/src/interfaces/engine-config.interface.js +6 -0
- package/src/interfaces/engine-config.interface.js.map +1 -0
- package/src/interfaces/global-active-context.d.ts +23 -0
- package/src/interfaces/global-active-context.d.ts.map +1 -0
- package/src/interfaces/global-active-context.js +3 -0
- package/src/interfaces/global-active-context.js.map +1 -0
- package/src/interfaces/handleable-error-options.d.ts +14 -0
- package/src/interfaces/handleable-error-options.d.ts.map +1 -0
- package/src/interfaces/handleable-error-options.js +3 -0
- package/src/interfaces/handleable-error-options.js.map +1 -0
- package/src/interfaces/handleable.d.ts +21 -0
- package/src/interfaces/handleable.d.ts.map +1 -0
- package/src/interfaces/handleable.js +3 -0
- package/src/interfaces/handleable.js.map +1 -0
- package/src/interfaces/i18n-engine.interface.d.ts +46 -0
- package/src/interfaces/i18n-engine.interface.d.ts.map +1 -0
- package/src/interfaces/i18n-engine.interface.js +6 -0
- package/src/interfaces/i18n-engine.interface.js.map +1 -0
- package/src/interfaces/{index.ts → index.d.ts} +1 -1
- package/src/interfaces/index.d.ts.map +1 -0
- package/src/interfaces/index.js +7 -0
- package/src/interfaces/index.js.map +1 -0
- package/src/interfaces/language-definition.interface.d.ts +17 -0
- package/src/interfaces/language-definition.interface.d.ts.map +1 -0
- package/src/interfaces/language-definition.interface.js +6 -0
- package/src/interfaces/language-definition.interface.js.map +1 -0
- package/src/interfaces/translation-options.interface.d.ts +15 -0
- package/src/interfaces/translation-options.interface.d.ts.map +1 -0
- package/src/interfaces/translation-options.interface.js +6 -0
- package/src/interfaces/translation-options.interface.js.map +1 -0
- package/src/interfaces/validation-result.interface.d.ts +24 -0
- package/src/interfaces/validation-result.interface.d.ts.map +1 -0
- package/src/interfaces/validation-result.interface.js +6 -0
- package/src/interfaces/validation-result.interface.js.map +1 -0
- package/src/language-codes.d.ts +28 -0
- package/src/language-codes.d.ts.map +1 -0
- package/src/language-codes.js +32 -0
- package/src/language-codes.js.map +1 -0
- package/src/language-definition.d.ts +14 -0
- package/src/language-definition.d.ts.map +1 -0
- package/src/language-definition.js +3 -0
- package/src/language-definition.js.map +1 -0
- package/src/plugin-i18n-engine.d.ts +164 -0
- package/src/plugin-i18n-engine.d.ts.map +1 -0
- package/src/plugin-i18n-engine.js +493 -0
- package/src/plugin-i18n-engine.js.map +1 -0
- package/src/pluralization/{index.ts → index.d.ts} +1 -1
- package/src/pluralization/index.d.ts.map +1 -0
- package/src/pluralization/index.js +10 -0
- package/src/pluralization/index.js.map +1 -0
- package/src/pluralization/language-plural-map.d.ts +29 -0
- package/src/pluralization/language-plural-map.d.ts.map +1 -0
- package/src/pluralization/language-plural-map.js +155 -0
- package/src/pluralization/language-plural-map.js.map +1 -0
- package/src/pluralization/{plural-categories.ts → plural-categories.d.ts} +3 -5
- package/src/pluralization/plural-categories.d.ts.map +1 -0
- package/src/pluralization/plural-categories.js +8 -0
- package/src/pluralization/plural-categories.js.map +1 -0
- package/src/pluralization/plural-rules.d.ts +102 -0
- package/src/pluralization/plural-rules.d.ts.map +1 -0
- package/src/pluralization/plural-rules.js +263 -0
- package/src/pluralization/plural-rules.js.map +1 -0
- package/src/registry-config.d.ts +16 -0
- package/src/registry-config.d.ts.map +1 -0
- package/src/registry-config.js +3 -0
- package/src/registry-config.js.map +1 -0
- package/src/registry-error-type.d.ts +20 -0
- package/src/registry-error-type.d.ts.map +1 -0
- package/src/registry-error-type.js +24 -0
- package/src/registry-error-type.js.map +1 -0
- package/src/registry-error.d.ts +25 -0
- package/src/registry-error.d.ts.map +1 -0
- package/src/registry-error.js +63 -0
- package/src/registry-error.js.map +1 -0
- package/src/strict-types.d.ts +19 -0
- package/src/strict-types.d.ts.map +1 -0
- package/src/strict-types.js +18 -0
- package/src/strict-types.js.map +1 -0
- package/src/strings/de.d.ts +3 -0
- package/src/strings/de.d.ts.map +1 -0
- package/src/strings/de.js +57 -0
- package/src/strings/de.js.map +1 -0
- package/src/strings/en-GB.d.ts +3 -0
- package/src/strings/en-GB.d.ts.map +1 -0
- package/src/strings/en-GB.js +57 -0
- package/src/strings/en-GB.js.map +1 -0
- package/src/strings/en-US.d.ts +3 -0
- package/src/strings/en-US.d.ts.map +1 -0
- package/src/strings/en-US.js +57 -0
- package/src/strings/en-US.js.map +1 -0
- package/src/strings/es.d.ts +3 -0
- package/src/strings/es.d.ts.map +1 -0
- package/src/strings/es.js +57 -0
- package/src/strings/es.js.map +1 -0
- package/src/strings/fr.d.ts +3 -0
- package/src/strings/fr.d.ts.map +1 -0
- package/src/strings/fr.js +57 -0
- package/src/strings/fr.js.map +1 -0
- package/src/strings/ja.d.ts +3 -0
- package/src/strings/ja.d.ts.map +1 -0
- package/src/strings/ja.js +57 -0
- package/src/strings/ja.js.map +1 -0
- package/src/strings/uk.d.ts +3 -0
- package/src/strings/uk.d.ts.map +1 -0
- package/src/strings/uk.js +57 -0
- package/src/strings/uk.js.map +1 -0
- package/src/strings/zh-CN.d.ts +3 -0
- package/src/strings/zh-CN.d.ts.map +1 -0
- package/src/strings/zh-CN.js +57 -0
- package/src/strings/zh-CN.js.map +1 -0
- package/src/template.d.ts +13 -0
- package/src/template.d.ts.map +1 -0
- package/src/template.js +40 -0
- package/src/template.js.map +1 -0
- package/src/translation-engine.d.ts +9 -0
- package/src/translation-engine.d.ts.map +1 -0
- package/src/translation-engine.js +3 -0
- package/src/translation-engine.js.map +1 -0
- package/src/translation-request.d.ts +10 -0
- package/src/translation-request.d.ts.map +1 -0
- package/src/translation-request.js +3 -0
- package/src/translation-request.js.map +1 -0
- package/src/translation-response.d.ts +9 -0
- package/src/translation-response.d.ts.map +1 -0
- package/src/translation-response.js +3 -0
- package/src/translation-response.js.map +1 -0
- package/src/types/engine.d.ts +47 -0
- package/src/types/engine.d.ts.map +1 -0
- package/src/types/engine.js +8 -0
- package/src/types/engine.js.map +1 -0
- package/src/types/{index.ts → index.d.ts} +1 -1
- package/src/types/index.d.ts.map +1 -0
- package/src/types/index.js +9 -0
- package/src/types/index.js.map +1 -0
- package/src/types/{plural-types.ts → plural-types.d.ts} +3 -29
- package/src/types/plural-types.d.ts.map +1 -0
- package/src/types/plural-types.js +39 -0
- package/src/types/plural-types.js.map +1 -0
- package/src/{types.ts → types.d.ts} +21 -72
- package/src/types.d.ts.map +1 -0
- package/src/types.js +23 -0
- package/src/types.js.map +1 -0
- package/src/utils/currency.d.ts +81 -0
- package/src/utils/currency.d.ts.map +1 -0
- package/src/utils/currency.js +99 -0
- package/src/utils/currency.js.map +1 -0
- package/src/utils/html-escape.d.ts +22 -0
- package/src/utils/html-escape.d.ts.map +1 -0
- package/src/utils/html-escape.js +53 -0
- package/src/utils/html-escape.js.map +1 -0
- package/src/utils/{index.ts → index.d.ts} +1 -0
- package/src/utils/index.d.ts.map +1 -0
- package/src/utils/index.js +12 -0
- package/src/utils/index.js.map +1 -0
- package/src/utils/lru-cache.d.ts +42 -0
- package/src/utils/lru-cache.d.ts.map +1 -0
- package/src/utils/lru-cache.js +73 -0
- package/src/utils/lru-cache.js.map +1 -0
- package/src/utils/{plural-helpers.ts → plural-helpers.d.ts} +4 -14
- package/src/utils/plural-helpers.d.ts.map +1 -0
- package/src/utils/plural-helpers.js +35 -0
- package/src/utils/plural-helpers.js.map +1 -0
- package/src/utils/safe-object.d.ts +39 -0
- package/src/utils/safe-object.d.ts.map +1 -0
- package/src/utils/{safe-object.ts → safe-object.js} +34 -37
- package/src/utils/safe-object.js.map +1 -0
- package/src/utils/string-utils.d.ts +28 -0
- package/src/utils/string-utils.d.ts.map +1 -0
- package/src/utils/string-utils.js +63 -0
- package/src/utils/string-utils.js.map +1 -0
- package/src/utils/timezone.d.ts +50 -0
- package/src/utils/timezone.d.ts.map +1 -0
- package/src/utils/timezone.js +74 -0
- package/src/utils/timezone.js.map +1 -0
- package/src/utils/validation.d.ts +40 -0
- package/src/utils/validation.d.ts.map +1 -0
- package/src/utils/validation.js +69 -0
- package/src/utils/validation.js.map +1 -0
- package/src/utils.d.ts +65 -0
- package/src/utils.d.ts.map +1 -0
- package/src/utils.js +129 -0
- package/src/utils.js.map +1 -0
- package/src/validation/{index.ts → index.d.ts} +1 -0
- package/src/validation/index.d.ts.map +1 -0
- package/src/validation/index.js +5 -0
- package/src/validation/index.js.map +1 -0
- package/src/validation/plural-validator.d.ts +46 -0
- package/src/validation/plural-validator.d.ts.map +1 -0
- package/src/validation/plural-validator.js +123 -0
- package/src/validation/plural-validator.js.map +1 -0
- package/src/validation-config.d.ts +12 -0
- package/src/validation-config.d.ts.map +1 -0
- package/src/validation-config.js +3 -0
- package/src/validation-config.js.map +1 -0
- package/src/validation-result.d.ts +13 -0
- package/src/validation-result.d.ts.map +1 -0
- package/src/validation-result.js +3 -0
- package/src/validation-result.js.map +1 -0
- package/LICENSE +0 -21
- package/src/builders/i18n-builder.ts +0 -82
- package/src/component-definition.ts +0 -11
- package/src/component-registration.ts +0 -29
- package/src/component-registry.ts +0 -432
- package/src/context-error-type.ts +0 -7
- package/src/core/component-store.ts +0 -241
- package/src/core/context-manager.ts +0 -113
- package/src/core/enum-registry.ts +0 -106
- package/src/core/i18n-engine.ts +0 -710
- package/src/core/language-registry.ts +0 -345
- package/src/core-i18n.ts +0 -270
- package/src/core-plugin-factory.ts +0 -111
- package/src/core-string-key.ts +0 -59
- package/src/create-translation-adapter.ts +0 -93
- package/src/enum-registry.ts +0 -152
- package/src/errors/context-error.ts +0 -122
- package/src/errors/enhanced-error-base.ts +0 -260
- package/src/errors/handleable.ts +0 -152
- package/src/errors/i18n-error.ts +0 -494
- package/src/errors/simple-typed-error.ts +0 -81
- package/src/errors/translatable-generic.ts +0 -245
- package/src/errors/translatable-handleable-generic.ts +0 -222
- package/src/errors/translatable.ts +0 -138
- package/src/errors/typed-handleable.ts +0 -138
- package/src/errors/typed.ts +0 -617
- package/src/gender/gender-resolver.ts +0 -40
- package/src/global-active-context.ts +0 -266
- package/src/icu/ast.ts +0 -56
- package/src/icu/compiler.ts +0 -96
- package/src/icu/formatter-registry.ts +0 -36
- package/src/icu/formatters/base-formatter.ts +0 -8
- package/src/icu/formatters/date-formatter.ts +0 -30
- package/src/icu/formatters/number-formatter.ts +0 -32
- package/src/icu/formatters/plural-formatter.ts +0 -12
- package/src/icu/formatters/select-formatter.ts +0 -7
- package/src/icu/formatters/selectordinal-formatter.ts +0 -17
- package/src/icu/formatters/time-formatter.ts +0 -30
- package/src/icu/helpers.ts +0 -34
- package/src/icu/parser.ts +0 -242
- package/src/icu/runtime.ts +0 -37
- package/src/icu/tokenizer.ts +0 -212
- package/src/icu/validator.ts +0 -163
- package/src/interfaces/active-context.interface.ts +0 -41
- package/src/interfaces/component-config.interface.ts +0 -17
- package/src/interfaces/engine-config.interface.ts +0 -22
- package/src/interfaces/global-active-context.ts +0 -39
- package/src/interfaces/handleable-error-options.ts +0 -13
- package/src/interfaces/handleable.ts +0 -20
- package/src/interfaces/i18n-engine.interface.ts +0 -57
- package/src/interfaces/language-definition.interface.ts +0 -17
- package/src/interfaces/translation-options.interface.ts +0 -15
- package/src/interfaces/validation-result.interface.ts +0 -24
- package/src/language-codes.ts +0 -40
- package/src/language-definition.ts +0 -13
- package/src/plugin-i18n-engine.ts +0 -707
- package/src/pluralization/language-plural-map.ts +0 -186
- package/src/pluralization/plural-rules.ts +0 -228
- package/src/registry-config.ts +0 -16
- package/src/registry-error-type.ts +0 -19
- package/src/registry-error.ts +0 -100
- package/src/strict-types.ts +0 -35
- package/src/strings/de.ts +0 -75
- package/src/strings/en-GB.ts +0 -74
- package/src/strings/en-US.ts +0 -74
- package/src/strings/es.ts +0 -74
- package/src/strings/fr.ts +0 -75
- package/src/strings/ja.ts +0 -73
- package/src/strings/uk.ts +0 -73
- package/src/strings/zh-CN.ts +0 -72
- package/src/template.ts +0 -72
- package/src/translation-engine.ts +0 -18
- package/src/translation-request.ts +0 -12
- package/src/translation-response.ts +0 -8
- package/src/types/engine.ts +0 -55
- package/src/utils/currency.ts +0 -141
- package/src/utils/html-escape.ts +0 -55
- package/src/utils/lru-cache.ts +0 -76
- package/src/utils/string-utils.ts +0 -77
- package/src/utils/timezone.ts +0 -76
- package/src/utils/validation.ts +0 -66
- package/src/utils.ts +0 -215
- package/src/validation/plural-validator.ts +0 -168
- package/src/validation-config.ts +0 -11
- package/src/validation-result.ts +0 -12
|
@@ -1,707 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin-based internationalization engine with component and language registration
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { ComponentDefinition } from './component-definition';
|
|
6
|
-
import { ComponentRegistration } from './component-registration';
|
|
7
|
-
import { ComponentRegistry } from './component-registry';
|
|
8
|
-
import { CoreI18nComponentId } from './core-component-id';
|
|
9
|
-
import { LanguageRegistry } from './core/language-registry';
|
|
10
|
-
import { EnumTranslationRegistry } from './enum-registry';
|
|
11
|
-
import { GlobalActiveContext } from './global-active-context';
|
|
12
|
-
import type { IActiveContext } from './interfaces/active-context.interface';
|
|
13
|
-
import { LanguageDefinition } from './language-definition';
|
|
14
|
-
import { RegistryConfig } from './registry-config';
|
|
15
|
-
import { RegistryError } from './registry-error';
|
|
16
|
-
import { RegistryErrorType } from './registry-error-type';
|
|
17
|
-
import { TranslationRequest } from './translation-request';
|
|
18
|
-
import { TranslationResponse } from './translation-response';
|
|
19
|
-
import { EnumLanguageTranslation } from './types';
|
|
20
|
-
import { CurrencyCode } from './utils/currency';
|
|
21
|
-
import { Timezone } from './utils/timezone';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Plugin-based I18n Engine with registration capabilities
|
|
25
|
-
*/
|
|
26
|
-
export class PluginI18nEngine<TLanguages extends string> {
|
|
27
|
-
private readonly componentRegistry: ComponentRegistry<TLanguages>;
|
|
28
|
-
private readonly enumRegistry: EnumTranslationRegistry<string, TLanguages>;
|
|
29
|
-
private readonly config: RegistryConfig<TLanguages>;
|
|
30
|
-
private contextKey: string;
|
|
31
|
-
private readonly aliasToComponent = new Map<string, string>();
|
|
32
|
-
private readonly componentKeyLookup = new Map<string, Map<string, string>>();
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Default template processor instance
|
|
36
|
-
*/
|
|
37
|
-
public readonly t: (
|
|
38
|
-
str: string,
|
|
39
|
-
language?: TLanguages,
|
|
40
|
-
...otherVars: Record<string, string | number>[]
|
|
41
|
-
) => string;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Static instances for semi-singleton pattern
|
|
45
|
-
*/
|
|
46
|
-
private static _instances = new Map<string, PluginI18nEngine<any>>();
|
|
47
|
-
private static _defaultKey: string | null = null;
|
|
48
|
-
protected static readonly DefaultInstanceKey = 'default';
|
|
49
|
-
|
|
50
|
-
constructor(
|
|
51
|
-
initialLanguages: readonly LanguageDefinition[],
|
|
52
|
-
config: Partial<RegistryConfig<TLanguages>> = {},
|
|
53
|
-
options?: {
|
|
54
|
-
instanceKey?: string;
|
|
55
|
-
registerInstance?: boolean;
|
|
56
|
-
setAsDefault?: boolean;
|
|
57
|
-
},
|
|
58
|
-
) {
|
|
59
|
-
// Find default language from initialLanguages or use the first one
|
|
60
|
-
const defaultLang =
|
|
61
|
-
initialLanguages.find((l) => l.isDefault) || initialLanguages[0];
|
|
62
|
-
if (!defaultLang) {
|
|
63
|
-
throw new Error('At least one language must be provided');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Set up configuration with defaults
|
|
67
|
-
this.config = {
|
|
68
|
-
defaultLanguage: defaultLang.id as TLanguages,
|
|
69
|
-
fallbackLanguage: defaultLang.id as TLanguages,
|
|
70
|
-
defaultCurrencyCode: new CurrencyCode('USD'),
|
|
71
|
-
timezone: new Timezone('UTC'),
|
|
72
|
-
adminTimezone: new Timezone('UTC'),
|
|
73
|
-
validation: {
|
|
74
|
-
requireCompleteStrings: false,
|
|
75
|
-
allowPartialRegistration: true,
|
|
76
|
-
fallbackLanguageId: defaultLang.id,
|
|
77
|
-
},
|
|
78
|
-
...config,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// Register initial languages in static registry (skip if already registered)
|
|
82
|
-
for (const lang of initialLanguages) {
|
|
83
|
-
if (!LanguageRegistry.hasLanguage(lang.id)) {
|
|
84
|
-
LanguageRegistry.registerLanguage(lang);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Initialize component registry (per-instance)
|
|
89
|
-
this.componentRegistry = new ComponentRegistry<TLanguages>(
|
|
90
|
-
initialLanguages.map((l) => l.id as TLanguages),
|
|
91
|
-
this.config.validation,
|
|
92
|
-
this.config.constants,
|
|
93
|
-
);
|
|
94
|
-
this.enumRegistry = new EnumTranslationRegistry<string, TLanguages>(
|
|
95
|
-
initialLanguages.map((l) => l.id as TLanguages),
|
|
96
|
-
(key: string, vars?: Record<string, any>) =>
|
|
97
|
-
this.safeTranslate(CoreI18nComponentId, key, vars),
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
// Initialize context key for this engine instance
|
|
101
|
-
this.contextKey =
|
|
102
|
-
options?.instanceKey ?? PluginI18nEngine.DefaultInstanceKey;
|
|
103
|
-
|
|
104
|
-
// Create or get the global context for this engine
|
|
105
|
-
const globalContext = GlobalActiveContext.getInstance<
|
|
106
|
-
TLanguages,
|
|
107
|
-
IActiveContext<TLanguages>
|
|
108
|
-
>();
|
|
109
|
-
|
|
110
|
-
// Always create/update the context for this engine
|
|
111
|
-
globalContext.createContext(
|
|
112
|
-
this.config.defaultLanguage,
|
|
113
|
-
this.config.defaultLanguage,
|
|
114
|
-
this.contextKey,
|
|
115
|
-
);
|
|
116
|
-
globalContext.setCurrencyCode(
|
|
117
|
-
this.config.defaultCurrencyCode,
|
|
118
|
-
this.contextKey,
|
|
119
|
-
);
|
|
120
|
-
globalContext.setUserTimezone(this.config.timezone, this.contextKey);
|
|
121
|
-
globalContext.setAdminTimezone(this.config.adminTimezone, this.contextKey);
|
|
122
|
-
|
|
123
|
-
// Initialize the default template processor for component-based patterns
|
|
124
|
-
this.t = (
|
|
125
|
-
str: string,
|
|
126
|
-
language?: TLanguages,
|
|
127
|
-
...otherVars: Record<string, string | number>[]
|
|
128
|
-
) => {
|
|
129
|
-
// Step 1: Replace component-based patterns like {{componentId.stringKey}}
|
|
130
|
-
let result = str.replace(/\{\{([^}]+)\}\}/g, (match, pattern) => {
|
|
131
|
-
const parts = pattern.split('.');
|
|
132
|
-
if (parts.length === 2) {
|
|
133
|
-
const [rawPrefix, rawKey] = parts;
|
|
134
|
-
const prefix = rawPrefix.trim();
|
|
135
|
-
const key = rawKey.trim();
|
|
136
|
-
// For template strings, use the first variable object if available
|
|
137
|
-
const isTemplate = key.toLowerCase().endsWith('template');
|
|
138
|
-
const vars = isTemplate && otherVars.length > 0 ? otherVars[0] : {};
|
|
139
|
-
const { componentId, stringKey } = this.resolveComponentAndKey(
|
|
140
|
-
prefix,
|
|
141
|
-
key,
|
|
142
|
-
);
|
|
143
|
-
return this.safeTranslate(componentId, stringKey, vars, language);
|
|
144
|
-
}
|
|
145
|
-
return match; // Return original if pattern doesn't match expected format
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Step 2: Get context variables (timezone, currency, language)
|
|
149
|
-
const context = this.getContext();
|
|
150
|
-
const contextVars: Record<string, string | number> = {
|
|
151
|
-
timezone:
|
|
152
|
-
context.currentContext === 'admin'
|
|
153
|
-
? context.adminTimezone.value
|
|
154
|
-
: context.timezone.value,
|
|
155
|
-
currencyCode: context.currencyCode.value,
|
|
156
|
-
language:
|
|
157
|
-
context.currentContext === 'admin'
|
|
158
|
-
? context.adminLanguage
|
|
159
|
-
: context.language,
|
|
160
|
-
userTimezone: context.timezone.value,
|
|
161
|
-
adminTimezone: context.adminTimezone.value,
|
|
162
|
-
userLanguage: context.language,
|
|
163
|
-
adminLanguage: context.adminLanguage,
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
// Step 3: Replace remaining variable patterns like {varName} with merged variables
|
|
167
|
-
const allVars = otherVars.reduce(
|
|
168
|
-
(acc, vars) => ({ ...acc, ...vars }),
|
|
169
|
-
contextVars,
|
|
170
|
-
);
|
|
171
|
-
result = result.replace(/\{(\w+)\}/g, (match, varName) => {
|
|
172
|
-
return allVars[varName] !== undefined
|
|
173
|
-
? String(allVars[varName])
|
|
174
|
-
: match;
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
return result;
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
// Auto-register as default instance if none exists
|
|
181
|
-
const shouldRegisterInstance = options?.registerInstance ?? true;
|
|
182
|
-
if (shouldRegisterInstance) {
|
|
183
|
-
if (!PluginI18nEngine._instances.has(this.contextKey)) {
|
|
184
|
-
PluginI18nEngine._instances.set(this.contextKey, this);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const shouldSetDefault =
|
|
188
|
-
options?.setAsDefault ??
|
|
189
|
-
(!PluginI18nEngine._defaultKey ||
|
|
190
|
-
this.contextKey === PluginI18nEngine.DefaultInstanceKey);
|
|
191
|
-
|
|
192
|
-
if (shouldSetDefault) {
|
|
193
|
-
PluginI18nEngine._defaultKey = this.contextKey;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private resolveComponentAndKey(
|
|
199
|
-
prefix: string,
|
|
200
|
-
rawKey: string,
|
|
201
|
-
): { componentId: string; stringKey: string } {
|
|
202
|
-
const componentId = this.aliasToComponent.get(prefix) ?? prefix;
|
|
203
|
-
const keyLookup = this.componentKeyLookup.get(componentId);
|
|
204
|
-
|
|
205
|
-
if (!keyLookup) {
|
|
206
|
-
return { componentId, stringKey: rawKey };
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const directMatch = keyLookup.get(rawKey);
|
|
210
|
-
if (directMatch) {
|
|
211
|
-
return { componentId, stringKey: directMatch };
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const normalized = this.normalizeLegacyKey(rawKey);
|
|
215
|
-
if (normalized) {
|
|
216
|
-
const normalizedMatch = keyLookup.get(normalized);
|
|
217
|
-
if (normalizedMatch) {
|
|
218
|
-
return { componentId, stringKey: normalizedMatch };
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return { componentId, stringKey: rawKey };
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private registerComponentMetadata<TStringKeys extends string>(
|
|
226
|
-
registration: ComponentRegistration<TStringKeys, TLanguages>,
|
|
227
|
-
): void {
|
|
228
|
-
const { component, enumName, enumObject, aliases } = registration;
|
|
229
|
-
const componentId = component.id;
|
|
230
|
-
|
|
231
|
-
const aliasSet = new Set<string>();
|
|
232
|
-
if (componentId) {
|
|
233
|
-
aliasSet.add(componentId);
|
|
234
|
-
}
|
|
235
|
-
if (enumName) {
|
|
236
|
-
aliasSet.add(enumName);
|
|
237
|
-
}
|
|
238
|
-
aliases?.forEach((alias) => {
|
|
239
|
-
if (alias) aliasSet.add(alias);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
aliasSet.forEach((alias) => {
|
|
243
|
-
const trimmed = alias.trim();
|
|
244
|
-
if (trimmed.length > 0) {
|
|
245
|
-
this.aliasToComponent.set(trimmed, componentId);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
if (!this.componentKeyLookup.has(componentId)) {
|
|
250
|
-
this.componentKeyLookup.set(componentId, new Map<string, string>());
|
|
251
|
-
}
|
|
252
|
-
const keyMap = this.componentKeyLookup.get(componentId)!;
|
|
253
|
-
|
|
254
|
-
const addKeyVariant = (aliasKey: string, canonicalKey: string) => {
|
|
255
|
-
if (!aliasKey || !canonicalKey) return;
|
|
256
|
-
keyMap.set(aliasKey, canonicalKey);
|
|
257
|
-
const normalized = this.normalizeLegacyKey(aliasKey);
|
|
258
|
-
if (normalized && normalized !== aliasKey) {
|
|
259
|
-
keyMap.set(normalized, canonicalKey);
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
component.stringKeys.forEach((key) => {
|
|
264
|
-
addKeyVariant(key, key);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
if (enumObject) {
|
|
268
|
-
Object.entries(enumObject).forEach(([enumKey, enumValue]) => {
|
|
269
|
-
if (typeof enumValue === 'string') {
|
|
270
|
-
addKeyVariant(enumKey, enumValue);
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
private normalizeLegacyKey(rawKey: string): string | null {
|
|
277
|
-
if (!rawKey) return null;
|
|
278
|
-
const normalized = rawKey
|
|
279
|
-
.replace(/[-\s]+/g, '_')
|
|
280
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
281
|
-
.replace(/__+/g, '_')
|
|
282
|
-
.toLowerCase();
|
|
283
|
-
return normalized.length > 0 ? normalized : null;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Create a new instance with a specific key
|
|
288
|
-
*/
|
|
289
|
-
public static createInstance<TLangs extends string>(
|
|
290
|
-
key: string,
|
|
291
|
-
initialLanguages: readonly LanguageDefinition[],
|
|
292
|
-
config?: Partial<RegistryConfig<TLangs>>,
|
|
293
|
-
): PluginI18nEngine<TLangs> {
|
|
294
|
-
if (PluginI18nEngine._instances.has(key)) {
|
|
295
|
-
throw RegistryError.createSimple(
|
|
296
|
-
RegistryErrorType.DuplicateComponent,
|
|
297
|
-
`I18n instance with key '${key}' already exists`,
|
|
298
|
-
{ key },
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const instance = new PluginI18nEngine<TLangs>(initialLanguages, config, {
|
|
303
|
-
instanceKey: key,
|
|
304
|
-
registerInstance: false,
|
|
305
|
-
});
|
|
306
|
-
instance.contextKey = key;
|
|
307
|
-
|
|
308
|
-
// Create context for this specific instance (constructor already did this,
|
|
309
|
-
// but we ensure the latest configuration is applied for explicit instances)
|
|
310
|
-
const globalContext = GlobalActiveContext.getInstance();
|
|
311
|
-
globalContext.createContext(
|
|
312
|
-
instance.config.defaultLanguage,
|
|
313
|
-
instance.config.defaultLanguage,
|
|
314
|
-
key,
|
|
315
|
-
);
|
|
316
|
-
globalContext.setCurrencyCode(instance.config.defaultCurrencyCode, key);
|
|
317
|
-
globalContext.setUserTimezone(instance.config.timezone, key);
|
|
318
|
-
globalContext.setAdminTimezone(instance.config.adminTimezone, key);
|
|
319
|
-
|
|
320
|
-
PluginI18nEngine._instances.set(key, instance);
|
|
321
|
-
|
|
322
|
-
if (!PluginI18nEngine._defaultKey) {
|
|
323
|
-
PluginI18nEngine._defaultKey = key;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return instance;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Get an existing instance by key
|
|
331
|
-
*/
|
|
332
|
-
public static getInstance<TLangs extends string>(
|
|
333
|
-
key?: string,
|
|
334
|
-
): PluginI18nEngine<TLangs> {
|
|
335
|
-
const instanceKey =
|
|
336
|
-
key ||
|
|
337
|
-
PluginI18nEngine._defaultKey ||
|
|
338
|
-
PluginI18nEngine.DefaultInstanceKey;
|
|
339
|
-
const instance = PluginI18nEngine._instances.get(instanceKey);
|
|
340
|
-
|
|
341
|
-
if (!instance) {
|
|
342
|
-
throw RegistryError.createSimple(
|
|
343
|
-
RegistryErrorType.ComponentNotFound,
|
|
344
|
-
`I18n instance with key '${instanceKey}' not found`,
|
|
345
|
-
{ key: instanceKey },
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return instance as PluginI18nEngine<TLangs>;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Register a new language (updates static registry)
|
|
354
|
-
*/
|
|
355
|
-
public registerLanguage(language: LanguageDefinition): void {
|
|
356
|
-
LanguageRegistry.registerLanguage(language);
|
|
357
|
-
|
|
358
|
-
// Update component registry with new language
|
|
359
|
-
const newLanguages = LanguageRegistry.getLanguageIds();
|
|
360
|
-
this.componentRegistry.updateRegisteredLanguages(
|
|
361
|
-
newLanguages as TLanguages[],
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Register multiple languages (updates static registry)
|
|
367
|
-
*/
|
|
368
|
-
public registerLanguages(languages: readonly LanguageDefinition[]): void {
|
|
369
|
-
for (const language of languages) {
|
|
370
|
-
this.registerLanguage(language);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Register a component with its translations
|
|
376
|
-
*/
|
|
377
|
-
public registerComponent<TStringKeys extends string>(
|
|
378
|
-
registration: ComponentRegistration<TStringKeys, TLanguages>,
|
|
379
|
-
) {
|
|
380
|
-
const validationResult =
|
|
381
|
-
this.componentRegistry.registerComponent(registration);
|
|
382
|
-
this.registerComponentMetadata(registration);
|
|
383
|
-
return validationResult;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Register a component only if it doesn't already exist
|
|
388
|
-
*/
|
|
389
|
-
public registerComponentIfNotExists<TStringKeys extends string>(
|
|
390
|
-
registration: ComponentRegistration<TStringKeys, TLanguages>,
|
|
391
|
-
) {
|
|
392
|
-
if (this.hasComponent(registration.component.id)) {
|
|
393
|
-
return { isValid: true, errors: [], warnings: [] };
|
|
394
|
-
}
|
|
395
|
-
return this.registerComponent(registration);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Update strings for an existing component
|
|
400
|
-
*/
|
|
401
|
-
public updateComponentStrings<TStringKeys extends string>(
|
|
402
|
-
componentId: string,
|
|
403
|
-
strings: Parameters<
|
|
404
|
-
ComponentRegistry<TLanguages>['updateComponentStrings']
|
|
405
|
-
>[1],
|
|
406
|
-
) {
|
|
407
|
-
return this.componentRegistry.updateComponentStrings(componentId, strings);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Register an enum with translations
|
|
412
|
-
*/
|
|
413
|
-
public registerEnum<TEnum extends string | number>(
|
|
414
|
-
enumObj: Record<string, TEnum>,
|
|
415
|
-
translations: EnumLanguageTranslation<TEnum, TLanguages>,
|
|
416
|
-
enumName: string,
|
|
417
|
-
): void {
|
|
418
|
-
this.enumRegistry.register(enumObj, translations, enumName);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Translate a string for a component
|
|
423
|
-
*/
|
|
424
|
-
public translate<TStringKeys extends string>(
|
|
425
|
-
componentId: string,
|
|
426
|
-
stringKey: TStringKeys,
|
|
427
|
-
variables?: Record<string, string | number>,
|
|
428
|
-
language?: TLanguages,
|
|
429
|
-
): string {
|
|
430
|
-
const request: TranslationRequest<TStringKeys, TLanguages> = {
|
|
431
|
-
componentId,
|
|
432
|
-
stringKey,
|
|
433
|
-
language: language || this.getCurrentLanguage(),
|
|
434
|
-
variables,
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
const response = this.componentRegistry.getTranslation(request);
|
|
438
|
-
return response.translation;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Safe translate that returns a placeholder if translation fails
|
|
443
|
-
*/
|
|
444
|
-
public safeTranslate(
|
|
445
|
-
componentId: string,
|
|
446
|
-
stringKey: string,
|
|
447
|
-
variables?: Record<string, string | number>,
|
|
448
|
-
language?: TLanguages,
|
|
449
|
-
): string {
|
|
450
|
-
try {
|
|
451
|
-
return this.translate(componentId, stringKey, variables, language);
|
|
452
|
-
} catch (error) {
|
|
453
|
-
// Return a placeholder if translation fails
|
|
454
|
-
return `[${componentId}.${stringKey}]`;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Translate an enum value
|
|
460
|
-
*/
|
|
461
|
-
public translateEnum<TEnum extends string | number>(
|
|
462
|
-
enumObj: Record<string, TEnum>,
|
|
463
|
-
value: TEnum,
|
|
464
|
-
language?: TLanguages,
|
|
465
|
-
): string {
|
|
466
|
-
return this.enumRegistry.translate(
|
|
467
|
-
enumObj,
|
|
468
|
-
value,
|
|
469
|
-
language || this.getCurrentLanguage(),
|
|
470
|
-
);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Get detailed translation response
|
|
475
|
-
*/
|
|
476
|
-
public getTranslationDetails<TStringKeys extends string>(
|
|
477
|
-
componentId: string,
|
|
478
|
-
stringKey: TStringKeys,
|
|
479
|
-
variables?: Record<string, string | number>,
|
|
480
|
-
language?: TLanguages,
|
|
481
|
-
): TranslationResponse {
|
|
482
|
-
const request: TranslationRequest<TStringKeys, TLanguages> = {
|
|
483
|
-
componentId,
|
|
484
|
-
stringKey,
|
|
485
|
-
language: language || this.getCurrentLanguage(),
|
|
486
|
-
variables,
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
return this.componentRegistry.getTranslation(request);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Get current context
|
|
494
|
-
*/
|
|
495
|
-
public getContext(): IActiveContext<TLanguages> {
|
|
496
|
-
const globalContext = GlobalActiveContext.getInstance<
|
|
497
|
-
TLanguages,
|
|
498
|
-
IActiveContext<TLanguages>
|
|
499
|
-
>();
|
|
500
|
-
return globalContext.getContext(this.contextKey);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* Update context
|
|
505
|
-
*/
|
|
506
|
-
public updateContext(updates: Partial<IActiveContext<TLanguages>>): void {
|
|
507
|
-
const globalContext = GlobalActiveContext.getInstance<
|
|
508
|
-
TLanguages,
|
|
509
|
-
IActiveContext<TLanguages>
|
|
510
|
-
>();
|
|
511
|
-
|
|
512
|
-
if (updates.language)
|
|
513
|
-
globalContext.setUserLanguage(updates.language, this.contextKey);
|
|
514
|
-
if (updates.adminLanguage)
|
|
515
|
-
globalContext.setAdminLanguage(updates.adminLanguage, this.contextKey);
|
|
516
|
-
if (updates.currencyCode)
|
|
517
|
-
globalContext.setCurrencyCode(updates.currencyCode, this.contextKey);
|
|
518
|
-
if (updates.currentContext)
|
|
519
|
-
globalContext.setLanguageContextSpace(
|
|
520
|
-
updates.currentContext,
|
|
521
|
-
this.contextKey,
|
|
522
|
-
);
|
|
523
|
-
if (updates.timezone)
|
|
524
|
-
globalContext.setUserTimezone(updates.timezone, this.contextKey);
|
|
525
|
-
if (updates.adminTimezone)
|
|
526
|
-
globalContext.setAdminTimezone(updates.adminTimezone, this.contextKey);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Get current language from global context
|
|
531
|
-
* Respects language context space (admin vs user)
|
|
532
|
-
*/
|
|
533
|
-
private getCurrentLanguage(): TLanguages {
|
|
534
|
-
const globalContext = GlobalActiveContext.getInstance<
|
|
535
|
-
TLanguages,
|
|
536
|
-
IActiveContext<TLanguages>
|
|
537
|
-
>();
|
|
538
|
-
const context = globalContext.getContext(this.contextKey);
|
|
539
|
-
return context.currentContext === 'admin'
|
|
540
|
-
? context.adminLanguage
|
|
541
|
-
: context.language;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Set current language
|
|
546
|
-
*/
|
|
547
|
-
public setLanguage(language: TLanguages): void {
|
|
548
|
-
if (!LanguageRegistry.hasLanguage(language)) {
|
|
549
|
-
throw RegistryError.createSimple(
|
|
550
|
-
RegistryErrorType.LanguageNotFound,
|
|
551
|
-
`Language '${language}' is not registered`,
|
|
552
|
-
{ language },
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
const globalContext = GlobalActiveContext.getInstance<
|
|
556
|
-
TLanguages,
|
|
557
|
-
IActiveContext<TLanguages>
|
|
558
|
-
>();
|
|
559
|
-
globalContext.setUserLanguage(language, this.contextKey);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* Get available languages from static registry
|
|
564
|
-
*/
|
|
565
|
-
public getLanguages(): readonly LanguageDefinition[] {
|
|
566
|
-
return LanguageRegistry.getAllLanguages();
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/**
|
|
570
|
-
* Get registered components
|
|
571
|
-
*/
|
|
572
|
-
public getComponents(): ReadonlyArray<ComponentDefinition<any>> {
|
|
573
|
-
return this.componentRegistry.getComponents();
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* Check if a component is registered
|
|
578
|
-
*/
|
|
579
|
-
public hasComponent(componentId: string): boolean {
|
|
580
|
-
return this.componentRegistry.hasComponent(componentId);
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
/**
|
|
584
|
-
* Check if a language is registered in static registry
|
|
585
|
-
*/
|
|
586
|
-
public hasLanguage(language: TLanguages): boolean {
|
|
587
|
-
return LanguageRegistry.hasLanguage(language);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Get language by code from static registry
|
|
592
|
-
*/
|
|
593
|
-
public getLanguageByCode(code: string): LanguageDefinition | undefined {
|
|
594
|
-
return LanguageRegistry.getLanguageByCode(code);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
* Get component registry for direct access
|
|
599
|
-
*/
|
|
600
|
-
public getComponentRegistry(): ComponentRegistry<TLanguages> {
|
|
601
|
-
return this.componentRegistry;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
* Get enum registry for direct access
|
|
606
|
-
*/
|
|
607
|
-
public getEnumRegistry(): EnumTranslationRegistry<string, TLanguages> {
|
|
608
|
-
return this.enumRegistry;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Validate that all components have complete translations
|
|
613
|
-
*/
|
|
614
|
-
public validateAllComponents(): {
|
|
615
|
-
isValid: boolean;
|
|
616
|
-
errors: string[];
|
|
617
|
-
warnings: string[];
|
|
618
|
-
} {
|
|
619
|
-
const errors: string[] = [];
|
|
620
|
-
const warnings: string[] = [];
|
|
621
|
-
let isValid = true;
|
|
622
|
-
|
|
623
|
-
const components = this.getComponents();
|
|
624
|
-
const languages = LanguageRegistry.getLanguageIds();
|
|
625
|
-
|
|
626
|
-
for (const component of components) {
|
|
627
|
-
const componentStrings = this.componentRegistry.getComponentStrings(
|
|
628
|
-
component.id,
|
|
629
|
-
);
|
|
630
|
-
|
|
631
|
-
if (!componentStrings) {
|
|
632
|
-
errors.push(`Component '${component.id}' has no registered strings`);
|
|
633
|
-
isValid = false;
|
|
634
|
-
continue;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
for (const language of languages) {
|
|
638
|
-
const languageStrings = componentStrings[language as TLanguages];
|
|
639
|
-
|
|
640
|
-
if (!languageStrings) {
|
|
641
|
-
errors.push(
|
|
642
|
-
`Component '${component.id}' missing strings for language '${language}'`,
|
|
643
|
-
);
|
|
644
|
-
isValid = false;
|
|
645
|
-
continue;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
for (const stringKey of component.stringKeys) {
|
|
649
|
-
if (!languageStrings[stringKey]) {
|
|
650
|
-
warnings.push(
|
|
651
|
-
`Component '${component.id}' missing key '${stringKey}' for language '${language}'`,
|
|
652
|
-
);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
return { isValid, errors, warnings };
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* Clear all component registrations for this instance (useful for testing)
|
|
663
|
-
*/
|
|
664
|
-
public clearAllComponents(): void {
|
|
665
|
-
this.componentRegistry.clearAllComponents();
|
|
666
|
-
this.aliasToComponent.clear();
|
|
667
|
-
this.componentKeyLookup.clear();
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* Remove a specific named instance
|
|
672
|
-
*/
|
|
673
|
-
public static removeInstance(key?: string): boolean {
|
|
674
|
-
const instanceKey = key || PluginI18nEngine.DefaultInstanceKey;
|
|
675
|
-
const removed = PluginI18nEngine._instances.delete(instanceKey);
|
|
676
|
-
|
|
677
|
-
// If we removed the default instance, clear the default key
|
|
678
|
-
if (removed && PluginI18nEngine._defaultKey === instanceKey) {
|
|
679
|
-
PluginI18nEngine._defaultKey = null;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
return removed;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* Check if an instance exists
|
|
687
|
-
*/
|
|
688
|
-
public static hasInstance(key?: string): boolean {
|
|
689
|
-
const instanceKey = key || PluginI18nEngine.DefaultInstanceKey;
|
|
690
|
-
return PluginI18nEngine._instances.has(instanceKey);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
/**
|
|
694
|
-
* Reset all plugin engines and clear component registrations
|
|
695
|
-
* Useful for test cleanup
|
|
696
|
-
*/
|
|
697
|
-
public static resetAll(): void {
|
|
698
|
-
// Clear component registrations for each engine BEFORE clearing instances
|
|
699
|
-
for (const engine of PluginI18nEngine._instances.values()) {
|
|
700
|
-
engine.clearAllComponents();
|
|
701
|
-
}
|
|
702
|
-
PluginI18nEngine._instances.clear();
|
|
703
|
-
PluginI18nEngine._defaultKey = null;
|
|
704
|
-
LanguageRegistry.clear();
|
|
705
|
-
GlobalActiveContext.clearAll();
|
|
706
|
-
}
|
|
707
|
-
}
|