@digitaldefiance/i18n-lib 3.7.5 → 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 +261 -0
- package/package.json +12 -4
- package/src/active-context.ts +4 -0
- 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.ts +16 -0
- package/src/core/language-registry.ts +345 -0
- package/src/core-component-id.ts +5 -0
- 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.ts +8 -0
- 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.ts +15 -0
- package/src/errors/simple-typed-error.ts +81 -0
- package/src/errors/{index.d.ts → translatable-exports.ts} +3 -5
- 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} +46 -14
- 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.ts +13 -0
- 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.ts +142 -0
- 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 +0 -36
- 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 -13
- 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 +0 -9
- package/src/core/index.d.ts.map +0 -1
- package/src/core/index.js +0 -12
- 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 -295
- package/src/core/language-registry.js.map +0 -1
- package/src/core-i18n.d.ts +0 -91
- package/src/core-i18n.d.ts.map +0 -1
- package/src/core-i18n.js +0 -287
- package/src/core-i18n.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/context-error.d.ts +0 -50
- package/src/errors/context-error.d.ts.map +0 -1
- package/src/errors/context-error.js +0 -75
- 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-generic.d.ts +0 -84
- package/src/errors/translatable-generic.d.ts.map +0 -1
- package/src/errors/translatable-generic.js +0 -134
- 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 -59
- package/src/errors/translatable.d.ts.map +0 -1
- package/src/errors/translatable.js +0 -80
- 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 -106
- 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 -452
- 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/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 +0 -11
- package/src/interfaces/index.d.ts.map +0 -1
- package/src/interfaces/index.js +0 -14
- 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 -489
- 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 -19
- package/src/registry-error.d.ts.map +0 -1
- package/src/registry-error.js +0 -49
- 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 +0 -96
- 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 -101
- 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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Digital Defiance
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -853,6 +853,85 @@ const error = new TypedError('Error message', {
|
|
|
853
853
|
|
|
854
854
|
None - This release maintains full backward compatibility while improving internal type safety.
|
|
855
855
|
|
|
856
|
+
### Version 3.8.0
|
|
857
|
+
|
|
858
|
+
**Internal Refactoring Release** - Circular Dependency Elimination
|
|
859
|
+
|
|
860
|
+
This release eliminates all circular dependencies from the codebase through internal architectural improvements. All changes are non-breaking and maintain full backward compatibility.
|
|
861
|
+
|
|
862
|
+
**Internal Improvements:**
|
|
863
|
+
|
|
864
|
+
- **Zero Circular Dependencies**: Eliminated all 15 circular dependencies that existed in the codebase
|
|
865
|
+
- Broke core/i18n-engine ↔ core-i18n cycle
|
|
866
|
+
- Broke errors/translatable → core/i18n-engine → errors/index cycle
|
|
867
|
+
- Broke core-i18n ↔ plugin-i18n-engine cycle
|
|
868
|
+
- Broke context-related cycles
|
|
869
|
+
- Broke registry-error cycles
|
|
870
|
+
- Optimized barrel exports with type-only exports
|
|
871
|
+
|
|
872
|
+
- **Lazy Initialization Pattern**: Error classes and core modules now use lazy initialization to avoid circular dependencies
|
|
873
|
+
- `TranslatableError` uses `getInstance()` at construction time instead of module load
|
|
874
|
+
- `TypedError` and related classes use lazy engine lookup
|
|
875
|
+
- Registry errors use lazy initialization for core dependencies
|
|
876
|
+
- Fallback behavior if engine not initialized
|
|
877
|
+
|
|
878
|
+
- **Factory Pattern**: Introduced `core-plugin-factory.ts` to break plugin engine cycles
|
|
879
|
+
- `createCorePluginI18nEngine()` moved to factory file
|
|
880
|
+
- Factory imports both core-i18n and plugin-i18n-engine
|
|
881
|
+
- Breaks circular dependency between these modules
|
|
882
|
+
|
|
883
|
+
- **Type-Only Exports**: Optimized barrel exports to eliminate runtime dependencies
|
|
884
|
+
- `src/interfaces/index.ts` uses `export type` for all type exports
|
|
885
|
+
- `src/errors/index.ts` split into base.ts and translatable-exports.ts
|
|
886
|
+
- `src/core/index.ts` uses type-only exports where appropriate
|
|
887
|
+
|
|
888
|
+
- **Module Organization**: Established clear dependency hierarchy
|
|
889
|
+
- Interfaces & Types (no implementation dependencies)
|
|
890
|
+
- Error Classes (lazy initialization for i18n)
|
|
891
|
+
- Core Modules (clear hierarchy, no cycles)
|
|
892
|
+
- High-Level Modules (core-i18n, plugin-i18n-engine)
|
|
893
|
+
|
|
894
|
+
**Testing & Quality:**
|
|
895
|
+
|
|
896
|
+
- **Automated Circular Dependency Detection**: Added test that fails if circular dependencies are introduced
|
|
897
|
+
- **Module Independence Tests**: Verify modules can be imported independently
|
|
898
|
+
- **All Tests Passing**: 1,779 tests passing with no regressions
|
|
899
|
+
- **Zero Breaking Changes**: Public API remains completely unchanged
|
|
900
|
+
|
|
901
|
+
**Documentation:**
|
|
902
|
+
|
|
903
|
+
- **[CIRCULAR_DEPENDENCY_FIXES.md](docs/CIRCULAR_DEPENDENCY_FIXES.md)** - Comprehensive internal documentation
|
|
904
|
+
- Detailed explanation of all patterns used
|
|
905
|
+
- Best practices for maintaining zero circular dependencies
|
|
906
|
+
- Examples of lazy initialization, factory pattern, and type-only exports
|
|
907
|
+
- Guidelines for adding new modules without creating cycles
|
|
908
|
+
|
|
909
|
+
**Files Modified:**
|
|
910
|
+
|
|
911
|
+
- `src/core-plugin-factory.ts` - New factory file for plugin engine creation
|
|
912
|
+
- `src/core-i18n.ts` - Lazy initialization with Proxy pattern
|
|
913
|
+
- `src/errors/*.ts` - Lazy initialization in error constructors
|
|
914
|
+
- `src/errors/index.ts` - Split into separate barrel files
|
|
915
|
+
- `src/interfaces/index.ts` - Type-only exports
|
|
916
|
+
- `src/core/index.ts` - Optimized barrel exports
|
|
917
|
+
- `src/registry-error.ts` - Lazy initialization for core dependencies
|
|
918
|
+
- `tests/circular-dependencies.spec.ts` - Automated detection test
|
|
919
|
+
|
|
920
|
+
**Breaking Changes:**
|
|
921
|
+
|
|
922
|
+
None - This release is fully backward compatible. All changes are internal refactoring only.
|
|
923
|
+
|
|
924
|
+
**Migration:**
|
|
925
|
+
|
|
926
|
+
No migration required! Your existing code works unchanged. The improvements are entirely internal.
|
|
927
|
+
|
|
928
|
+
**Benefits:**
|
|
929
|
+
|
|
930
|
+
- **Improved Maintainability**: Clearer module structure and dependencies
|
|
931
|
+
- **Better Tree-Shaking**: Reduced runtime dependencies improve bundle optimization
|
|
932
|
+
- **Predictable Initialization**: No more initialization order issues
|
|
933
|
+
- **Future-Proof**: Established patterns prevent circular dependencies from being reintroduced
|
|
934
|
+
|
|
856
935
|
### Version 3.7.2
|
|
857
936
|
|
|
858
937
|
- Minor version bump to fix an export
|
|
@@ -1675,6 +1754,188 @@ const registration: ComponentRegistration<MyStringKeys, MyLanguages> = {
|
|
|
1675
1754
|
- Safari: Latest 2 versions
|
|
1676
1755
|
- Node.js: 18+
|
|
1677
1756
|
|
|
1757
|
+
## Testing
|
|
1758
|
+
|
|
1759
|
+
### Testing Approach
|
|
1760
|
+
|
|
1761
|
+
The i18n-lib package uses a comprehensive testing strategy combining unit tests, integration tests, and property-based testing to ensure correctness across all features.
|
|
1762
|
+
|
|
1763
|
+
**Test Framework**: Jest with TypeScript support
|
|
1764
|
+
**Property-Based Testing**: fast-check for testing universal properties
|
|
1765
|
+
**Coverage Target**: 90%+ statement coverage, 85%+ branch coverage
|
|
1766
|
+
|
|
1767
|
+
### Test Structure
|
|
1768
|
+
|
|
1769
|
+
```
|
|
1770
|
+
tests/
|
|
1771
|
+
├── unit/ # Unit tests for individual components
|
|
1772
|
+
├── integration/ # Integration tests for component interactions
|
|
1773
|
+
├── property/ # Property-based tests using fast-check
|
|
1774
|
+
└── fixtures/ # Test data and mock translations
|
|
1775
|
+
```
|
|
1776
|
+
|
|
1777
|
+
### Running Tests
|
|
1778
|
+
|
|
1779
|
+
```bash
|
|
1780
|
+
# Run all tests
|
|
1781
|
+
npm test
|
|
1782
|
+
|
|
1783
|
+
# Run with coverage
|
|
1784
|
+
npm test -- --coverage
|
|
1785
|
+
|
|
1786
|
+
# Run specific test file
|
|
1787
|
+
npm test -- plugin-i18n-engine.spec.ts
|
|
1788
|
+
|
|
1789
|
+
# Run in watch mode
|
|
1790
|
+
npm test -- --watch
|
|
1791
|
+
```
|
|
1792
|
+
|
|
1793
|
+
### Test Patterns
|
|
1794
|
+
|
|
1795
|
+
#### Testing Translation Registration
|
|
1796
|
+
|
|
1797
|
+
```typescript
|
|
1798
|
+
import { PluginI18nEngine, LanguageCodes } from '@digitaldefiance/i18n-lib';
|
|
1799
|
+
|
|
1800
|
+
describe('Component Registration', () => {
|
|
1801
|
+
let engine: PluginI18nEngine;
|
|
1802
|
+
|
|
1803
|
+
beforeEach(() => {
|
|
1804
|
+
PluginI18nEngine.resetAll();
|
|
1805
|
+
engine = PluginI18nEngine.createInstance('test', [
|
|
1806
|
+
{ id: LanguageCodes.EN_US, name: 'English', code: 'en-US', isDefault: true }
|
|
1807
|
+
]);
|
|
1808
|
+
});
|
|
1809
|
+
|
|
1810
|
+
afterEach(() => {
|
|
1811
|
+
PluginI18nEngine.resetAll();
|
|
1812
|
+
});
|
|
1813
|
+
|
|
1814
|
+
it('should register component with translations', () => {
|
|
1815
|
+
engine.registerComponent({
|
|
1816
|
+
component: {
|
|
1817
|
+
id: 'test',
|
|
1818
|
+
name: 'Test',
|
|
1819
|
+
stringKeys: ['hello']
|
|
1820
|
+
},
|
|
1821
|
+
strings: {
|
|
1822
|
+
[LanguageCodes.EN_US]: {
|
|
1823
|
+
hello: 'Hello, {name}!'
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
});
|
|
1827
|
+
|
|
1828
|
+
expect(engine.translate('test', 'hello', { name: 'World' }))
|
|
1829
|
+
.toBe('Hello, World!');
|
|
1830
|
+
});
|
|
1831
|
+
});
|
|
1832
|
+
```
|
|
1833
|
+
|
|
1834
|
+
#### Testing ICU MessageFormat
|
|
1835
|
+
|
|
1836
|
+
```typescript
|
|
1837
|
+
import { formatICUMessage } from '@digitaldefiance/i18n-lib';
|
|
1838
|
+
|
|
1839
|
+
describe('ICU MessageFormat', () => {
|
|
1840
|
+
it('should format plural messages', () => {
|
|
1841
|
+
const message = '{count, plural, one {# item} other {# items}}';
|
|
1842
|
+
|
|
1843
|
+
expect(formatICUMessage(message, { count: 1 })).toBe('1 item');
|
|
1844
|
+
expect(formatICUMessage(message, { count: 5 })).toBe('5 items');
|
|
1845
|
+
});
|
|
1846
|
+
|
|
1847
|
+
it('should handle nested select and plural', () => {
|
|
1848
|
+
const message = '{gender, select, male {He has} female {She has}} {count, plural, one {# item} other {# items}}';
|
|
1849
|
+
|
|
1850
|
+
expect(formatICUMessage(message, { gender: 'female', count: 2 }))
|
|
1851
|
+
.toBe('She has 2 items');
|
|
1852
|
+
});
|
|
1853
|
+
});
|
|
1854
|
+
```
|
|
1855
|
+
|
|
1856
|
+
#### Testing Error Handling
|
|
1857
|
+
|
|
1858
|
+
```typescript
|
|
1859
|
+
import { RegistryError, RegistryErrorType } from '@digitaldefiance/i18n-lib';
|
|
1860
|
+
|
|
1861
|
+
describe('Error Handling', () => {
|
|
1862
|
+
it('should throw RegistryError for missing component', () => {
|
|
1863
|
+
expect(() => {
|
|
1864
|
+
engine.translate('missing', 'key');
|
|
1865
|
+
}).toThrow(RegistryError);
|
|
1866
|
+
});
|
|
1867
|
+
|
|
1868
|
+
it('should provide error metadata', () => {
|
|
1869
|
+
try {
|
|
1870
|
+
engine.translate('missing', 'key');
|
|
1871
|
+
} catch (error) {
|
|
1872
|
+
expect(error).toBeInstanceOf(RegistryError);
|
|
1873
|
+
expect(error.type).toBe(RegistryErrorType.COMPONENT_NOT_FOUND);
|
|
1874
|
+
expect(error.metadata).toEqual({ componentId: 'missing' });
|
|
1875
|
+
}
|
|
1876
|
+
});
|
|
1877
|
+
});
|
|
1878
|
+
```
|
|
1879
|
+
|
|
1880
|
+
#### Property-Based Testing
|
|
1881
|
+
|
|
1882
|
+
```typescript
|
|
1883
|
+
import * as fc from 'fast-check';
|
|
1884
|
+
import { createPluralString } from '@digitaldefiance/i18n-lib';
|
|
1885
|
+
|
|
1886
|
+
describe('Pluralization Properties', () => {
|
|
1887
|
+
it('should always return a string for any count', () => {
|
|
1888
|
+
fc.assert(
|
|
1889
|
+
fc.property(fc.integer(), (count) => {
|
|
1890
|
+
const plural = createPluralString({
|
|
1891
|
+
one: '{count} item',
|
|
1892
|
+
other: '{count} items'
|
|
1893
|
+
});
|
|
1894
|
+
|
|
1895
|
+
const result = engine.translate('test', 'items', { count });
|
|
1896
|
+
expect(typeof result).toBe('string');
|
|
1897
|
+
expect(result.length).toBeGreaterThan(0);
|
|
1898
|
+
})
|
|
1899
|
+
);
|
|
1900
|
+
});
|
|
1901
|
+
});
|
|
1902
|
+
```
|
|
1903
|
+
|
|
1904
|
+
### Testing Best Practices
|
|
1905
|
+
|
|
1906
|
+
1. **Always reset engine state** between tests using `PluginI18nEngine.resetAll()`
|
|
1907
|
+
2. **Test with multiple languages** to ensure translations work correctly
|
|
1908
|
+
3. **Test edge cases** like empty strings, special characters, and missing variables
|
|
1909
|
+
4. **Use property-based tests** for testing universal properties across many inputs
|
|
1910
|
+
5. **Mock external dependencies** when testing error conditions
|
|
1911
|
+
|
|
1912
|
+
### Cross-Package Testing
|
|
1913
|
+
|
|
1914
|
+
When testing packages that depend on i18n-lib:
|
|
1915
|
+
|
|
1916
|
+
```typescript
|
|
1917
|
+
import { PluginI18nEngine } from '@digitaldefiance/i18n-lib';
|
|
1918
|
+
import { YourService } from 'your-package';
|
|
1919
|
+
|
|
1920
|
+
describe('Service with i18n', () => {
|
|
1921
|
+
beforeEach(() => {
|
|
1922
|
+
// Set up i18n engine for your service
|
|
1923
|
+
PluginI18nEngine.resetAll();
|
|
1924
|
+
const engine = PluginI18nEngine.createInstance('test', languages);
|
|
1925
|
+
// Register your component translations
|
|
1926
|
+
});
|
|
1927
|
+
|
|
1928
|
+
afterEach(() => {
|
|
1929
|
+
PluginI18nEngine.resetAll();
|
|
1930
|
+
});
|
|
1931
|
+
|
|
1932
|
+
it('should use translated error messages', () => {
|
|
1933
|
+
const service = new YourService();
|
|
1934
|
+
expect(() => service.doSomething()).toThrow(/translated message/);
|
|
1935
|
+
});
|
|
1936
|
+
});
|
|
1937
|
+
```
|
|
1938
|
+
|
|
1678
1939
|
## License
|
|
1679
1940
|
|
|
1680
1941
|
MIT License - See LICENSE file for details
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/i18n-lib",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "i18n library with enum translation support",
|
|
5
|
+
"homepage": "https://github.com/Digital-Defiance/i18n-lib/blob/main/README.md",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Digital-Defiance/i18n-lib.git"
|
|
9
|
+
},
|
|
5
10
|
"main": "src/index.js",
|
|
6
11
|
"types": "src/index.d.ts",
|
|
7
12
|
"scripts": {
|
|
@@ -41,7 +46,10 @@
|
|
|
41
46
|
"moment-timezone": "^0.6.0"
|
|
42
47
|
},
|
|
43
48
|
"devDependencies": {
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^8.48.0",
|
|
50
|
+
"@typescript-eslint/parser": "^8.48.0",
|
|
51
|
+
"eslint-plugin-import": "^2.32.0",
|
|
52
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
44
53
|
"fast-check": "^4.3.0"
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent builder for I18n Engine
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { I18nEngine } from '../core/i18n-engine';
|
|
6
|
+
import { EngineConfig, LanguageDefinition } from '../interfaces';
|
|
7
|
+
|
|
8
|
+
export class I18nBuilder {
|
|
9
|
+
private languages: LanguageDefinition[] = [];
|
|
10
|
+
private config: EngineConfig = {};
|
|
11
|
+
private instanceKey = 'default';
|
|
12
|
+
private registerInstance = true;
|
|
13
|
+
private setAsDefault = true;
|
|
14
|
+
|
|
15
|
+
private constructor() {}
|
|
16
|
+
|
|
17
|
+
static create(): I18nBuilder {
|
|
18
|
+
return new I18nBuilder();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
withLanguages(languages: readonly LanguageDefinition[]): this {
|
|
22
|
+
this.languages = [...languages];
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
withDefaultLanguage(languageId: string): this {
|
|
27
|
+
this.config.defaultLanguage = languageId;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
withFallbackLanguage(languageId: string): this {
|
|
32
|
+
this.config.fallbackLanguage = languageId;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
withConstants(constants: Record<string, any>): this {
|
|
37
|
+
this.config.constants = constants;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
withValidation(validation: EngineConfig['validation']): this {
|
|
42
|
+
this.config.validation = validation;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
withInstanceKey(key: string): this {
|
|
47
|
+
this.instanceKey = key;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
withRegisterInstance(register: boolean): this {
|
|
52
|
+
this.registerInstance = register;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
withSetAsDefault(setDefault: boolean): this {
|
|
57
|
+
this.setAsDefault = setDefault;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
isolated(): this {
|
|
62
|
+
this.registerInstance = false;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
asDefault(): this {
|
|
67
|
+
this.setAsDefault = true;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
build(): I18nEngine {
|
|
72
|
+
if (this.languages.length === 0) {
|
|
73
|
+
throw new Error('At least one language must be provided');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return new I18nEngine(this.languages, this.config, {
|
|
77
|
+
instanceKey: this.instanceKey,
|
|
78
|
+
registerInstance: this.registerInstance,
|
|
79
|
+
setAsDefault: this.setAsDefault,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component definition with its string keys
|
|
3
|
+
*/
|
|
4
|
+
export interface ComponentDefinition<TStringKeys extends string> {
|
|
5
|
+
/** Unique identifier for the component */
|
|
6
|
+
readonly id: string;
|
|
7
|
+
/** Human-readable name for the component */
|
|
8
|
+
readonly name: string;
|
|
9
|
+
/** Array of all string keys this component requires */
|
|
10
|
+
readonly stringKeys: readonly TStringKeys[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ComponentDefinition } from './component-definition';
|
|
2
|
+
import { PartialComponentLanguageStrings } from './types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Registration payload for a component with its strings
|
|
6
|
+
*/
|
|
7
|
+
export interface ComponentRegistration<
|
|
8
|
+
TStringKeys extends string,
|
|
9
|
+
TLanguages extends string,
|
|
10
|
+
> {
|
|
11
|
+
readonly component: ComponentDefinition<TStringKeys>;
|
|
12
|
+
readonly strings: PartialComponentLanguageStrings<TStringKeys, TLanguages>;
|
|
13
|
+
readonly enumName?: string;
|
|
14
|
+
readonly enumObject?: Record<string, TStringKeys>;
|
|
15
|
+
readonly aliases?: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Type utility to extract string keys from a component definition
|
|
20
|
+
*/
|
|
21
|
+
type ExtractStringKeys<T> = T extends ComponentDefinition<infer K> ? K : never;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Type utility to create a strongly typed component registration
|
|
25
|
+
*/
|
|
26
|
+
export type CreateComponentRegistration<
|
|
27
|
+
TComponent extends ComponentDefinition<any>,
|
|
28
|
+
TLanguages extends string,
|
|
29
|
+
> = ComponentRegistration<ExtractStringKeys<TComponent>, TLanguages>;
|