@digitaldefiance/i18n-lib 3.8.0 → 3.8.1
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/LICENSE +21 -0
- package/README.md +182 -0
- package/package.json +12 -4
- package/src/{active-context.d.ts → active-context.ts} +0 -1
- package/src/builders/i18n-builder.ts +82 -0
- package/src/builders/{index.d.ts → index.ts} +1 -1
- package/src/component-definition.ts +11 -0
- package/src/component-registration.ts +29 -0
- package/src/component-registry.ts +432 -0
- package/src/context-error-type.ts +7 -0
- package/src/core/component-store.ts +241 -0
- package/src/core/context-manager.ts +113 -0
- package/src/core/enum-registry.ts +106 -0
- package/src/core/i18n-engine.ts +710 -0
- package/src/core/{index.d.ts → index.ts} +4 -1
- package/src/core/language-registry.ts +345 -0
- package/src/{core-component-id.d.ts → core-component-id.ts} +1 -2
- package/src/core-i18n.ts +270 -0
- package/src/core-plugin-factory.ts +111 -0
- package/src/core-string-key.ts +59 -0
- package/src/create-translation-adapter.ts +93 -0
- package/src/enum-registry.ts +152 -0
- package/src/errors/{base.d.ts → base.ts} +1 -1
- package/src/errors/context-error.ts +122 -0
- package/src/errors/enhanced-error-base.ts +260 -0
- package/src/errors/handleable.ts +152 -0
- package/src/errors/i18n-error.ts +494 -0
- package/src/errors/{index.d.ts → index.ts} +4 -1
- package/src/errors/simple-typed-error.ts +81 -0
- package/src/errors/{translatable-exports.d.ts → translatable-exports.ts} +1 -1
- package/src/errors/translatable-generic.ts +245 -0
- package/src/errors/translatable-handleable-generic.ts +222 -0
- package/src/errors/translatable.ts +138 -0
- package/src/errors/typed-handleable.ts +138 -0
- package/src/errors/typed.ts +617 -0
- package/src/gender/{gender-categories.d.ts → gender-categories.ts} +6 -2
- package/src/gender/gender-resolver.ts +40 -0
- package/src/gender/{index.d.ts → index.ts} +0 -1
- package/src/global-active-context.ts +266 -0
- package/src/icu/ast.ts +56 -0
- package/src/icu/compiler.ts +96 -0
- package/src/icu/formatter-registry.ts +36 -0
- package/src/icu/formatters/base-formatter.ts +8 -0
- package/src/icu/formatters/date-formatter.ts +30 -0
- package/src/icu/formatters/number-formatter.ts +32 -0
- package/src/icu/formatters/plural-formatter.ts +12 -0
- package/src/icu/formatters/select-formatter.ts +7 -0
- package/src/icu/formatters/selectordinal-formatter.ts +17 -0
- package/src/icu/formatters/time-formatter.ts +30 -0
- package/src/icu/helpers.ts +34 -0
- package/src/icu/parser.ts +242 -0
- package/src/icu/runtime.ts +37 -0
- package/src/icu/tokenizer.ts +212 -0
- package/src/icu/validator.ts +163 -0
- package/src/{index.d.ts → index.ts} +38 -6
- package/src/interfaces/active-context.interface.ts +41 -0
- package/src/interfaces/component-config.interface.ts +17 -0
- package/src/interfaces/engine-config.interface.ts +22 -0
- package/src/interfaces/global-active-context.ts +39 -0
- package/src/interfaces/handleable-error-options.ts +13 -0
- package/src/interfaces/handleable.ts +20 -0
- package/src/interfaces/i18n-engine.interface.ts +57 -0
- package/src/interfaces/{index.d.ts → index.ts} +1 -1
- package/src/interfaces/language-definition.interface.ts +17 -0
- package/src/interfaces/translation-options.interface.ts +15 -0
- package/src/interfaces/validation-result.interface.ts +24 -0
- package/src/language-codes.ts +40 -0
- package/src/language-definition.ts +13 -0
- package/src/plugin-i18n-engine.ts +707 -0
- package/src/pluralization/{index.d.ts → index.ts} +1 -1
- package/src/pluralization/language-plural-map.ts +186 -0
- package/src/pluralization/{plural-categories.d.ts → plural-categories.ts} +5 -3
- package/src/pluralization/plural-rules.ts +228 -0
- package/src/registry-config.ts +16 -0
- package/src/registry-error-type.ts +19 -0
- package/src/registry-error.ts +100 -0
- package/src/strict-types.ts +35 -0
- package/src/strings/de.ts +75 -0
- package/src/strings/en-GB.ts +74 -0
- package/src/strings/en-US.ts +74 -0
- package/src/strings/es.ts +74 -0
- package/src/strings/fr.ts +75 -0
- package/src/strings/ja.ts +73 -0
- package/src/strings/uk.ts +73 -0
- package/src/strings/zh-CN.ts +72 -0
- package/src/template.ts +72 -0
- package/src/translation-engine.ts +18 -0
- package/src/translation-request.ts +12 -0
- package/src/translation-response.ts +8 -0
- package/src/types/engine.ts +55 -0
- package/src/types/{index.d.ts → index.ts} +1 -1
- package/src/types/{plural-types.d.ts → plural-types.ts} +29 -3
- package/src/{types.d.ts → types.ts} +72 -21
- package/src/utils/currency.ts +141 -0
- package/src/utils/html-escape.ts +55 -0
- package/src/utils/{index.d.ts → index.ts} +0 -1
- package/src/utils/lru-cache.ts +76 -0
- package/src/utils/{plural-helpers.d.ts → plural-helpers.ts} +14 -4
- package/src/utils/{safe-object.js → safe-object.ts} +37 -34
- package/src/utils/string-utils.ts +77 -0
- package/src/utils/timezone.ts +76 -0
- package/src/utils/validation.ts +66 -0
- package/src/utils.ts +215 -0
- package/src/validation/{index.d.ts → index.ts} +0 -1
- package/src/validation/plural-validator.ts +168 -0
- package/src/validation-config.ts +11 -0
- package/src/validation-result.ts +12 -0
- package/src/active-context.d.ts.map +0 -1
- package/src/active-context.js +0 -3
- package/src/active-context.js.map +0 -1
- package/src/builders/i18n-builder.d.ts +0 -26
- package/src/builders/i18n-builder.d.ts.map +0 -1
- package/src/builders/i18n-builder.js +0 -70
- package/src/builders/i18n-builder.js.map +0 -1
- package/src/builders/index.d.ts.map +0 -1
- package/src/builders/index.js +0 -8
- package/src/builders/index.js.map +0 -1
- package/src/component-definition.d.ts +0 -12
- package/src/component-definition.d.ts.map +0 -1
- package/src/component-definition.js +0 -3
- package/src/component-definition.js.map +0 -1
- package/src/component-registration.d.ts +0 -22
- package/src/component-registration.d.ts.map +0 -1
- package/src/component-registration.js +0 -3
- package/src/component-registration.js.map +0 -1
- package/src/component-registry.d.ts +0 -102
- package/src/component-registry.d.ts.map +0 -1
- package/src/component-registry.js +0 -282
- package/src/component-registry.js.map +0 -1
- package/src/context-error-type.d.ts +0 -8
- package/src/context-error-type.d.ts.map +0 -1
- package/src/context-error-type.js +0 -12
- package/src/context-error-type.js.map +0 -1
- package/src/core/component-store.d.ts +0 -93
- package/src/core/component-store.d.ts.map +0 -1
- package/src/core/component-store.js +0 -198
- package/src/core/component-store.js.map +0 -1
- package/src/core/context-manager.d.ts +0 -72
- package/src/core/context-manager.d.ts.map +0 -1
- package/src/core/context-manager.js +0 -98
- package/src/core/context-manager.js.map +0 -1
- package/src/core/enum-registry.d.ts +0 -48
- package/src/core/enum-registry.d.ts.map +0 -1
- package/src/core/enum-registry.js +0 -85
- package/src/core/enum-registry.js.map +0 -1
- package/src/core/i18n-engine.d.ts +0 -241
- package/src/core/i18n-engine.d.ts.map +0 -1
- package/src/core/i18n-engine.js +0 -568
- package/src/core/i18n-engine.js.map +0 -1
- package/src/core/index.d.ts.map +0 -1
- package/src/core/index.js +0 -21
- package/src/core/index.js.map +0 -1
- package/src/core/language-registry.d.ts +0 -180
- package/src/core/language-registry.d.ts.map +0 -1
- package/src/core/language-registry.js +0 -298
- package/src/core/language-registry.js.map +0 -1
- package/src/core-component-id.d.ts.map +0 -1
- package/src/core-component-id.js +0 -9
- package/src/core-component-id.js.map +0 -1
- package/src/core-i18n.d.ts +0 -69
- package/src/core-i18n.d.ts.map +0 -1
- package/src/core-i18n.js +0 -219
- package/src/core-i18n.js.map +0 -1
- package/src/core-plugin-factory.d.ts +0 -28
- package/src/core-plugin-factory.d.ts.map +0 -1
- package/src/core-plugin-factory.js +0 -80
- package/src/core-plugin-factory.js.map +0 -1
- package/src/core-string-key.d.ts +0 -52
- package/src/core-string-key.d.ts.map +0 -1
- package/src/core-string-key.js +0 -61
- package/src/core-string-key.js.map +0 -1
- package/src/create-translation-adapter.d.ts +0 -33
- package/src/create-translation-adapter.d.ts.map +0 -1
- package/src/create-translation-adapter.js +0 -72
- package/src/create-translation-adapter.js.map +0 -1
- package/src/enum-registry.d.ts +0 -65
- package/src/enum-registry.d.ts.map +0 -1
- package/src/enum-registry.js +0 -123
- package/src/enum-registry.js.map +0 -1
- package/src/errors/base.d.ts.map +0 -1
- package/src/errors/base.js +0 -11
- package/src/errors/base.js.map +0 -1
- package/src/errors/context-error.d.ts +0 -50
- package/src/errors/context-error.d.ts.map +0 -1
- package/src/errors/context-error.js +0 -93
- package/src/errors/context-error.js.map +0 -1
- package/src/errors/enhanced-error-base.d.ts +0 -125
- package/src/errors/enhanced-error-base.d.ts.map +0 -1
- package/src/errors/enhanced-error-base.js +0 -165
- package/src/errors/enhanced-error-base.js.map +0 -1
- package/src/errors/handleable.d.ts +0 -83
- package/src/errors/handleable.d.ts.map +0 -1
- package/src/errors/handleable.js +0 -136
- package/src/errors/handleable.js.map +0 -1
- package/src/errors/i18n-error.d.ts +0 -211
- package/src/errors/i18n-error.d.ts.map +0 -1
- package/src/errors/i18n-error.js +0 -358
- package/src/errors/i18n-error.js.map +0 -1
- package/src/errors/index.d.ts.map +0 -1
- package/src/errors/index.js +0 -17
- package/src/errors/index.js.map +0 -1
- package/src/errors/simple-typed-error.d.ts +0 -53
- package/src/errors/simple-typed-error.d.ts.map +0 -1
- package/src/errors/simple-typed-error.js +0 -51
- package/src/errors/simple-typed-error.js.map +0 -1
- package/src/errors/translatable-exports.d.ts.map +0 -1
- package/src/errors/translatable-exports.js +0 -15
- package/src/errors/translatable-exports.js.map +0 -1
- package/src/errors/translatable-generic.d.ts +0 -87
- package/src/errors/translatable-generic.d.ts.map +0 -1
- package/src/errors/translatable-generic.js +0 -139
- package/src/errors/translatable-generic.js.map +0 -1
- package/src/errors/translatable-handleable-generic.d.ts +0 -116
- package/src/errors/translatable-handleable-generic.d.ts.map +0 -1
- package/src/errors/translatable-handleable-generic.js +0 -121
- package/src/errors/translatable-handleable-generic.js.map +0 -1
- package/src/errors/translatable.d.ts +0 -63
- package/src/errors/translatable.d.ts.map +0 -1
- package/src/errors/translatable.js +0 -85
- package/src/errors/translatable.js.map +0 -1
- package/src/errors/typed-handleable.d.ts +0 -62
- package/src/errors/typed-handleable.d.ts.map +0 -1
- package/src/errors/typed-handleable.js +0 -108
- package/src/errors/typed-handleable.js.map +0 -1
- package/src/errors/typed.d.ts +0 -206
- package/src/errors/typed.d.ts.map +0 -1
- package/src/errors/typed.js +0 -458
- package/src/errors/typed.js.map +0 -1
- package/src/gender/gender-categories.d.ts.map +0 -1
- package/src/gender/gender-categories.js +0 -15
- package/src/gender/gender-categories.js.map +0 -1
- package/src/gender/gender-resolver.d.ts +0 -14
- package/src/gender/gender-resolver.d.ts.map +0 -1
- package/src/gender/gender-resolver.js +0 -35
- package/src/gender/gender-resolver.js.map +0 -1
- package/src/gender/index.d.ts.map +0 -1
- package/src/gender/index.js +0 -6
- package/src/gender/index.js.map +0 -1
- package/src/global-active-context.d.ts +0 -50
- package/src/global-active-context.d.ts.map +0 -1
- package/src/global-active-context.js +0 -185
- package/src/global-active-context.js.map +0 -1
- package/src/icu/ast.d.ts +0 -48
- package/src/icu/ast.d.ts.map +0 -1
- package/src/icu/ast.js +0 -16
- package/src/icu/ast.js.map +0 -1
- package/src/icu/compiler.d.ts +0 -16
- package/src/icu/compiler.d.ts.map +0 -1
- package/src/icu/compiler.js +0 -87
- package/src/icu/compiler.js.map +0 -1
- package/src/icu/formatter-registry.d.ts +0 -10
- package/src/icu/formatter-registry.d.ts.map +0 -1
- package/src/icu/formatter-registry.js +0 -34
- package/src/icu/formatter-registry.js.map +0 -1
- package/src/icu/formatters/base-formatter.d.ts +0 -8
- package/src/icu/formatters/base-formatter.d.ts.map +0 -1
- package/src/icu/formatters/base-formatter.js +0 -3
- package/src/icu/formatters/base-formatter.js.map +0 -1
- package/src/icu/formatters/date-formatter.d.ts +0 -5
- package/src/icu/formatters/date-formatter.d.ts.map +0 -1
- package/src/icu/formatters/date-formatter.js +0 -31
- package/src/icu/formatters/date-formatter.js.map +0 -1
- package/src/icu/formatters/number-formatter.d.ts +0 -5
- package/src/icu/formatters/number-formatter.d.ts.map +0 -1
- package/src/icu/formatters/number-formatter.js +0 -33
- package/src/icu/formatters/number-formatter.js.map +0 -1
- package/src/icu/formatters/plural-formatter.d.ts +0 -5
- package/src/icu/formatters/plural-formatter.d.ts.map +0 -1
- package/src/icu/formatters/plural-formatter.js +0 -15
- package/src/icu/formatters/plural-formatter.js.map +0 -1
- package/src/icu/formatters/select-formatter.d.ts +0 -5
- package/src/icu/formatters/select-formatter.d.ts.map +0 -1
- package/src/icu/formatters/select-formatter.js +0 -10
- package/src/icu/formatters/select-formatter.js.map +0 -1
- package/src/icu/formatters/selectordinal-formatter.d.ts +0 -5
- package/src/icu/formatters/selectordinal-formatter.d.ts.map +0 -1
- package/src/icu/formatters/selectordinal-formatter.js +0 -22
- package/src/icu/formatters/selectordinal-formatter.js.map +0 -1
- package/src/icu/formatters/time-formatter.d.ts +0 -5
- package/src/icu/formatters/time-formatter.d.ts.map +0 -1
- package/src/icu/formatters/time-formatter.js +0 -31
- package/src/icu/formatters/time-formatter.js.map +0 -1
- package/src/icu/helpers.d.ts +0 -9
- package/src/icu/helpers.d.ts.map +0 -1
- package/src/icu/helpers.js +0 -31
- package/src/icu/helpers.js.map +0 -1
- package/src/icu/parser.d.ts +0 -31
- package/src/icu/parser.d.ts.map +0 -1
- package/src/icu/parser.js +0 -203
- package/src/icu/parser.js.map +0 -1
- package/src/icu/runtime.d.ts +0 -10
- package/src/icu/runtime.d.ts.map +0 -1
- package/src/icu/runtime.js +0 -33
- package/src/icu/runtime.js.map +0 -1
- package/src/icu/tokenizer.d.ts +0 -37
- package/src/icu/tokenizer.d.ts.map +0 -1
- package/src/icu/tokenizer.js +0 -187
- package/src/icu/tokenizer.js.map +0 -1
- package/src/icu/validator.d.ts +0 -11
- package/src/icu/validator.d.ts.map +0 -1
- package/src/icu/validator.js +0 -140
- package/src/icu/validator.js.map +0 -1
- package/src/index.d.ts.map +0 -1
- package/src/index.js +0 -76
- package/src/index.js.map +0 -1
- package/src/interfaces/active-context.interface.d.ts +0 -36
- package/src/interfaces/active-context.interface.d.ts.map +0 -1
- package/src/interfaces/active-context.interface.js +0 -3
- package/src/interfaces/active-context.interface.js.map +0 -1
- package/src/interfaces/component-config.interface.d.ts +0 -16
- package/src/interfaces/component-config.interface.d.ts.map +0 -1
- package/src/interfaces/component-config.interface.js +0 -6
- package/src/interfaces/component-config.interface.js.map +0 -1
- package/src/interfaces/engine-config.interface.d.ts +0 -22
- package/src/interfaces/engine-config.interface.d.ts.map +0 -1
- package/src/interfaces/engine-config.interface.js +0 -6
- package/src/interfaces/engine-config.interface.js.map +0 -1
- package/src/interfaces/global-active-context.d.ts +0 -23
- package/src/interfaces/global-active-context.d.ts.map +0 -1
- package/src/interfaces/global-active-context.js +0 -3
- package/src/interfaces/global-active-context.js.map +0 -1
- package/src/interfaces/handleable-error-options.d.ts +0 -14
- package/src/interfaces/handleable-error-options.d.ts.map +0 -1
- package/src/interfaces/handleable-error-options.js +0 -3
- package/src/interfaces/handleable-error-options.js.map +0 -1
- package/src/interfaces/handleable.d.ts +0 -21
- package/src/interfaces/handleable.d.ts.map +0 -1
- package/src/interfaces/handleable.js +0 -3
- package/src/interfaces/handleable.js.map +0 -1
- package/src/interfaces/i18n-engine.interface.d.ts +0 -46
- package/src/interfaces/i18n-engine.interface.d.ts.map +0 -1
- package/src/interfaces/i18n-engine.interface.js +0 -6
- package/src/interfaces/i18n-engine.interface.js.map +0 -1
- package/src/interfaces/index.d.ts.map +0 -1
- package/src/interfaces/index.js +0 -7
- package/src/interfaces/index.js.map +0 -1
- package/src/interfaces/language-definition.interface.d.ts +0 -17
- package/src/interfaces/language-definition.interface.d.ts.map +0 -1
- package/src/interfaces/language-definition.interface.js +0 -6
- package/src/interfaces/language-definition.interface.js.map +0 -1
- package/src/interfaces/translation-options.interface.d.ts +0 -15
- package/src/interfaces/translation-options.interface.d.ts.map +0 -1
- package/src/interfaces/translation-options.interface.js +0 -6
- package/src/interfaces/translation-options.interface.js.map +0 -1
- package/src/interfaces/validation-result.interface.d.ts +0 -24
- package/src/interfaces/validation-result.interface.d.ts.map +0 -1
- package/src/interfaces/validation-result.interface.js +0 -6
- package/src/interfaces/validation-result.interface.js.map +0 -1
- package/src/language-codes.d.ts +0 -28
- package/src/language-codes.d.ts.map +0 -1
- package/src/language-codes.js +0 -32
- package/src/language-codes.js.map +0 -1
- package/src/language-definition.d.ts +0 -14
- package/src/language-definition.d.ts.map +0 -1
- package/src/language-definition.js +0 -3
- package/src/language-definition.js.map +0 -1
- package/src/plugin-i18n-engine.d.ts +0 -164
- package/src/plugin-i18n-engine.d.ts.map +0 -1
- package/src/plugin-i18n-engine.js +0 -493
- package/src/plugin-i18n-engine.js.map +0 -1
- package/src/pluralization/index.d.ts.map +0 -1
- package/src/pluralization/index.js +0 -10
- package/src/pluralization/index.js.map +0 -1
- package/src/pluralization/language-plural-map.d.ts +0 -29
- package/src/pluralization/language-plural-map.d.ts.map +0 -1
- package/src/pluralization/language-plural-map.js +0 -155
- package/src/pluralization/language-plural-map.js.map +0 -1
- package/src/pluralization/plural-categories.d.ts.map +0 -1
- package/src/pluralization/plural-categories.js +0 -8
- package/src/pluralization/plural-categories.js.map +0 -1
- package/src/pluralization/plural-rules.d.ts +0 -102
- package/src/pluralization/plural-rules.d.ts.map +0 -1
- package/src/pluralization/plural-rules.js +0 -263
- package/src/pluralization/plural-rules.js.map +0 -1
- package/src/registry-config.d.ts +0 -16
- package/src/registry-config.d.ts.map +0 -1
- package/src/registry-config.js +0 -3
- package/src/registry-config.js.map +0 -1
- package/src/registry-error-type.d.ts +0 -20
- package/src/registry-error-type.d.ts.map +0 -1
- package/src/registry-error-type.js +0 -24
- package/src/registry-error-type.js.map +0 -1
- package/src/registry-error.d.ts +0 -25
- package/src/registry-error.d.ts.map +0 -1
- package/src/registry-error.js +0 -63
- package/src/registry-error.js.map +0 -1
- package/src/strict-types.d.ts +0 -19
- package/src/strict-types.d.ts.map +0 -1
- package/src/strict-types.js +0 -18
- package/src/strict-types.js.map +0 -1
- package/src/strings/de.d.ts +0 -3
- package/src/strings/de.d.ts.map +0 -1
- package/src/strings/de.js +0 -57
- package/src/strings/de.js.map +0 -1
- package/src/strings/en-GB.d.ts +0 -3
- package/src/strings/en-GB.d.ts.map +0 -1
- package/src/strings/en-GB.js +0 -57
- package/src/strings/en-GB.js.map +0 -1
- package/src/strings/en-US.d.ts +0 -3
- package/src/strings/en-US.d.ts.map +0 -1
- package/src/strings/en-US.js +0 -57
- package/src/strings/en-US.js.map +0 -1
- package/src/strings/es.d.ts +0 -3
- package/src/strings/es.d.ts.map +0 -1
- package/src/strings/es.js +0 -57
- package/src/strings/es.js.map +0 -1
- package/src/strings/fr.d.ts +0 -3
- package/src/strings/fr.d.ts.map +0 -1
- package/src/strings/fr.js +0 -57
- package/src/strings/fr.js.map +0 -1
- package/src/strings/ja.d.ts +0 -3
- package/src/strings/ja.d.ts.map +0 -1
- package/src/strings/ja.js +0 -57
- package/src/strings/ja.js.map +0 -1
- package/src/strings/uk.d.ts +0 -3
- package/src/strings/uk.d.ts.map +0 -1
- package/src/strings/uk.js +0 -57
- package/src/strings/uk.js.map +0 -1
- package/src/strings/zh-CN.d.ts +0 -3
- package/src/strings/zh-CN.d.ts.map +0 -1
- package/src/strings/zh-CN.js +0 -57
- package/src/strings/zh-CN.js.map +0 -1
- package/src/template.d.ts +0 -13
- package/src/template.d.ts.map +0 -1
- package/src/template.js +0 -40
- package/src/template.js.map +0 -1
- package/src/translation-engine.d.ts +0 -9
- package/src/translation-engine.d.ts.map +0 -1
- package/src/translation-engine.js +0 -3
- package/src/translation-engine.js.map +0 -1
- package/src/translation-request.d.ts +0 -10
- package/src/translation-request.d.ts.map +0 -1
- package/src/translation-request.js +0 -3
- package/src/translation-request.js.map +0 -1
- package/src/translation-response.d.ts +0 -9
- package/src/translation-response.d.ts.map +0 -1
- package/src/translation-response.js +0 -3
- package/src/translation-response.js.map +0 -1
- package/src/types/engine.d.ts +0 -47
- package/src/types/engine.d.ts.map +0 -1
- package/src/types/engine.js +0 -8
- package/src/types/engine.js.map +0 -1
- package/src/types/index.d.ts.map +0 -1
- package/src/types/index.js +0 -9
- package/src/types/index.js.map +0 -1
- package/src/types/plural-types.d.ts.map +0 -1
- package/src/types/plural-types.js +0 -39
- package/src/types/plural-types.js.map +0 -1
- package/src/types.d.ts.map +0 -1
- package/src/types.js +0 -23
- package/src/types.js.map +0 -1
- package/src/utils/currency.d.ts +0 -81
- package/src/utils/currency.d.ts.map +0 -1
- package/src/utils/currency.js +0 -99
- package/src/utils/currency.js.map +0 -1
- package/src/utils/html-escape.d.ts +0 -22
- package/src/utils/html-escape.d.ts.map +0 -1
- package/src/utils/html-escape.js +0 -53
- package/src/utils/html-escape.js.map +0 -1
- package/src/utils/index.d.ts.map +0 -1
- package/src/utils/index.js +0 -12
- package/src/utils/index.js.map +0 -1
- package/src/utils/lru-cache.d.ts +0 -42
- package/src/utils/lru-cache.d.ts.map +0 -1
- package/src/utils/lru-cache.js +0 -73
- package/src/utils/lru-cache.js.map +0 -1
- package/src/utils/plural-helpers.d.ts.map +0 -1
- package/src/utils/plural-helpers.js +0 -35
- package/src/utils/plural-helpers.js.map +0 -1
- package/src/utils/safe-object.d.ts +0 -39
- package/src/utils/safe-object.d.ts.map +0 -1
- package/src/utils/safe-object.js.map +0 -1
- package/src/utils/string-utils.d.ts +0 -28
- package/src/utils/string-utils.d.ts.map +0 -1
- package/src/utils/string-utils.js +0 -63
- package/src/utils/string-utils.js.map +0 -1
- package/src/utils/timezone.d.ts +0 -50
- package/src/utils/timezone.d.ts.map +0 -1
- package/src/utils/timezone.js +0 -74
- package/src/utils/timezone.js.map +0 -1
- package/src/utils/validation.d.ts +0 -40
- package/src/utils/validation.d.ts.map +0 -1
- package/src/utils/validation.js +0 -69
- package/src/utils/validation.js.map +0 -1
- package/src/utils.d.ts +0 -65
- package/src/utils.d.ts.map +0 -1
- package/src/utils.js +0 -129
- package/src/utils.js.map +0 -1
- package/src/validation/index.d.ts.map +0 -1
- package/src/validation/index.js +0 -5
- package/src/validation/index.js.map +0 -1
- package/src/validation/plural-validator.d.ts +0 -46
- package/src/validation/plural-validator.d.ts.map +0 -1
- package/src/validation/plural-validator.js +0 -123
- package/src/validation/plural-validator.js.map +0 -1
- package/src/validation-config.d.ts +0 -12
- package/src/validation-config.d.ts.map +0 -1
- package/src/validation-config.js +0 -3
- package/src/validation-config.js.map +0 -1
- package/src/validation-result.d.ts +0 -13
- package/src/validation-result.d.ts.map +0 -1
- package/src/validation-result.js +0 -3
- package/src/validation-result.js.map +0 -1
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Component registry for managing internationalization components and their string translations
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ComponentRegistry = void 0;
|
|
7
|
-
const registry_error_1 = require("./registry-error");
|
|
8
|
-
const registry_error_type_1 = require("./registry-error-type");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
/**
|
|
11
|
-
* Registry for managing components and their translations
|
|
12
|
-
*/
|
|
13
|
-
class ComponentRegistry {
|
|
14
|
-
components = new Map();
|
|
15
|
-
componentStrings = new Map();
|
|
16
|
-
validationConfig;
|
|
17
|
-
registeredLanguages;
|
|
18
|
-
constants;
|
|
19
|
-
/**
|
|
20
|
-
* Creates a new ComponentRegistry.
|
|
21
|
-
* @param languages - Array of supported language codes.
|
|
22
|
-
* @param validationConfig - Configuration for validation rules.
|
|
23
|
-
* @param constants - Optional constants for variable replacement in templates.
|
|
24
|
-
*/
|
|
25
|
-
constructor(languages, validationConfig, constants) {
|
|
26
|
-
this.registeredLanguages = new Set(languages);
|
|
27
|
-
this.validationConfig = validationConfig;
|
|
28
|
-
this.constants = constants;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Update the set of registered languages (for dynamic language addition).
|
|
32
|
-
* @param languages - Array of language codes to register.
|
|
33
|
-
*/
|
|
34
|
-
updateRegisteredLanguages(languages) {
|
|
35
|
-
this.registeredLanguages.clear();
|
|
36
|
-
languages.forEach((lang) => this.registeredLanguages.add(lang));
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Register a new component with its translations.
|
|
40
|
-
* @param registration - Component registration payload.
|
|
41
|
-
* @returns ValidationResult indicating success or errors.
|
|
42
|
-
* @throws RegistryError if component is already registered or validation fails.
|
|
43
|
-
*/
|
|
44
|
-
registerComponent(registration) {
|
|
45
|
-
const { component, strings } = registration;
|
|
46
|
-
// Check for duplicate component
|
|
47
|
-
if (this.components.has(component.id)) {
|
|
48
|
-
throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.DuplicateComponent, `Component '${component.id}' is already registered`, { componentId: component.id });
|
|
49
|
-
}
|
|
50
|
-
// Validate the registration
|
|
51
|
-
const validationResult = this.validateComponentRegistration(registration);
|
|
52
|
-
if (!validationResult.isValid &&
|
|
53
|
-
!this.validationConfig.allowPartialRegistration) {
|
|
54
|
-
throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.ValidationFailed, `Component registration validation failed: ${validationResult.errors.join(', ')}`, {
|
|
55
|
-
componentId: component.id,
|
|
56
|
-
missingKeys: validationResult.missingKeys,
|
|
57
|
-
errors: validationResult.errors,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
// Complete missing strings with fallbacks if partial registration is allowed
|
|
61
|
-
const completeStrings = this.completeStringsWithFallbacks(component, strings);
|
|
62
|
-
// Register the component
|
|
63
|
-
this.components.set(component.id, component);
|
|
64
|
-
this.componentStrings.set(component.id, completeStrings);
|
|
65
|
-
return validationResult;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Update strings for an existing component.
|
|
69
|
-
* @param componentId - The ID of the component to update.
|
|
70
|
-
* @param strings - Partial strings to update.
|
|
71
|
-
* @returns ValidationResult indicating success or errors.
|
|
72
|
-
* @throws RegistryError if component is not found.
|
|
73
|
-
*/
|
|
74
|
-
updateComponentStrings(componentId, strings) {
|
|
75
|
-
const component = this.components.get(componentId);
|
|
76
|
-
if (!component) {
|
|
77
|
-
throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.ComponentNotFound, `Component with ID '${componentId}' not found`, { componentId });
|
|
78
|
-
}
|
|
79
|
-
const registration = {
|
|
80
|
-
component: component,
|
|
81
|
-
strings,
|
|
82
|
-
};
|
|
83
|
-
const validationResult = this.validateComponentRegistration(registration);
|
|
84
|
-
if (validationResult.isValid ||
|
|
85
|
-
this.validationConfig.allowPartialRegistration) {
|
|
86
|
-
const existingStrings = this.componentStrings.get(componentId) ||
|
|
87
|
-
{};
|
|
88
|
-
const updatedStrings = this.mergeStrings(existingStrings, strings);
|
|
89
|
-
const completeStrings = this.completeStringsWithFallbacks(component, updatedStrings);
|
|
90
|
-
this.componentStrings.set(componentId, completeStrings);
|
|
91
|
-
}
|
|
92
|
-
return validationResult;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Get a translation for a specific component, string key, and language.
|
|
96
|
-
* @param request - Translation request containing componentId, stringKey, language, and variables.
|
|
97
|
-
* @returns TranslationResponse with the translated string and metadata.
|
|
98
|
-
* @throws RegistryError if component, language, or string key is not found.
|
|
99
|
-
*/
|
|
100
|
-
getTranslation(request) {
|
|
101
|
-
const { componentId, stringKey, language, variables } = request;
|
|
102
|
-
// Check if component exists
|
|
103
|
-
if (!this.components.has(componentId)) {
|
|
104
|
-
throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.ComponentNotFound, `Component '${componentId}' not found`, { componentId });
|
|
105
|
-
}
|
|
106
|
-
const componentStrings = this.componentStrings.get(componentId);
|
|
107
|
-
if (!componentStrings) {
|
|
108
|
-
throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.StringKeyNotFound, `No strings registered for component '${componentId}'`, { componentId });
|
|
109
|
-
}
|
|
110
|
-
const targetLanguage = language || this.validationConfig.fallbackLanguageId;
|
|
111
|
-
let actualLanguage = targetLanguage;
|
|
112
|
-
let wasFallback = false;
|
|
113
|
-
// Try to get the string in the requested language
|
|
114
|
-
let languageStrings = componentStrings[targetLanguage];
|
|
115
|
-
// If not found and different from fallback, try fallback language
|
|
116
|
-
if (!languageStrings &&
|
|
117
|
-
targetLanguage !== this.validationConfig.fallbackLanguageId) {
|
|
118
|
-
languageStrings =
|
|
119
|
-
componentStrings[this.validationConfig.fallbackLanguageId];
|
|
120
|
-
actualLanguage = this.validationConfig.fallbackLanguageId;
|
|
121
|
-
wasFallback = true;
|
|
122
|
-
}
|
|
123
|
-
if (!languageStrings) {
|
|
124
|
-
throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.LanguageNotFound, `No strings found for language '${targetLanguage}' in component '${componentId}'`, { componentId, language: targetLanguage });
|
|
125
|
-
}
|
|
126
|
-
const translation = languageStrings[stringKey];
|
|
127
|
-
if (!translation) {
|
|
128
|
-
throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.StringKeyNotFound, `String key '${stringKey}' not found for component '${componentId}' in language '${actualLanguage}'`, { componentId, stringKey, language: actualLanguage });
|
|
129
|
-
}
|
|
130
|
-
// Process variables if the string key indicates it's a template
|
|
131
|
-
let processedTranslation = translation;
|
|
132
|
-
if ((0, utils_1.isTemplate)(stringKey)) {
|
|
133
|
-
processedTranslation = (0, utils_1.replaceVariables)(translation, variables, this.constants);
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
translation: processedTranslation,
|
|
137
|
-
actualLanguage,
|
|
138
|
-
wasFallback,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Get all registered components.
|
|
143
|
-
* @returns Array of all registered ComponentDefinition objects.
|
|
144
|
-
*/
|
|
145
|
-
getComponents() {
|
|
146
|
-
return Array.from(this.components.values());
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Get a specific component by ID.
|
|
150
|
-
* @param componentId - The ID of the component to retrieve.
|
|
151
|
-
* @returns The ComponentDefinition or undefined if not found.
|
|
152
|
-
*/
|
|
153
|
-
getComponent(componentId) {
|
|
154
|
-
return this.components.get(componentId);
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Check if a component is registered.
|
|
158
|
-
* @param componentId - The ID of the component to check.
|
|
159
|
-
* @returns True if the component is registered, false otherwise.
|
|
160
|
-
*/
|
|
161
|
-
hasComponent(componentId) {
|
|
162
|
-
return this.components.has(componentId);
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Get all strings for a component in all languages.
|
|
166
|
-
* @param componentId - The ID of the component.
|
|
167
|
-
* @returns ComponentLanguageStrings or undefined if not found.
|
|
168
|
-
*/
|
|
169
|
-
getComponentStrings(componentId) {
|
|
170
|
-
return this.componentStrings.get(componentId);
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Validate a component registration.
|
|
174
|
-
* @param registration - Component registration to validate.
|
|
175
|
-
* @returns ValidationResult with details of missing keys and errors.
|
|
176
|
-
*/
|
|
177
|
-
validateComponentRegistration(registration) {
|
|
178
|
-
const { component, strings } = registration;
|
|
179
|
-
const missingKeys = [];
|
|
180
|
-
const errors = [];
|
|
181
|
-
// Check if all required string keys are provided for each language
|
|
182
|
-
for (const languageId of this.registeredLanguages) {
|
|
183
|
-
const languageStrings = strings[languageId];
|
|
184
|
-
if (!languageStrings) {
|
|
185
|
-
if (this.validationConfig.requireCompleteStrings) {
|
|
186
|
-
errors.push(`Missing all strings for language '${languageId}' in component '${component.id}'`);
|
|
187
|
-
}
|
|
188
|
-
// Add all missing keys for this language
|
|
189
|
-
for (const stringKey of component.stringKeys) {
|
|
190
|
-
missingKeys.push({
|
|
191
|
-
languageId,
|
|
192
|
-
componentId: component.id,
|
|
193
|
-
stringKey,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
// Check individual string keys
|
|
199
|
-
for (const stringKey of component.stringKeys) {
|
|
200
|
-
if (!languageStrings[stringKey]) {
|
|
201
|
-
missingKeys.push({
|
|
202
|
-
languageId,
|
|
203
|
-
componentId: component.id,
|
|
204
|
-
stringKey,
|
|
205
|
-
});
|
|
206
|
-
if (this.validationConfig.requireCompleteStrings) {
|
|
207
|
-
errors.push(`Missing string key '${stringKey}' for language '${languageId}' in component '${component.id}'`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return {
|
|
213
|
-
isValid: missingKeys.length === 0,
|
|
214
|
-
missingKeys,
|
|
215
|
-
errors,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Complete missing strings with fallbacks.
|
|
220
|
-
* @param component - The component definition.
|
|
221
|
-
* @param strings - Partial strings provided.
|
|
222
|
-
* @returns Complete strings with fallbacks filled in.
|
|
223
|
-
*/
|
|
224
|
-
completeStringsWithFallbacks(component, strings) {
|
|
225
|
-
const result = {};
|
|
226
|
-
const fallbackLanguage = this.validationConfig
|
|
227
|
-
.fallbackLanguageId;
|
|
228
|
-
const fallbackStrings = strings[fallbackLanguage];
|
|
229
|
-
// Ensure all languages have all required keys
|
|
230
|
-
for (const languageId of this.registeredLanguages) {
|
|
231
|
-
const existingLanguageStrings = strings[languageId] || {};
|
|
232
|
-
const languageStrings = {};
|
|
233
|
-
for (const stringKey of component.stringKeys) {
|
|
234
|
-
if (existingLanguageStrings[stringKey]) {
|
|
235
|
-
languageStrings[stringKey] = existingLanguageStrings[stringKey];
|
|
236
|
-
}
|
|
237
|
-
else if (fallbackStrings && fallbackStrings[stringKey]) {
|
|
238
|
-
// Try to use fallback language
|
|
239
|
-
languageStrings[stringKey] = fallbackStrings[stringKey];
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
// Last resort: use a placeholder
|
|
243
|
-
languageStrings[stringKey] = `[${component.id}.${stringKey}]`;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
result[languageId] = languageStrings;
|
|
247
|
-
}
|
|
248
|
-
return result;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Merge existing strings with new strings.
|
|
252
|
-
* @param existing - Existing complete strings.
|
|
253
|
-
* @param updates - Partial updates to apply.
|
|
254
|
-
* @returns Merged partial strings.
|
|
255
|
-
*/
|
|
256
|
-
mergeStrings(existing, updates) {
|
|
257
|
-
const result = {};
|
|
258
|
-
// Copy existing strings
|
|
259
|
-
for (const [languageId, languageStrings] of Object.entries(existing)) {
|
|
260
|
-
result[languageId] = { ...languageStrings };
|
|
261
|
-
}
|
|
262
|
-
// Apply updates
|
|
263
|
-
for (const [languageId, languageStrings] of Object.entries(updates)) {
|
|
264
|
-
if (languageStrings) {
|
|
265
|
-
result[languageId] = {
|
|
266
|
-
...result[languageId],
|
|
267
|
-
...languageStrings,
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return result;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Clear all components and their strings (useful for testing).
|
|
275
|
-
*/
|
|
276
|
-
clearAllComponents() {
|
|
277
|
-
this.components.clear();
|
|
278
|
-
this.componentStrings.clear();
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
exports.ComponentRegistry = ComponentRegistry;
|
|
282
|
-
//# sourceMappingURL=component-registry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component-registry.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/component-registry.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH,qDAAiD;AACjD,+DAA0D;AAS1D,mCAAuD;AAIvD;;GAEG;AACH,MAAa,iBAAiB;IACX,UAAU,GAAG,IAAI,GAAG,EAAoC,CAAC;IACzD,gBAAgB,GAAG,IAAI,GAAG,EAGxC,CAAC;IACa,gBAAgB,CAAmB;IACnC,mBAAmB,CAAkB;IACrC,SAAS,CAAuB;IAEjD;;;;;OAKG;IACH,YACE,SAAgC,EAChC,gBAAkC,EAClC,SAA+B;QAE/B,IAAI,CAAC,mBAAmB,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC9C,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC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AAC,OAAO,CAG/D,EAAE,CAAC;YACJ,IAAI,eAAe,EAAE,CAAC;gBACpB,MAAM,CAAC,UAAU,CAAC,GAAG;oBACnB,GAAG,MAAM,CAAC,UAAU,CAAC;oBACrB,GAAG,eAAe;iBACnB,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,kBAAkB;QACvB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACF;AAxZD,8CAwZC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-error-type.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/context-error-type.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,gBAAgB;IAC1B,0DAA0D;IAC1D,cAAc,mBAAmB;CAClC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ContextErrorType = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Types of context-related errors
|
|
6
|
-
*/
|
|
7
|
-
var ContextErrorType;
|
|
8
|
-
(function (ContextErrorType) {
|
|
9
|
-
/** Error indicating an invalid or non-existent context */
|
|
10
|
-
ContextErrorType["InvalidContext"] = "InvalidContext";
|
|
11
|
-
})(ContextErrorType || (exports.ContextErrorType = ContextErrorType = {}));
|
|
12
|
-
//# sourceMappingURL=context-error-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-error-type.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/context-error-type.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,0DAA0D;IAC1D,qDAAiC,CAAA;AACnC,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Component storage (no generics)
|
|
3
|
-
*/
|
|
4
|
-
import { ComponentConfig, ValidationResult } from '../interfaces';
|
|
5
|
-
/**
|
|
6
|
-
* Class representing a storage for component configurations and translations.
|
|
7
|
-
*/
|
|
8
|
-
export declare class ComponentStore {
|
|
9
|
-
private components;
|
|
10
|
-
private aliasMap;
|
|
11
|
-
private constants?;
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new ComponentStore instance.
|
|
14
|
-
* @param constants - Optional constants to be used in variable replacement.
|
|
15
|
-
*/
|
|
16
|
-
constructor(constants?: Record<string, any>);
|
|
17
|
-
/**
|
|
18
|
-
* Registers a new component configuration.
|
|
19
|
-
* @param config - The component configuration to register.
|
|
20
|
-
* @returns ValidationResult indicating the result of the registration.
|
|
21
|
-
* @throws {I18nError} If the component ID is already registered.
|
|
22
|
-
*/
|
|
23
|
-
register(config: ComponentConfig): ValidationResult;
|
|
24
|
-
/**
|
|
25
|
-
* Updates an existing component's strings.
|
|
26
|
-
* @param componentId - The ID of the component to update.
|
|
27
|
-
* @param strings - The new strings to merge into the component.
|
|
28
|
-
* @returns ValidationResult indicating the result of the update.
|
|
29
|
-
* @throws {I18nError} If the component is not found.
|
|
30
|
-
*/
|
|
31
|
-
update(componentId: string, strings: Record<string, Record<string, string>>): ValidationResult;
|
|
32
|
-
/**
|
|
33
|
-
* Checks if a component or alias is registered.
|
|
34
|
-
* @param componentId - The component ID or alias to check.
|
|
35
|
-
* @returns True if the component or alias is registered, false otherwise.
|
|
36
|
-
*/
|
|
37
|
-
has(componentId: string): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Retrieves a component configuration by ID or alias.
|
|
40
|
-
* @param componentId - The component ID or alias to retrieve.
|
|
41
|
-
* @returns The component configuration.
|
|
42
|
-
* @throws {I18nError} If the component is not found.
|
|
43
|
-
*/
|
|
44
|
-
get(componentId: string): ComponentConfig;
|
|
45
|
-
/**
|
|
46
|
-
* Retrieves all registered component configurations.
|
|
47
|
-
* @returns An array of all component configurations.
|
|
48
|
-
*/
|
|
49
|
-
getAll(): readonly ComponentConfig[];
|
|
50
|
-
/**
|
|
51
|
-
* Translates a key for a component in a given language, replacing variables.
|
|
52
|
-
* @param componentId - The component ID.
|
|
53
|
-
* @param key - The translation key.
|
|
54
|
-
* @param variables - Optional variables for replacement.
|
|
55
|
-
* @param language - Optional language code (default is 'en-US').
|
|
56
|
-
* @returns The translated string.
|
|
57
|
-
* @throws {I18nError} If the language or translation key is not found.
|
|
58
|
-
*/
|
|
59
|
-
translate(componentId: string, key: string, variables?: Record<string, any>, language?: string): string;
|
|
60
|
-
/**
|
|
61
|
-
* Resolve plural form from a PluralString based on count variable.
|
|
62
|
-
* @param value - The string or PluralString to resolve.
|
|
63
|
-
* @param count - The count for pluralization.
|
|
64
|
-
* @param language - The language code.
|
|
65
|
-
* @returns The resolved plural form string.
|
|
66
|
-
*/
|
|
67
|
-
private resolvePluralForm;
|
|
68
|
-
/**
|
|
69
|
-
* Safely translates a key for a component, returning a fallback string on error.
|
|
70
|
-
* @param componentId - The component ID.
|
|
71
|
-
* @param key - The translation key.
|
|
72
|
-
* @param variables - Optional variables for replacement.
|
|
73
|
-
* @param language - Optional language code.
|
|
74
|
-
* @returns The translated string or a fallback string if translation fails.
|
|
75
|
-
*/
|
|
76
|
-
safeTranslate(componentId: string, key: string, variables?: Record<string, any>, language?: string): string;
|
|
77
|
-
/**
|
|
78
|
-
* Validates a component configuration for missing keys across languages.
|
|
79
|
-
* @param config - The component configuration to validate.
|
|
80
|
-
* @returns ValidationResult containing errors and warnings.
|
|
81
|
-
*/
|
|
82
|
-
private validate;
|
|
83
|
-
/**
|
|
84
|
-
* Sets constants for variable replacement.
|
|
85
|
-
* @param constants - The constants to set.
|
|
86
|
-
*/
|
|
87
|
-
setConstants(constants: Record<string, any>): void;
|
|
88
|
-
/**
|
|
89
|
-
* Clears all registered components and aliases.
|
|
90
|
-
*/
|
|
91
|
-
clear(): void;
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=component-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component-store.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-i18n-lib/src/core/component-store.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAKlE;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,UAAU,CAAsC;IACxD,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,SAAS,CAAC,CAAsB;IAExC;;;OAGG;gBACS,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAI3C;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,eAAe,GAAG,gBAAgB;IAkBnD;;;;;;OAMG;IACH,MAAM,CACJ,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC9C,gBAAgB;IAenB;;;;OAIG;IACH,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAIjC;;;;;OAKG;IACH,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,eAAe;IASzC;;;OAGG;IACH,MAAM,IAAI,SAAS,eAAe,EAAE;IAIpC;;;;;;;;OAQG;IACH,SAAS,CACP,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM;IAoBT;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAsBzB;;;;;;;OAOG;IACH,aAAa,CACX,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM;IAQT;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IA6BhB;;;OAGG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAIlD;;OAEG;IACH,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Component storage (no generics)
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ComponentStore = void 0;
|
|
7
|
-
const i18n_error_1 = require("../errors/i18n-error");
|
|
8
|
-
const language_plural_map_1 = require("../pluralization/language-plural-map");
|
|
9
|
-
const plural_types_1 = require("../types/plural-types");
|
|
10
|
-
const utils_1 = require("../utils");
|
|
11
|
-
/**
|
|
12
|
-
* Class representing a storage for component configurations and translations.
|
|
13
|
-
*/
|
|
14
|
-
class ComponentStore {
|
|
15
|
-
components = new Map();
|
|
16
|
-
aliasMap = new Map();
|
|
17
|
-
constants;
|
|
18
|
-
/**
|
|
19
|
-
* Creates a new ComponentStore instance.
|
|
20
|
-
* @param constants - Optional constants to be used in variable replacement.
|
|
21
|
-
*/
|
|
22
|
-
constructor(constants) {
|
|
23
|
-
this.constants = constants;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Registers a new component configuration.
|
|
27
|
-
* @param config - The component configuration to register.
|
|
28
|
-
* @returns ValidationResult indicating the result of the registration.
|
|
29
|
-
* @throws {I18nError} If the component ID is already registered.
|
|
30
|
-
*/
|
|
31
|
-
register(config) {
|
|
32
|
-
if (this.components.has(config.id)) {
|
|
33
|
-
throw i18n_error_1.I18nError.duplicateComponent(config.id);
|
|
34
|
-
}
|
|
35
|
-
const validation = this.validate(config);
|
|
36
|
-
this.components.set(config.id, config);
|
|
37
|
-
// Register aliases
|
|
38
|
-
if (config.aliases) {
|
|
39
|
-
for (const alias of config.aliases) {
|
|
40
|
-
this.aliasMap.set(alias, config.id);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return validation;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Updates an existing component's strings.
|
|
47
|
-
* @param componentId - The ID of the component to update.
|
|
48
|
-
* @param strings - The new strings to merge into the component.
|
|
49
|
-
* @returns ValidationResult indicating the result of the update.
|
|
50
|
-
* @throws {I18nError} If the component is not found.
|
|
51
|
-
*/
|
|
52
|
-
update(componentId, strings) {
|
|
53
|
-
const existing = this.components.get(componentId);
|
|
54
|
-
if (!existing) {
|
|
55
|
-
throw i18n_error_1.I18nError.componentNotFound(componentId);
|
|
56
|
-
}
|
|
57
|
-
const updated = {
|
|
58
|
-
...existing,
|
|
59
|
-
strings: { ...existing.strings, ...strings },
|
|
60
|
-
};
|
|
61
|
-
this.components.set(componentId, updated);
|
|
62
|
-
return this.validate(updated);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Checks if a component or alias is registered.
|
|
66
|
-
* @param componentId - The component ID or alias to check.
|
|
67
|
-
* @returns True if the component or alias is registered, false otherwise.
|
|
68
|
-
*/
|
|
69
|
-
has(componentId) {
|
|
70
|
-
return this.components.has(componentId) || this.aliasMap.has(componentId);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Retrieves a component configuration by ID or alias.
|
|
74
|
-
* @param componentId - The component ID or alias to retrieve.
|
|
75
|
-
* @returns The component configuration.
|
|
76
|
-
* @throws {I18nError} If the component is not found.
|
|
77
|
-
*/
|
|
78
|
-
get(componentId) {
|
|
79
|
-
const id = this.aliasMap.get(componentId) || componentId;
|
|
80
|
-
const component = this.components.get(id);
|
|
81
|
-
if (!component) {
|
|
82
|
-
throw i18n_error_1.I18nError.componentNotFound(componentId);
|
|
83
|
-
}
|
|
84
|
-
return component;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Retrieves all registered component configurations.
|
|
88
|
-
* @returns An array of all component configurations.
|
|
89
|
-
*/
|
|
90
|
-
getAll() {
|
|
91
|
-
return Array.from(this.components.values());
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Translates a key for a component in a given language, replacing variables.
|
|
95
|
-
* @param componentId - The component ID.
|
|
96
|
-
* @param key - The translation key.
|
|
97
|
-
* @param variables - Optional variables for replacement.
|
|
98
|
-
* @param language - Optional language code (default is 'en-US').
|
|
99
|
-
* @returns The translated string.
|
|
100
|
-
* @throws {I18nError} If the language or translation key is not found.
|
|
101
|
-
*/
|
|
102
|
-
translate(componentId, key, variables, language) {
|
|
103
|
-
const component = this.get(componentId);
|
|
104
|
-
const lang = language || 'en-US';
|
|
105
|
-
const langStrings = component.strings[lang];
|
|
106
|
-
if (!langStrings) {
|
|
107
|
-
throw i18n_error_1.I18nError.languageNotFound(lang);
|
|
108
|
-
}
|
|
109
|
-
const value = langStrings[key];
|
|
110
|
-
if (!value) {
|
|
111
|
-
throw i18n_error_1.I18nError.translationMissing(componentId, key, lang);
|
|
112
|
-
}
|
|
113
|
-
// Resolve plural form if needed
|
|
114
|
-
const translation = this.resolvePluralForm(value, variables?.count, lang);
|
|
115
|
-
return (0, utils_1.replaceVariables)(translation, variables, this.constants);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Resolve plural form from a PluralString based on count variable.
|
|
119
|
-
* @param value - The string or PluralString to resolve.
|
|
120
|
-
* @param count - The count for pluralization.
|
|
121
|
-
* @param language - The language code.
|
|
122
|
-
* @returns The resolved plural form string.
|
|
123
|
-
*/
|
|
124
|
-
resolvePluralForm(value, count, language) {
|
|
125
|
-
// If it's a simple string, return as-is
|
|
126
|
-
if (typeof value === 'string') {
|
|
127
|
-
return value;
|
|
128
|
-
}
|
|
129
|
-
// If no count provided, use 'other' form or first available
|
|
130
|
-
if (count === undefined) {
|
|
131
|
-
return (0, plural_types_1.resolvePluralString)(value, 'other') || '';
|
|
132
|
-
}
|
|
133
|
-
// Get the appropriate plural category for this count and language
|
|
134
|
-
const category = (0, language_plural_map_1.getPluralCategory)(language, count);
|
|
135
|
-
// Resolve the plural form with fallback logic
|
|
136
|
-
return (0, plural_types_1.resolvePluralString)(value, category) || '';
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Safely translates a key for a component, returning a fallback string on error.
|
|
140
|
-
* @param componentId - The component ID.
|
|
141
|
-
* @param key - The translation key.
|
|
142
|
-
* @param variables - Optional variables for replacement.
|
|
143
|
-
* @param language - Optional language code.
|
|
144
|
-
* @returns The translated string or a fallback string if translation fails.
|
|
145
|
-
*/
|
|
146
|
-
safeTranslate(componentId, key, variables, language) {
|
|
147
|
-
try {
|
|
148
|
-
return this.translate(componentId, key, variables, language);
|
|
149
|
-
}
|
|
150
|
-
catch {
|
|
151
|
-
return `[${componentId}.${key}]`;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Validates a component configuration for missing keys across languages.
|
|
156
|
-
* @param config - The component configuration to validate.
|
|
157
|
-
* @returns ValidationResult containing errors and warnings.
|
|
158
|
-
*/
|
|
159
|
-
validate(config) {
|
|
160
|
-
const errors = [];
|
|
161
|
-
const warnings = [];
|
|
162
|
-
// Check if all languages have all keys
|
|
163
|
-
const allKeys = new Set();
|
|
164
|
-
for (const langStrings of Object.values(config.strings)) {
|
|
165
|
-
for (const key of Object.keys(langStrings)) {
|
|
166
|
-
allKeys.add(key);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
for (const [lang, langStrings] of Object.entries(config.strings)) {
|
|
170
|
-
for (const key of allKeys) {
|
|
171
|
-
if (!langStrings[key]) {
|
|
172
|
-
warnings.push(`Missing key '${key}' for language '${lang}' in component '${config.id}'`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
isValid: errors.length === 0,
|
|
178
|
-
errors,
|
|
179
|
-
warnings,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Sets constants for variable replacement.
|
|
184
|
-
* @param constants - The constants to set.
|
|
185
|
-
*/
|
|
186
|
-
setConstants(constants) {
|
|
187
|
-
this.constants = constants;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Clears all registered components and aliases.
|
|
191
|
-
*/
|
|
192
|
-
clear() {
|
|
193
|
-
this.components.clear();
|
|
194
|
-
this.aliasMap.clear();
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.ComponentStore = ComponentStore;
|
|
198
|
-
//# sourceMappingURL=component-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component-store.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-i18n-lib/src/core/component-store.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,qDAAiD;AAEjD,8EAAyE;AACzE,wDAA0E;AAC1E,oCAA4C;AAE5C;;GAEG;AACH,MAAa,cAAc;IACjB,UAAU,GAAG,IAAI,GAAG,EAA2B,CAAC;IAChD,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IACrC,SAAS,CAAuB;IAExC;;;OAGG;IACH,YAAY,SAA+B;QACzC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,QAAQ,CAAC,MAAuB;QAC9B,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;YACnC,MAAM,sBAAS,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAEvC,mBAAmB;QACnB,IAAI,MAAM,CAA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