@digitaldefiance/i18n-lib 3.8.2 → 3.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -7
- package/src/{active-context.ts → active-context.d.ts} +1 -0
- package/src/active-context.d.ts.map +1 -0
- package/src/active-context.js +3 -0
- package/src/active-context.js.map +1 -0
- package/src/builders/i18n-builder.d.ts +26 -0
- package/src/builders/i18n-builder.d.ts.map +1 -0
- package/src/builders/i18n-builder.js +70 -0
- package/src/builders/i18n-builder.js.map +1 -0
- package/src/builders/{index.ts → index.d.ts} +1 -1
- package/src/builders/index.d.ts.map +1 -0
- package/src/builders/index.js +8 -0
- package/src/builders/index.js.map +1 -0
- package/src/component-definition.d.ts +12 -0
- package/src/component-definition.d.ts.map +1 -0
- package/src/component-definition.js +3 -0
- package/src/component-definition.js.map +1 -0
- package/src/component-registration.d.ts +22 -0
- package/src/component-registration.d.ts.map +1 -0
- package/src/component-registration.js +3 -0
- package/src/component-registration.js.map +1 -0
- package/src/component-registry.d.ts +102 -0
- package/src/component-registry.d.ts.map +1 -0
- package/src/component-registry.js +282 -0
- package/src/component-registry.js.map +1 -0
- package/src/context-error-type.d.ts +8 -0
- package/src/context-error-type.d.ts.map +1 -0
- package/src/context-error-type.js +12 -0
- package/src/context-error-type.js.map +1 -0
- package/src/core/component-store.d.ts +93 -0
- package/src/core/component-store.d.ts.map +1 -0
- package/src/core/component-store.js +198 -0
- package/src/core/component-store.js.map +1 -0
- package/src/core/context-manager.d.ts +72 -0
- package/src/core/context-manager.d.ts.map +1 -0
- package/src/core/context-manager.js +98 -0
- package/src/core/context-manager.js.map +1 -0
- package/src/core/enum-registry.d.ts +48 -0
- package/src/core/enum-registry.d.ts.map +1 -0
- package/src/core/enum-registry.js +85 -0
- package/src/core/enum-registry.js.map +1 -0
- package/src/core/i18n-engine.d.ts +241 -0
- package/src/core/i18n-engine.d.ts.map +1 -0
- package/src/core/i18n-engine.js +568 -0
- package/src/core/i18n-engine.js.map +1 -0
- package/src/core/{index.ts → index.d.ts} +1 -4
- package/src/core/index.d.ts.map +1 -0
- package/src/core/index.js +21 -0
- package/src/core/index.js.map +1 -0
- package/src/core/language-registry.d.ts +180 -0
- package/src/core/language-registry.d.ts.map +1 -0
- package/src/core/language-registry.js +298 -0
- package/src/core/language-registry.js.map +1 -0
- package/src/{core-component-id.ts → core-component-id.d.ts} +2 -1
- package/src/core-component-id.d.ts.map +1 -0
- package/src/core-component-id.js +9 -0
- package/src/core-component-id.js.map +1 -0
- package/src/core-i18n.d.ts +69 -0
- package/src/core-i18n.d.ts.map +1 -0
- package/src/core-i18n.js +219 -0
- package/src/core-i18n.js.map +1 -0
- package/src/core-plugin-factory.d.ts +28 -0
- package/src/core-plugin-factory.d.ts.map +1 -0
- package/src/core-plugin-factory.js +80 -0
- package/src/core-plugin-factory.js.map +1 -0
- package/src/core-string-key.d.ts +52 -0
- package/src/core-string-key.d.ts.map +1 -0
- package/src/core-string-key.js +61 -0
- package/src/core-string-key.js.map +1 -0
- package/src/create-translation-adapter.d.ts +33 -0
- package/src/create-translation-adapter.d.ts.map +1 -0
- package/src/create-translation-adapter.js +72 -0
- package/src/create-translation-adapter.js.map +1 -0
- package/src/enum-registry.d.ts +65 -0
- package/src/enum-registry.d.ts.map +1 -0
- package/src/enum-registry.js +123 -0
- package/src/enum-registry.js.map +1 -0
- package/src/errors/{base.ts → base.d.ts} +1 -1
- package/src/errors/base.d.ts.map +1 -0
- package/src/errors/base.js +11 -0
- package/src/errors/base.js.map +1 -0
- package/src/errors/context-error.d.ts +50 -0
- package/src/errors/context-error.d.ts.map +1 -0
- package/src/errors/context-error.js +93 -0
- package/src/errors/context-error.js.map +1 -0
- package/src/errors/enhanced-error-base.d.ts +125 -0
- package/src/errors/enhanced-error-base.d.ts.map +1 -0
- package/src/errors/enhanced-error-base.js +165 -0
- package/src/errors/enhanced-error-base.js.map +1 -0
- package/src/errors/handleable.d.ts +83 -0
- package/src/errors/handleable.d.ts.map +1 -0
- package/src/errors/handleable.js +136 -0
- package/src/errors/handleable.js.map +1 -0
- package/src/errors/i18n-error.d.ts +211 -0
- package/src/errors/i18n-error.d.ts.map +1 -0
- package/src/errors/i18n-error.js +358 -0
- package/src/errors/i18n-error.js.map +1 -0
- package/src/errors/{index.ts → index.d.ts} +1 -4
- package/src/errors/index.d.ts.map +1 -0
- package/src/errors/index.js +17 -0
- package/src/errors/index.js.map +1 -0
- package/src/errors/simple-typed-error.d.ts +53 -0
- package/src/errors/simple-typed-error.d.ts.map +1 -0
- package/src/errors/simple-typed-error.js +51 -0
- package/src/errors/simple-typed-error.js.map +1 -0
- package/src/errors/{translatable-exports.ts → translatable-exports.d.ts} +1 -1
- package/src/errors/translatable-exports.d.ts.map +1 -0
- package/src/errors/translatable-exports.js +15 -0
- package/src/errors/translatable-exports.js.map +1 -0
- package/src/errors/translatable-generic.d.ts +87 -0
- package/src/errors/translatable-generic.d.ts.map +1 -0
- package/src/errors/translatable-generic.js +139 -0
- package/src/errors/translatable-generic.js.map +1 -0
- package/src/errors/translatable-handleable-generic.d.ts +116 -0
- package/src/errors/translatable-handleable-generic.d.ts.map +1 -0
- package/src/errors/translatable-handleable-generic.js +121 -0
- package/src/errors/translatable-handleable-generic.js.map +1 -0
- package/src/errors/translatable.d.ts +63 -0
- package/src/errors/translatable.d.ts.map +1 -0
- package/src/errors/translatable.js +85 -0
- package/src/errors/translatable.js.map +1 -0
- package/src/errors/typed-handleable.d.ts +62 -0
- package/src/errors/typed-handleable.d.ts.map +1 -0
- package/src/errors/typed-handleable.js +108 -0
- package/src/errors/typed-handleable.js.map +1 -0
- package/src/errors/typed.d.ts +206 -0
- package/src/errors/typed.d.ts.map +1 -0
- package/src/errors/typed.js +458 -0
- package/src/errors/typed.js.map +1 -0
- package/src/gender/{gender-categories.ts → gender-categories.d.ts} +2 -6
- package/src/gender/gender-categories.d.ts.map +1 -0
- package/src/gender/gender-categories.js +15 -0
- package/src/gender/gender-categories.js.map +1 -0
- package/src/gender/gender-resolver.d.ts +14 -0
- package/src/gender/gender-resolver.d.ts.map +1 -0
- package/src/gender/gender-resolver.js +35 -0
- package/src/gender/gender-resolver.js.map +1 -0
- package/src/gender/{index.ts → index.d.ts} +1 -0
- package/src/gender/index.d.ts.map +1 -0
- package/src/gender/index.js +6 -0
- package/src/gender/index.js.map +1 -0
- package/src/global-active-context.d.ts +50 -0
- package/src/global-active-context.d.ts.map +1 -0
- package/src/global-active-context.js +185 -0
- package/src/global-active-context.js.map +1 -0
- package/src/icu/ast.d.ts +48 -0
- package/src/icu/ast.d.ts.map +1 -0
- package/src/icu/ast.js +16 -0
- package/src/icu/ast.js.map +1 -0
- package/src/icu/compiler.d.ts +16 -0
- package/src/icu/compiler.d.ts.map +1 -0
- package/src/icu/compiler.js +87 -0
- package/src/icu/compiler.js.map +1 -0
- package/src/icu/formatter-registry.d.ts +10 -0
- package/src/icu/formatter-registry.d.ts.map +1 -0
- package/src/icu/formatter-registry.js +34 -0
- package/src/icu/formatter-registry.js.map +1 -0
- package/src/icu/formatters/base-formatter.d.ts +8 -0
- package/src/icu/formatters/base-formatter.d.ts.map +1 -0
- package/src/icu/formatters/base-formatter.js +3 -0
- package/src/icu/formatters/base-formatter.js.map +1 -0
- package/src/icu/formatters/date-formatter.d.ts +5 -0
- package/src/icu/formatters/date-formatter.d.ts.map +1 -0
- package/src/icu/formatters/date-formatter.js +31 -0
- package/src/icu/formatters/date-formatter.js.map +1 -0
- package/src/icu/formatters/number-formatter.d.ts +5 -0
- package/src/icu/formatters/number-formatter.d.ts.map +1 -0
- package/src/icu/formatters/number-formatter.js +33 -0
- package/src/icu/formatters/number-formatter.js.map +1 -0
- package/src/icu/formatters/plural-formatter.d.ts +5 -0
- package/src/icu/formatters/plural-formatter.d.ts.map +1 -0
- package/src/icu/formatters/plural-formatter.js +15 -0
- package/src/icu/formatters/plural-formatter.js.map +1 -0
- package/src/icu/formatters/select-formatter.d.ts +5 -0
- package/src/icu/formatters/select-formatter.d.ts.map +1 -0
- package/src/icu/formatters/select-formatter.js +10 -0
- package/src/icu/formatters/select-formatter.js.map +1 -0
- package/src/icu/formatters/selectordinal-formatter.d.ts +5 -0
- package/src/icu/formatters/selectordinal-formatter.d.ts.map +1 -0
- package/src/icu/formatters/selectordinal-formatter.js +22 -0
- package/src/icu/formatters/selectordinal-formatter.js.map +1 -0
- package/src/icu/formatters/time-formatter.d.ts +5 -0
- package/src/icu/formatters/time-formatter.d.ts.map +1 -0
- package/src/icu/formatters/time-formatter.js +31 -0
- package/src/icu/formatters/time-formatter.js.map +1 -0
- package/src/icu/helpers.d.ts +9 -0
- package/src/icu/helpers.d.ts.map +1 -0
- package/src/icu/helpers.js +31 -0
- package/src/icu/helpers.js.map +1 -0
- package/src/icu/parser.d.ts +31 -0
- package/src/icu/parser.d.ts.map +1 -0
- package/src/icu/parser.js +203 -0
- package/src/icu/parser.js.map +1 -0
- package/src/icu/runtime.d.ts +10 -0
- package/src/icu/runtime.d.ts.map +1 -0
- package/src/icu/runtime.js +33 -0
- package/src/icu/runtime.js.map +1 -0
- package/src/icu/tokenizer.d.ts +37 -0
- package/src/icu/tokenizer.d.ts.map +1 -0
- package/src/icu/tokenizer.js +187 -0
- package/src/icu/tokenizer.js.map +1 -0
- package/src/icu/validator.d.ts +11 -0
- package/src/icu/validator.d.ts.map +1 -0
- package/src/icu/validator.js +140 -0
- package/src/icu/validator.js.map +1 -0
- package/src/{index.ts → index.d.ts} +6 -38
- package/src/index.d.ts.map +1 -0
- package/src/index.js +76 -0
- package/src/index.js.map +1 -0
- package/src/interfaces/active-context.interface.d.ts +36 -0
- package/src/interfaces/active-context.interface.d.ts.map +1 -0
- package/src/interfaces/active-context.interface.js +3 -0
- package/src/interfaces/active-context.interface.js.map +1 -0
- package/src/interfaces/component-config.interface.d.ts +16 -0
- package/src/interfaces/component-config.interface.d.ts.map +1 -0
- package/src/interfaces/component-config.interface.js +6 -0
- package/src/interfaces/component-config.interface.js.map +1 -0
- package/src/interfaces/engine-config.interface.d.ts +22 -0
- package/src/interfaces/engine-config.interface.d.ts.map +1 -0
- package/src/interfaces/engine-config.interface.js +6 -0
- package/src/interfaces/engine-config.interface.js.map +1 -0
- package/src/interfaces/global-active-context.d.ts +23 -0
- package/src/interfaces/global-active-context.d.ts.map +1 -0
- package/src/interfaces/global-active-context.js +3 -0
- package/src/interfaces/global-active-context.js.map +1 -0
- package/src/interfaces/handleable-error-options.d.ts +14 -0
- package/src/interfaces/handleable-error-options.d.ts.map +1 -0
- package/src/interfaces/handleable-error-options.js +3 -0
- package/src/interfaces/handleable-error-options.js.map +1 -0
- package/src/interfaces/handleable.d.ts +21 -0
- package/src/interfaces/handleable.d.ts.map +1 -0
- package/src/interfaces/handleable.js +3 -0
- package/src/interfaces/handleable.js.map +1 -0
- package/src/interfaces/i18n-engine.interface.d.ts +46 -0
- package/src/interfaces/i18n-engine.interface.d.ts.map +1 -0
- package/src/interfaces/i18n-engine.interface.js +6 -0
- package/src/interfaces/i18n-engine.interface.js.map +1 -0
- package/src/interfaces/{index.ts → index.d.ts} +1 -1
- package/src/interfaces/index.d.ts.map +1 -0
- package/src/interfaces/index.js +7 -0
- package/src/interfaces/index.js.map +1 -0
- package/src/interfaces/language-definition.interface.d.ts +17 -0
- package/src/interfaces/language-definition.interface.d.ts.map +1 -0
- package/src/interfaces/language-definition.interface.js +6 -0
- package/src/interfaces/language-definition.interface.js.map +1 -0
- package/src/interfaces/translation-options.interface.d.ts +15 -0
- package/src/interfaces/translation-options.interface.d.ts.map +1 -0
- package/src/interfaces/translation-options.interface.js +6 -0
- package/src/interfaces/translation-options.interface.js.map +1 -0
- package/src/interfaces/validation-result.interface.d.ts +24 -0
- package/src/interfaces/validation-result.interface.d.ts.map +1 -0
- package/src/interfaces/validation-result.interface.js +6 -0
- package/src/interfaces/validation-result.interface.js.map +1 -0
- package/src/language-codes.d.ts +28 -0
- package/src/language-codes.d.ts.map +1 -0
- package/src/language-codes.js +32 -0
- package/src/language-codes.js.map +1 -0
- package/src/language-definition.d.ts +14 -0
- package/src/language-definition.d.ts.map +1 -0
- package/src/language-definition.js +3 -0
- package/src/language-definition.js.map +1 -0
- package/src/plugin-i18n-engine.d.ts +164 -0
- package/src/plugin-i18n-engine.d.ts.map +1 -0
- package/src/plugin-i18n-engine.js +493 -0
- package/src/plugin-i18n-engine.js.map +1 -0
- package/src/pluralization/{index.ts → index.d.ts} +1 -1
- package/src/pluralization/index.d.ts.map +1 -0
- package/src/pluralization/index.js +10 -0
- package/src/pluralization/index.js.map +1 -0
- package/src/pluralization/language-plural-map.d.ts +29 -0
- package/src/pluralization/language-plural-map.d.ts.map +1 -0
- package/src/pluralization/language-plural-map.js +155 -0
- package/src/pluralization/language-plural-map.js.map +1 -0
- package/src/pluralization/{plural-categories.ts → plural-categories.d.ts} +3 -5
- package/src/pluralization/plural-categories.d.ts.map +1 -0
- package/src/pluralization/plural-categories.js +8 -0
- package/src/pluralization/plural-categories.js.map +1 -0
- package/src/pluralization/plural-rules.d.ts +102 -0
- package/src/pluralization/plural-rules.d.ts.map +1 -0
- package/src/pluralization/plural-rules.js +263 -0
- package/src/pluralization/plural-rules.js.map +1 -0
- package/src/registry-config.d.ts +16 -0
- package/src/registry-config.d.ts.map +1 -0
- package/src/registry-config.js +3 -0
- package/src/registry-config.js.map +1 -0
- package/src/registry-error-type.d.ts +20 -0
- package/src/registry-error-type.d.ts.map +1 -0
- package/src/registry-error-type.js +24 -0
- package/src/registry-error-type.js.map +1 -0
- package/src/registry-error.d.ts +25 -0
- package/src/registry-error.d.ts.map +1 -0
- package/src/registry-error.js +63 -0
- package/src/registry-error.js.map +1 -0
- package/src/strict-types.d.ts +19 -0
- package/src/strict-types.d.ts.map +1 -0
- package/src/strict-types.js +18 -0
- package/src/strict-types.js.map +1 -0
- package/src/strings/de.d.ts +3 -0
- package/src/strings/de.d.ts.map +1 -0
- package/src/strings/de.js +57 -0
- package/src/strings/de.js.map +1 -0
- package/src/strings/en-GB.d.ts +3 -0
- package/src/strings/en-GB.d.ts.map +1 -0
- package/src/strings/en-GB.js +57 -0
- package/src/strings/en-GB.js.map +1 -0
- package/src/strings/en-US.d.ts +3 -0
- package/src/strings/en-US.d.ts.map +1 -0
- package/src/strings/en-US.js +57 -0
- package/src/strings/en-US.js.map +1 -0
- package/src/strings/es.d.ts +3 -0
- package/src/strings/es.d.ts.map +1 -0
- package/src/strings/es.js +57 -0
- package/src/strings/es.js.map +1 -0
- package/src/strings/fr.d.ts +3 -0
- package/src/strings/fr.d.ts.map +1 -0
- package/src/strings/fr.js +57 -0
- package/src/strings/fr.js.map +1 -0
- package/src/strings/ja.d.ts +3 -0
- package/src/strings/ja.d.ts.map +1 -0
- package/src/strings/ja.js +57 -0
- package/src/strings/ja.js.map +1 -0
- package/src/strings/uk.d.ts +3 -0
- package/src/strings/uk.d.ts.map +1 -0
- package/src/strings/uk.js +57 -0
- package/src/strings/uk.js.map +1 -0
- package/src/strings/zh-CN.d.ts +3 -0
- package/src/strings/zh-CN.d.ts.map +1 -0
- package/src/strings/zh-CN.js +57 -0
- package/src/strings/zh-CN.js.map +1 -0
- package/src/template.d.ts +13 -0
- package/src/template.d.ts.map +1 -0
- package/src/template.js +40 -0
- package/src/template.js.map +1 -0
- package/src/translation-engine.d.ts +9 -0
- package/src/translation-engine.d.ts.map +1 -0
- package/src/translation-engine.js +3 -0
- package/src/translation-engine.js.map +1 -0
- package/src/translation-request.d.ts +10 -0
- package/src/translation-request.d.ts.map +1 -0
- package/src/translation-request.js +3 -0
- package/src/translation-request.js.map +1 -0
- package/src/translation-response.d.ts +9 -0
- package/src/translation-response.d.ts.map +1 -0
- package/src/translation-response.js +3 -0
- package/src/translation-response.js.map +1 -0
- package/src/types/engine.d.ts +47 -0
- package/src/types/engine.d.ts.map +1 -0
- package/src/types/engine.js +8 -0
- package/src/types/engine.js.map +1 -0
- package/src/types/{index.ts → index.d.ts} +1 -1
- package/src/types/index.d.ts.map +1 -0
- package/src/types/index.js +9 -0
- package/src/types/index.js.map +1 -0
- package/src/types/{plural-types.ts → plural-types.d.ts} +3 -29
- package/src/types/plural-types.d.ts.map +1 -0
- package/src/types/plural-types.js +39 -0
- package/src/types/plural-types.js.map +1 -0
- package/src/{types.ts → types.d.ts} +21 -72
- package/src/types.d.ts.map +1 -0
- package/src/types.js +23 -0
- package/src/types.js.map +1 -0
- package/src/utils/currency.d.ts +81 -0
- package/src/utils/currency.d.ts.map +1 -0
- package/src/utils/currency.js +99 -0
- package/src/utils/currency.js.map +1 -0
- package/src/utils/html-escape.d.ts +22 -0
- package/src/utils/html-escape.d.ts.map +1 -0
- package/src/utils/html-escape.js +53 -0
- package/src/utils/html-escape.js.map +1 -0
- package/src/utils/{index.ts → index.d.ts} +1 -0
- package/src/utils/index.d.ts.map +1 -0
- package/src/utils/index.js +12 -0
- package/src/utils/index.js.map +1 -0
- package/src/utils/lru-cache.d.ts +42 -0
- package/src/utils/lru-cache.d.ts.map +1 -0
- package/src/utils/lru-cache.js +73 -0
- package/src/utils/lru-cache.js.map +1 -0
- package/src/utils/{plural-helpers.ts → plural-helpers.d.ts} +4 -14
- package/src/utils/plural-helpers.d.ts.map +1 -0
- package/src/utils/plural-helpers.js +35 -0
- package/src/utils/plural-helpers.js.map +1 -0
- package/src/utils/safe-object.d.ts +39 -0
- package/src/utils/safe-object.d.ts.map +1 -0
- package/src/utils/{safe-object.ts → safe-object.js} +34 -37
- package/src/utils/safe-object.js.map +1 -0
- package/src/utils/string-utils.d.ts +28 -0
- package/src/utils/string-utils.d.ts.map +1 -0
- package/src/utils/string-utils.js +63 -0
- package/src/utils/string-utils.js.map +1 -0
- package/src/utils/timezone.d.ts +50 -0
- package/src/utils/timezone.d.ts.map +1 -0
- package/src/utils/timezone.js +74 -0
- package/src/utils/timezone.js.map +1 -0
- package/src/utils/validation.d.ts +40 -0
- package/src/utils/validation.d.ts.map +1 -0
- package/src/utils/validation.js +69 -0
- package/src/utils/validation.js.map +1 -0
- package/src/utils.d.ts +65 -0
- package/src/utils.d.ts.map +1 -0
- package/src/utils.js +129 -0
- package/src/utils.js.map +1 -0
- package/src/validation/{index.ts → index.d.ts} +1 -0
- package/src/validation/index.d.ts.map +1 -0
- package/src/validation/index.js +5 -0
- package/src/validation/index.js.map +1 -0
- package/src/validation/plural-validator.d.ts +46 -0
- package/src/validation/plural-validator.d.ts.map +1 -0
- package/src/validation/plural-validator.js +123 -0
- package/src/validation/plural-validator.js.map +1 -0
- package/src/validation-config.d.ts +12 -0
- package/src/validation-config.d.ts.map +1 -0
- package/src/validation-config.js +3 -0
- package/src/validation-config.js.map +1 -0
- package/src/validation-result.d.ts +13 -0
- package/src/validation-result.d.ts.map +1 -0
- package/src/validation-result.js +3 -0
- package/src/validation-result.js.map +1 -0
- package/LICENSE +0 -21
- package/src/builders/i18n-builder.ts +0 -82
- package/src/component-definition.ts +0 -11
- package/src/component-registration.ts +0 -29
- package/src/component-registry.ts +0 -432
- package/src/context-error-type.ts +0 -7
- package/src/core/component-store.ts +0 -241
- package/src/core/context-manager.ts +0 -113
- package/src/core/enum-registry.ts +0 -106
- package/src/core/i18n-engine.ts +0 -710
- package/src/core/language-registry.ts +0 -345
- package/src/core-i18n.ts +0 -270
- package/src/core-plugin-factory.ts +0 -111
- package/src/core-string-key.ts +0 -59
- package/src/create-translation-adapter.ts +0 -93
- package/src/enum-registry.ts +0 -152
- package/src/errors/context-error.ts +0 -122
- package/src/errors/enhanced-error-base.ts +0 -260
- package/src/errors/handleable.ts +0 -152
- package/src/errors/i18n-error.ts +0 -494
- package/src/errors/simple-typed-error.ts +0 -81
- package/src/errors/translatable-generic.ts +0 -245
- package/src/errors/translatable-handleable-generic.ts +0 -222
- package/src/errors/translatable.ts +0 -138
- package/src/errors/typed-handleable.ts +0 -138
- package/src/errors/typed.ts +0 -617
- package/src/gender/gender-resolver.ts +0 -40
- package/src/global-active-context.ts +0 -266
- package/src/icu/ast.ts +0 -56
- package/src/icu/compiler.ts +0 -96
- package/src/icu/formatter-registry.ts +0 -36
- package/src/icu/formatters/base-formatter.ts +0 -8
- package/src/icu/formatters/date-formatter.ts +0 -30
- package/src/icu/formatters/number-formatter.ts +0 -32
- package/src/icu/formatters/plural-formatter.ts +0 -12
- package/src/icu/formatters/select-formatter.ts +0 -7
- package/src/icu/formatters/selectordinal-formatter.ts +0 -17
- package/src/icu/formatters/time-formatter.ts +0 -30
- package/src/icu/helpers.ts +0 -34
- package/src/icu/parser.ts +0 -242
- package/src/icu/runtime.ts +0 -37
- package/src/icu/tokenizer.ts +0 -212
- package/src/icu/validator.ts +0 -163
- package/src/interfaces/active-context.interface.ts +0 -41
- package/src/interfaces/component-config.interface.ts +0 -17
- package/src/interfaces/engine-config.interface.ts +0 -22
- package/src/interfaces/global-active-context.ts +0 -39
- package/src/interfaces/handleable-error-options.ts +0 -13
- package/src/interfaces/handleable.ts +0 -20
- package/src/interfaces/i18n-engine.interface.ts +0 -57
- package/src/interfaces/language-definition.interface.ts +0 -17
- package/src/interfaces/translation-options.interface.ts +0 -15
- package/src/interfaces/validation-result.interface.ts +0 -24
- package/src/language-codes.ts +0 -40
- package/src/language-definition.ts +0 -13
- package/src/plugin-i18n-engine.ts +0 -707
- package/src/pluralization/language-plural-map.ts +0 -186
- package/src/pluralization/plural-rules.ts +0 -228
- package/src/registry-config.ts +0 -16
- package/src/registry-error-type.ts +0 -19
- package/src/registry-error.ts +0 -100
- package/src/strict-types.ts +0 -35
- package/src/strings/de.ts +0 -75
- package/src/strings/en-GB.ts +0 -74
- package/src/strings/en-US.ts +0 -74
- package/src/strings/es.ts +0 -74
- package/src/strings/fr.ts +0 -75
- package/src/strings/ja.ts +0 -73
- package/src/strings/uk.ts +0 -73
- package/src/strings/zh-CN.ts +0 -72
- package/src/template.ts +0 -72
- package/src/translation-engine.ts +0 -18
- package/src/translation-request.ts +0 -12
- package/src/translation-response.ts +0 -8
- package/src/types/engine.ts +0 -55
- package/src/utils/currency.ts +0 -141
- package/src/utils/html-escape.ts +0 -55
- package/src/utils/lru-cache.ts +0 -76
- package/src/utils/string-utils.ts +0 -77
- package/src/utils/timezone.ts +0 -76
- package/src/utils/validation.ts +0 -66
- package/src/utils.ts +0 -215
- package/src/validation/plural-validator.ts +0 -168
- package/src/validation-config.ts +0 -11
- package/src/validation-result.ts +0 -12
package/src/errors/typed.ts
DELETED
|
@@ -1,617 +0,0 @@
|
|
|
1
|
-
// New plugin architecture imports
|
|
2
|
-
// CoreLanguageCode is deprecated - using string for flexibility
|
|
3
|
-
import { CoreI18nComponentId } from '../core-component-id';
|
|
4
|
-
import { CoreStringKey } from '../core-string-key';
|
|
5
|
-
import { I18nEngine } from '../core/i18n-engine';
|
|
6
|
-
import { TranslationEngine } from '../translation-engine';
|
|
7
|
-
import { TypedError as SimpleTypedError } from './simple-typed-error';
|
|
8
|
-
|
|
9
|
-
export type { TranslationEngine };
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Type constraint to ensure reasonMap has entries for all enum values
|
|
13
|
-
*/
|
|
14
|
-
export type CompleteReasonMap<
|
|
15
|
-
TEnum extends Record<string, string | number>,
|
|
16
|
-
TStringKey extends string,
|
|
17
|
-
> = Record<TEnum[keyof TEnum], TStringKey>;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Base typed error class with full i18n feature support.
|
|
21
|
-
*
|
|
22
|
-
* **Supported i18n Features** (via translation strings):
|
|
23
|
-
* - ICU MessageFormat: plural, select, selectordinal
|
|
24
|
-
* - Pluralization: 37 languages with CLDR rules
|
|
25
|
-
* - Gender support: male, female, neutral, other
|
|
26
|
-
* - Number formatting: integer, currency, percent
|
|
27
|
-
* - Date/Time formatting: short, medium, long, full
|
|
28
|
-
* - Nested messages: up to 4 levels deep
|
|
29
|
-
*
|
|
30
|
-
* **Translation String Examples:**
|
|
31
|
-
* ```typescript
|
|
32
|
-
* // Register translations with ICU features
|
|
33
|
-
* engine.registerComponent({
|
|
34
|
-
* component: { id: 'errors', name: 'Errors', stringKeys: ['invalidCount'] },
|
|
35
|
-
* strings: {
|
|
36
|
-
* 'en-US': {
|
|
37
|
-
* invalidCount: "{count, plural, one {# item is invalid} other {# items are invalid}}"
|
|
38
|
-
* }
|
|
39
|
-
* }
|
|
40
|
-
* });
|
|
41
|
-
*
|
|
42
|
-
* // Use with typed error
|
|
43
|
-
* throw BaseTypedError.createTranslated(
|
|
44
|
-
* engine, 'errors', ErrorType.InvalidCount, reasonMap,
|
|
45
|
-
* { count: 5 }, 'en-US'
|
|
46
|
-
* );
|
|
47
|
-
* // Result: "5 items are invalid"
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export abstract class BaseTypedError<
|
|
51
|
-
TEnum extends Record<string, string>,
|
|
52
|
-
> extends Error {
|
|
53
|
-
constructor(
|
|
54
|
-
public override readonly type: TEnum[keyof TEnum],
|
|
55
|
-
message: string,
|
|
56
|
-
public override readonly metadata?: Record<string, any>,
|
|
57
|
-
) {
|
|
58
|
-
super(message);
|
|
59
|
-
this.name = this.constructor.name;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Create a simple typed error without engine dependency
|
|
64
|
-
*/
|
|
65
|
-
static createSimple<
|
|
66
|
-
TEnum extends Record<string, string>,
|
|
67
|
-
TError extends BaseTypedError<TEnum>,
|
|
68
|
-
>(
|
|
69
|
-
this: new (
|
|
70
|
-
type: TEnum[keyof TEnum],
|
|
71
|
-
message: string,
|
|
72
|
-
metadata?: Record<string, any>,
|
|
73
|
-
) => TError,
|
|
74
|
-
type: TEnum[keyof TEnum],
|
|
75
|
-
message: string,
|
|
76
|
-
metadata?: Record<string, any>,
|
|
77
|
-
): TError {
|
|
78
|
-
return new this(type, message, metadata);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Create a typed error with translation support
|
|
83
|
-
*/
|
|
84
|
-
static createTranslated<
|
|
85
|
-
TEnum extends Record<string, string>,
|
|
86
|
-
TStringKey extends string,
|
|
87
|
-
TError extends BaseTypedError<TEnum>,
|
|
88
|
-
>(
|
|
89
|
-
this: new (
|
|
90
|
-
type: TEnum[keyof TEnum],
|
|
91
|
-
message: string,
|
|
92
|
-
metadata?: Record<string, any>,
|
|
93
|
-
) => TError,
|
|
94
|
-
engine: TranslationEngine,
|
|
95
|
-
componentId: string,
|
|
96
|
-
type: TEnum[keyof TEnum],
|
|
97
|
-
reasonMap: CompleteReasonMap<TEnum, TStringKey>,
|
|
98
|
-
variables?: Record<string, string | number>,
|
|
99
|
-
language?: string,
|
|
100
|
-
metadata?: Record<string, any>,
|
|
101
|
-
): TError {
|
|
102
|
-
const key = reasonMap[type];
|
|
103
|
-
let message: string;
|
|
104
|
-
|
|
105
|
-
if (key && engine) {
|
|
106
|
-
// Try to translate the error message using the engine
|
|
107
|
-
message = engine.safeTranslate(componentId, key, variables, language);
|
|
108
|
-
} else {
|
|
109
|
-
// Fallback to a basic English message
|
|
110
|
-
message = `Error: ${type}${
|
|
111
|
-
metadata ? ` - ${JSON.stringify(metadata)}` : ''
|
|
112
|
-
}`;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return new this(type, message, metadata);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* AbstractTypedError with complete enum coverage and full i18n feature support.
|
|
121
|
-
* @deprecated Use SimpleTypedError from './simple-typed-error' for new code
|
|
122
|
-
*
|
|
123
|
-
* **Supported i18n Features** (via translation strings):
|
|
124
|
-
* - ICU MessageFormat: plural, select, selectordinal
|
|
125
|
-
* - Pluralization: 37 languages with CLDR rules
|
|
126
|
-
* - Gender support: male, female, neutral, other
|
|
127
|
-
* - Number formatting: integer, currency, percent
|
|
128
|
-
* - Nested messages: up to 4 levels deep
|
|
129
|
-
*
|
|
130
|
-
* **Translation String Examples:**
|
|
131
|
-
* ```typescript
|
|
132
|
-
* // Define error types
|
|
133
|
-
* enum ValidationError {
|
|
134
|
-
* InvalidCount = 'invalidCount',
|
|
135
|
-
* ThresholdExceeded = 'thresholdExceeded'
|
|
136
|
-
* }
|
|
137
|
-
*
|
|
138
|
-
* // Register translations with ICU
|
|
139
|
-
* engine.registerComponent({
|
|
140
|
-
* component: { id: 'validation', stringKeys: ['invalidCount', 'thresholdExceeded'] },
|
|
141
|
-
* strings: {
|
|
142
|
-
* 'en-US': {
|
|
143
|
-
* invalidCount: "{count, plural, one {# error found} other {# errors found}}",
|
|
144
|
-
* thresholdExceeded: "Value {value, number, integer} exceeds limit"
|
|
145
|
-
* }
|
|
146
|
-
* }
|
|
147
|
-
* });
|
|
148
|
-
*
|
|
149
|
-
* // Use typed error
|
|
150
|
-
* throw new MyTypedError('validation', ValidationError.InvalidCount, reasonMap, 'en-US', { count: 3 });
|
|
151
|
-
* // Result: "3 errors found"
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
export abstract class AbstractTypedError<
|
|
155
|
-
TEnum extends Record<string, string>,
|
|
156
|
-
TStringKey extends string,
|
|
157
|
-
> extends Error {
|
|
158
|
-
constructor(
|
|
159
|
-
public override readonly componentId: string,
|
|
160
|
-
public override readonly type: TEnum[keyof TEnum],
|
|
161
|
-
public override readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>,
|
|
162
|
-
public readonly language?: string,
|
|
163
|
-
public readonly otherVars?: Record<string, string | number>,
|
|
164
|
-
) {
|
|
165
|
-
const key = reasonMap[type];
|
|
166
|
-
|
|
167
|
-
// Lazy initialization: getInstance() is only called when error is constructed
|
|
168
|
-
const engine = I18nEngine.getInstance('default');
|
|
169
|
-
|
|
170
|
-
if (!key) {
|
|
171
|
-
throw new Error(
|
|
172
|
-
engine.safeTranslate(
|
|
173
|
-
CoreI18nComponentId,
|
|
174
|
-
CoreStringKey.Error_MissingTranslationKeyTemplate,
|
|
175
|
-
{ type },
|
|
176
|
-
language,
|
|
177
|
-
),
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Use translate instead of safeTranslate to get actual translations
|
|
182
|
-
let message: string;
|
|
183
|
-
try {
|
|
184
|
-
message = engine.translate(componentId, key, otherVars, language);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
// Fallback to safeTranslate if translate fails
|
|
187
|
-
message = engine.safeTranslate(componentId, key, otherVars, language);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
super(message);
|
|
191
|
-
this.name = this.constructor.name;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Component-based TypedError that works with the component registration system
|
|
197
|
-
* @deprecated Use TypedError instead - PluginTypedError is an alias for backward compatibility
|
|
198
|
-
*/
|
|
199
|
-
export abstract class PluginTypedError<
|
|
200
|
-
TEnum extends Record<string, string>,
|
|
201
|
-
TStringKey extends string,
|
|
202
|
-
> extends Error {
|
|
203
|
-
constructor(
|
|
204
|
-
public override readonly componentId: string,
|
|
205
|
-
public override readonly type: TEnum[keyof TEnum],
|
|
206
|
-
public override readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>,
|
|
207
|
-
public readonly language?: string,
|
|
208
|
-
public readonly otherVars?: Record<string, string | number>,
|
|
209
|
-
) {
|
|
210
|
-
const key = reasonMap[type];
|
|
211
|
-
|
|
212
|
-
// Lazy initialization: getInstance() is only called when error is constructed
|
|
213
|
-
const engine = I18nEngine.getInstance('default');
|
|
214
|
-
|
|
215
|
-
// If key is not found in the reason map, use core error message
|
|
216
|
-
if (!key) {
|
|
217
|
-
const errorMsg = engine.safeTranslate(
|
|
218
|
-
CoreI18nComponentId,
|
|
219
|
-
CoreStringKey.Error_StringKeyNotFoundTemplate,
|
|
220
|
-
{
|
|
221
|
-
stringKey: String(type),
|
|
222
|
-
componentId: componentId,
|
|
223
|
-
},
|
|
224
|
-
language,
|
|
225
|
-
);
|
|
226
|
-
throw new Error(errorMsg);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Translate the error message using the component and string key
|
|
230
|
-
const translatedMessage = engine.safeTranslate(
|
|
231
|
-
componentId,
|
|
232
|
-
key,
|
|
233
|
-
otherVars,
|
|
234
|
-
language,
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
super(translatedMessage);
|
|
238
|
-
this.name = this.constructor.name;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Component-based TypedError with full i18n feature support.
|
|
244
|
-
*
|
|
245
|
-
* **Supported i18n Features** (via translation strings):
|
|
246
|
-
* - ICU MessageFormat: plural, select, selectordinal
|
|
247
|
-
* - Pluralization: 37 languages with CLDR rules
|
|
248
|
-
* - Gender support: male, female, neutral, other
|
|
249
|
-
* - Number formatting: integer, currency, percent
|
|
250
|
-
* - SelectOrdinal: 1st, 2nd, 3rd formatting
|
|
251
|
-
* - Nested messages: complex multi-level patterns
|
|
252
|
-
*
|
|
253
|
-
* **Translation String Examples:**
|
|
254
|
-
* ```typescript
|
|
255
|
-
* // Define component errors
|
|
256
|
-
* enum UserError {
|
|
257
|
-
* AccountLocked = 'accountLocked',
|
|
258
|
-
* TooManyAttempts = 'tooManyAttempts'
|
|
259
|
-
* }
|
|
260
|
-
*
|
|
261
|
-
* // Register with ICU features
|
|
262
|
-
* engine.registerComponent({
|
|
263
|
-
* component: { id: 'user', stringKeys: ['accountLocked', 'tooManyAttempts'] },
|
|
264
|
-
* strings: {
|
|
265
|
-
* 'en-US': {
|
|
266
|
-
* accountLocked: "{gender, select, male {His account} female {Her account} other {Their account}} is locked",
|
|
267
|
-
* tooManyAttempts: "{count, plural, one {# attempt} other {# attempts}} failed. Try again in {minutes, number, integer} minutes."
|
|
268
|
-
* }
|
|
269
|
-
* }
|
|
270
|
-
* });
|
|
271
|
-
*
|
|
272
|
-
* // Use component error
|
|
273
|
-
* throw new MyComponentError('user', UserError.TooManyAttempts, reasonMap, 'en-US', { count: 5, minutes: 10 });
|
|
274
|
-
* // Result: "5 attempts failed. Try again in 10 minutes."
|
|
275
|
-
* ```
|
|
276
|
-
*/
|
|
277
|
-
export abstract class ComponentTypedError<
|
|
278
|
-
TEnum extends Record<string, string>,
|
|
279
|
-
TStringKey extends string,
|
|
280
|
-
> extends Error {
|
|
281
|
-
constructor(
|
|
282
|
-
public override readonly componentId: string,
|
|
283
|
-
public override readonly type: TEnum[keyof TEnum],
|
|
284
|
-
public override readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>,
|
|
285
|
-
public readonly language?: string,
|
|
286
|
-
public readonly otherVars?: Record<string, string | number>,
|
|
287
|
-
) {
|
|
288
|
-
const key = reasonMap[type];
|
|
289
|
-
|
|
290
|
-
// Lazy initialization: getInstance() is only called when error is constructed
|
|
291
|
-
const engine = I18nEngine.getInstance('default');
|
|
292
|
-
|
|
293
|
-
// If key is not found in the reason map, use core error message
|
|
294
|
-
if (!key) {
|
|
295
|
-
const errorMsg = engine.safeTranslate(
|
|
296
|
-
CoreI18nComponentId,
|
|
297
|
-
CoreStringKey.Error_StringKeyNotFoundTemplate,
|
|
298
|
-
{
|
|
299
|
-
stringKey: String(type),
|
|
300
|
-
componentId: componentId,
|
|
301
|
-
},
|
|
302
|
-
language,
|
|
303
|
-
);
|
|
304
|
-
throw new Error(errorMsg);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// Translate the error message using the component and string key
|
|
308
|
-
const translatedMessage = engine.safeTranslate(
|
|
309
|
-
componentId,
|
|
310
|
-
key,
|
|
311
|
-
otherVars,
|
|
312
|
-
language,
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
super(translatedMessage);
|
|
316
|
-
this.name = this.constructor.name;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Core system TypedError using core component strings with full i18n support.
|
|
322
|
-
*
|
|
323
|
-
* **Supported i18n Features** (via CoreStringKey translations):
|
|
324
|
-
* - ICU MessageFormat: plural, select, selectordinal
|
|
325
|
-
* - Pluralization: 37 languages with CLDR rules
|
|
326
|
-
* - Gender support: male, female, neutral, other
|
|
327
|
-
* - Number formatting: integer, currency, percent
|
|
328
|
-
* - Nested messages: complex patterns
|
|
329
|
-
*
|
|
330
|
-
* **Usage Example:**
|
|
331
|
-
* ```typescript
|
|
332
|
-
* // Define core error types
|
|
333
|
-
* enum CoreErrorType {
|
|
334
|
-
* InvalidOperation = 'invalidOperation',
|
|
335
|
-
* ResourceNotFound = 'resourceNotFound'
|
|
336
|
-
* }
|
|
337
|
-
*
|
|
338
|
-
* // Core strings already registered with ICU features
|
|
339
|
-
* const reasonMap: CompleteReasonMap<typeof CoreErrorType, CoreStringKey> = {
|
|
340
|
-
* [CoreErrorType.InvalidOperation]: CoreStringKey.Error_InvalidOperation,
|
|
341
|
-
* [CoreErrorType.ResourceNotFound]: CoreStringKey.Error_ResourceNotFound
|
|
342
|
-
* };
|
|
343
|
-
*
|
|
344
|
-
* // Use core typed error
|
|
345
|
-
* throw new MyCoreError(CoreErrorType.ResourceNotFound, reasonMap, 'en-US', { resource: 'user', id: 123 });
|
|
346
|
-
* ```
|
|
347
|
-
*/
|
|
348
|
-
export abstract class CoreTypedError<
|
|
349
|
-
TEnum extends Record<string, string>,
|
|
350
|
-
> extends Error {
|
|
351
|
-
constructor(
|
|
352
|
-
public override readonly type: TEnum[keyof TEnum],
|
|
353
|
-
public override readonly reasonMap: CompleteReasonMap<TEnum, CoreStringKey>,
|
|
354
|
-
public readonly language?: string,
|
|
355
|
-
public readonly otherVars?: Record<string, string | number>,
|
|
356
|
-
) {
|
|
357
|
-
const key = reasonMap[type];
|
|
358
|
-
|
|
359
|
-
// Lazy initialization: getInstance() is only called when error is constructed
|
|
360
|
-
const engine = I18nEngine.getInstance('default');
|
|
361
|
-
|
|
362
|
-
// If key is not found in the reason map, use a fallback error
|
|
363
|
-
if (!key) {
|
|
364
|
-
const errorMsg = engine.safeTranslate(
|
|
365
|
-
CoreI18nComponentId,
|
|
366
|
-
CoreStringKey.Error_StringKeyNotFoundTemplate,
|
|
367
|
-
{
|
|
368
|
-
stringKey: String(type),
|
|
369
|
-
componentId: CoreI18nComponentId,
|
|
370
|
-
},
|
|
371
|
-
language,
|
|
372
|
-
);
|
|
373
|
-
throw new Error(errorMsg);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// Translate the error message using the core component
|
|
377
|
-
const translatedMessage = engine.safeTranslate(
|
|
378
|
-
CoreI18nComponentId,
|
|
379
|
-
key,
|
|
380
|
-
otherVars,
|
|
381
|
-
language,
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
super(translatedMessage);
|
|
385
|
-
this.name = this.constructor.name;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Helper function to create a component-based TypedError with automatic engine detection
|
|
391
|
-
* @deprecated Use createComponentTypedError instead
|
|
392
|
-
*/
|
|
393
|
-
export function createPluginTypedError<
|
|
394
|
-
TEnum extends Record<string, string>,
|
|
395
|
-
TStringKey extends string,
|
|
396
|
-
>(
|
|
397
|
-
componentId: string,
|
|
398
|
-
type: TEnum[keyof TEnum],
|
|
399
|
-
reasonMap: CompleteReasonMap<TEnum, TStringKey>,
|
|
400
|
-
otherVars?: Record<string, string | number>,
|
|
401
|
-
language?: string,
|
|
402
|
-
instanceKey?: string,
|
|
403
|
-
): Error {
|
|
404
|
-
return createComponentTypedError(
|
|
405
|
-
componentId,
|
|
406
|
-
type,
|
|
407
|
-
reasonMap,
|
|
408
|
-
otherVars,
|
|
409
|
-
language,
|
|
410
|
-
instanceKey,
|
|
411
|
-
);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Helper function to create a component-based TypedError with automatic engine detection
|
|
416
|
-
*/
|
|
417
|
-
export function createComponentTypedError<
|
|
418
|
-
TEnum extends Record<string, string>,
|
|
419
|
-
TStringKey extends string,
|
|
420
|
-
>(
|
|
421
|
-
componentId: string,
|
|
422
|
-
type: TEnum[keyof TEnum],
|
|
423
|
-
reasonMap: CompleteReasonMap<TEnum, TStringKey>,
|
|
424
|
-
otherVars?: Record<string, string | number>,
|
|
425
|
-
language?: string,
|
|
426
|
-
instanceKey?: string,
|
|
427
|
-
): SimpleTypedError {
|
|
428
|
-
const key = reasonMap[type];
|
|
429
|
-
|
|
430
|
-
if (!key) {
|
|
431
|
-
throw new Error(`Missing key for type ${type} in reason map`);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// Lazy initialization: getInstance() is only called when function is executed
|
|
435
|
-
const engine = I18nEngine.getInstance(instanceKey || 'default');
|
|
436
|
-
const message = engine.safeTranslate(componentId, key, otherVars, language);
|
|
437
|
-
|
|
438
|
-
const error = new SimpleTypedError(message, {
|
|
439
|
-
type,
|
|
440
|
-
componentId,
|
|
441
|
-
reasonMap,
|
|
442
|
-
});
|
|
443
|
-
error.name = 'PluginTypedError';
|
|
444
|
-
|
|
445
|
-
return error;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Helper function to create a core system TypedError with automatic engine detection
|
|
450
|
-
*/
|
|
451
|
-
export function createCoreTypedError<TEnum extends Record<string, string>>(
|
|
452
|
-
type: TEnum[keyof TEnum],
|
|
453
|
-
reasonMap: CompleteReasonMap<TEnum, CoreStringKey>,
|
|
454
|
-
otherVars?: Record<string, string | number>,
|
|
455
|
-
language?: string,
|
|
456
|
-
instanceKey?: string,
|
|
457
|
-
): SimpleTypedError {
|
|
458
|
-
const key = reasonMap[type];
|
|
459
|
-
|
|
460
|
-
if (!key) {
|
|
461
|
-
throw new Error(`Missing key for type ${type} in reason map`);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// Lazy initialization: getInstance() is only called when function is executed
|
|
465
|
-
const engine = I18nEngine.getInstance(instanceKey || 'default');
|
|
466
|
-
const message = engine.safeTranslate(
|
|
467
|
-
CoreI18nComponentId,
|
|
468
|
-
key,
|
|
469
|
-
otherVars,
|
|
470
|
-
language,
|
|
471
|
-
);
|
|
472
|
-
|
|
473
|
-
const error = new SimpleTypedError(message, {
|
|
474
|
-
type,
|
|
475
|
-
componentId: CoreI18nComponentId,
|
|
476
|
-
reasonMap,
|
|
477
|
-
});
|
|
478
|
-
error.name = 'CoreTypedError';
|
|
479
|
-
|
|
480
|
-
return error;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* Create a simple error with translation support (generalized pattern from RegistryError)
|
|
485
|
-
*/
|
|
486
|
-
export function createTranslatedError<
|
|
487
|
-
TEnum extends Record<string, string>,
|
|
488
|
-
TStringKey extends string,
|
|
489
|
-
>(
|
|
490
|
-
engine: TranslationEngine,
|
|
491
|
-
componentId: string,
|
|
492
|
-
type: TEnum[keyof TEnum],
|
|
493
|
-
reasonMap: Record<TEnum[keyof TEnum], TStringKey>,
|
|
494
|
-
variables?: Record<string, string | number>,
|
|
495
|
-
language?: string,
|
|
496
|
-
metadata?: Record<string, any>,
|
|
497
|
-
errorName?: string,
|
|
498
|
-
): SimpleTypedError {
|
|
499
|
-
const key = reasonMap[type];
|
|
500
|
-
let message: string;
|
|
501
|
-
|
|
502
|
-
if (key && engine) {
|
|
503
|
-
try {
|
|
504
|
-
// Try to translate the error message using the engine
|
|
505
|
-
message = engine.safeTranslate(componentId, key, variables, language);
|
|
506
|
-
} catch (translationError) {
|
|
507
|
-
// Fallback if translation fails
|
|
508
|
-
message = `Error: ${type}${
|
|
509
|
-
metadata ? ` - ${JSON.stringify(metadata)}` : ''
|
|
510
|
-
}`;
|
|
511
|
-
}
|
|
512
|
-
} else {
|
|
513
|
-
// Fallback to a basic English message
|
|
514
|
-
message = `Error: ${type}${
|
|
515
|
-
metadata ? ` - ${JSON.stringify(metadata)}` : ''
|
|
516
|
-
}`;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
const error = new SimpleTypedError(message, {
|
|
520
|
-
type,
|
|
521
|
-
componentId,
|
|
522
|
-
metadata,
|
|
523
|
-
});
|
|
524
|
-
error.name = errorName || 'TranslatedError';
|
|
525
|
-
|
|
526
|
-
return error;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Example usage of the new plugin-based TypedError system
|
|
531
|
-
*/
|
|
532
|
-
|
|
533
|
-
// Example 1: Core system error using CoreStringKey
|
|
534
|
-
/*
|
|
535
|
-
enum DatabaseErrorType {
|
|
536
|
-
ConnectionFailed = 'connectionFailed',
|
|
537
|
-
QueryTimeout = 'queryTimeout',
|
|
538
|
-
AccessDenied = 'accessDenied'
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
const coreErrorReasonMap: CompleteReasonMap<typeof DatabaseErrorType, CoreStringKey> = {
|
|
542
|
-
[DatabaseErrorType.ConnectionFailed]: CoreStringKey.Error_NetworkError,
|
|
543
|
-
[DatabaseErrorType.QueryTimeout]: CoreStringKey.Error_InternalServer,
|
|
544
|
-
[DatabaseErrorType.AccessDenied]: CoreStringKey.Error_AccessDenied
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
class DatabaseError extends CoreTypedError<typeof DatabaseErrorType> {
|
|
548
|
-
constructor(
|
|
549
|
-
type: DatabaseErrorType,
|
|
550
|
-
otherVars?: Record<string, string | number>,
|
|
551
|
-
language?: string
|
|
552
|
-
) {
|
|
553
|
-
super(type, coreErrorReasonMap, language, otherVars);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
// Usage:
|
|
558
|
-
// throw new DatabaseError(DatabaseErrorType.ConnectionFailed);
|
|
559
|
-
*/
|
|
560
|
-
|
|
561
|
-
// Example 2: Custom component error with custom strings
|
|
562
|
-
/*
|
|
563
|
-
enum UserErrorType {
|
|
564
|
-
UserNotFound = 'userNotFound',
|
|
565
|
-
InvalidCredentials = 'invalidCredentials',
|
|
566
|
-
AccountLocked = 'accountLocked'
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
enum UserErrorStringKey {
|
|
570
|
-
UserNotFoundMessage = 'userNotFoundMessage',
|
|
571
|
-
InvalidCredentialsMessage = 'invalidCredentialsMessage',
|
|
572
|
-
AccountLockedMessage = 'accountLockedMessage'
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
const userErrorReasonMap: CompleteReasonMap<typeof UserErrorType, UserErrorStringKey> = {
|
|
576
|
-
[UserErrorType.UserNotFound]: UserErrorStringKey.UserNotFoundMessage,
|
|
577
|
-
[UserErrorType.InvalidCredentials]: UserErrorStringKey.InvalidCredentialsMessage,
|
|
578
|
-
[UserErrorType.AccountLocked]: UserErrorStringKey.AccountLockedMessage
|
|
579
|
-
};
|
|
580
|
-
|
|
581
|
-
class UserError extends PluginTypedError<typeof UserErrorType, UserErrorStringKey> {
|
|
582
|
-
constructor(
|
|
583
|
-
type: UserErrorType,
|
|
584
|
-
otherVars?: Record<string, string | number>,
|
|
585
|
-
language?: string
|
|
586
|
-
) {
|
|
587
|
-
super('user-system', type, userErrorReasonMap, language, otherVars);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
// Usage:
|
|
592
|
-
// throw new UserError(UserErrorType.UserNotFound, { username: 'john_doe' });
|
|
593
|
-
*/
|
|
594
|
-
|
|
595
|
-
// Example 3: Using helper functions for simpler error creation
|
|
596
|
-
/*
|
|
597
|
-
// Define your error types and mappings
|
|
598
|
-
enum ApiErrorType {
|
|
599
|
-
Timeout = 'timeout',
|
|
600
|
-
NotFound = 'notFound'
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
const apiErrorMap: CompleteReasonMap<typeof ApiErrorType, CoreStringKey> = {
|
|
604
|
-
[ApiErrorType.Timeout]: CoreStringKey.Error_NetworkError,
|
|
605
|
-
[ApiErrorType.NotFound]: CoreStringKey.Error_NotFound
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
// Create errors using helper functions
|
|
609
|
-
function throwApiError(type: ApiErrorType, vars?: Record<string, string | number>) {
|
|
610
|
-
throw createCoreTypedError(type, apiErrorMap, vars);
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
// Usage:
|
|
614
|
-
// throwApiError(ApiErrorType.NotFound, { resource: 'user' });
|
|
615
|
-
*/
|
|
616
|
-
|
|
617
|
-
// Export the type for external use (already exported above)
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gender form resolution
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { GenderCategory, GenderedString, isGenderedString } from './gender-categories';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Resolve a gender-specific form with fallback logic.
|
|
9
|
-
* If the value is a simple string, it's returned as-is.
|
|
10
|
-
* For gendered strings, it tries the requested gender, then neutral, then other, then the first available form.
|
|
11
|
-
* @param value - The gendered string value or simple string
|
|
12
|
-
* @param gender - The gender category to resolve (optional)
|
|
13
|
-
* @returns The resolved string form
|
|
14
|
-
*/
|
|
15
|
-
export function resolveGenderForm(
|
|
16
|
-
value: GenderedString,
|
|
17
|
-
gender: GenderCategory | string | undefined
|
|
18
|
-
): string {
|
|
19
|
-
if (typeof value === 'string') {
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!isGenderedString(value)) {
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// No gender provided - use neutral or other or first available
|
|
28
|
-
if (!gender) {
|
|
29
|
-
return value.neutral || value.other || Object.values(value)[0] || '';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Try requested gender
|
|
33
|
-
const requested = value[gender as GenderCategory];
|
|
34
|
-
if (requested) {
|
|
35
|
-
return requested;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Fallback: neutral → other → first available
|
|
39
|
-
return value.neutral || value.other || Object.values(value)[0] || '';
|
|
40
|
-
}
|