@digitaldefiance/i18n-lib 3.8.1 → 3.8.3
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 +7 -6
- package/src/{active-context.ts → active-context.d.ts} +1 -0
- package/src/active-context.d.ts.map +1 -0
- package/src/active-context.js +3 -0
- package/src/active-context.js.map +1 -0
- package/src/builders/i18n-builder.d.ts +26 -0
- package/src/builders/i18n-builder.d.ts.map +1 -0
- package/src/builders/i18n-builder.js +70 -0
- package/src/builders/i18n-builder.js.map +1 -0
- package/src/builders/{index.ts → index.d.ts} +1 -1
- package/src/builders/index.d.ts.map +1 -0
- package/src/builders/index.js +8 -0
- package/src/builders/index.js.map +1 -0
- package/src/component-definition.d.ts +12 -0
- package/src/component-definition.d.ts.map +1 -0
- package/src/component-definition.js +3 -0
- package/src/component-definition.js.map +1 -0
- package/src/component-registration.d.ts +22 -0
- package/src/component-registration.d.ts.map +1 -0
- package/src/component-registration.js +3 -0
- package/src/component-registration.js.map +1 -0
- package/src/component-registry.d.ts +102 -0
- package/src/component-registry.d.ts.map +1 -0
- package/src/component-registry.js +282 -0
- package/src/component-registry.js.map +1 -0
- package/src/context-error-type.d.ts +8 -0
- package/src/context-error-type.d.ts.map +1 -0
- package/src/context-error-type.js +12 -0
- package/src/context-error-type.js.map +1 -0
- package/src/core/component-store.d.ts +93 -0
- package/src/core/component-store.d.ts.map +1 -0
- package/src/core/component-store.js +198 -0
- package/src/core/component-store.js.map +1 -0
- package/src/core/context-manager.d.ts +72 -0
- package/src/core/context-manager.d.ts.map +1 -0
- package/src/core/context-manager.js +98 -0
- package/src/core/context-manager.js.map +1 -0
- package/src/core/enum-registry.d.ts +48 -0
- package/src/core/enum-registry.d.ts.map +1 -0
- package/src/core/enum-registry.js +85 -0
- package/src/core/enum-registry.js.map +1 -0
- package/src/core/i18n-engine.d.ts +241 -0
- package/src/core/i18n-engine.d.ts.map +1 -0
- package/src/core/i18n-engine.js +568 -0
- package/src/core/i18n-engine.js.map +1 -0
- package/src/core/{index.ts → index.d.ts} +1 -4
- package/src/core/index.d.ts.map +1 -0
- package/src/core/index.js +21 -0
- package/src/core/index.js.map +1 -0
- package/src/core/language-registry.d.ts +180 -0
- package/src/core/language-registry.d.ts.map +1 -0
- package/src/core/language-registry.js +298 -0
- package/src/core/language-registry.js.map +1 -0
- package/src/{core-component-id.ts → core-component-id.d.ts} +2 -1
- package/src/core-component-id.d.ts.map +1 -0
- package/src/core-component-id.js +9 -0
- package/src/core-component-id.js.map +1 -0
- package/src/core-i18n.d.ts +69 -0
- package/src/core-i18n.d.ts.map +1 -0
- package/src/core-i18n.js +219 -0
- package/src/core-i18n.js.map +1 -0
- package/src/core-plugin-factory.d.ts +28 -0
- package/src/core-plugin-factory.d.ts.map +1 -0
- package/src/core-plugin-factory.js +80 -0
- package/src/core-plugin-factory.js.map +1 -0
- package/src/core-string-key.d.ts +52 -0
- package/src/core-string-key.d.ts.map +1 -0
- package/src/core-string-key.js +61 -0
- package/src/core-string-key.js.map +1 -0
- package/src/create-translation-adapter.d.ts +33 -0
- package/src/create-translation-adapter.d.ts.map +1 -0
- package/src/create-translation-adapter.js +72 -0
- package/src/create-translation-adapter.js.map +1 -0
- package/src/enum-registry.d.ts +65 -0
- package/src/enum-registry.d.ts.map +1 -0
- package/src/enum-registry.js +123 -0
- package/src/enum-registry.js.map +1 -0
- package/src/errors/{base.ts → base.d.ts} +1 -1
- package/src/errors/base.d.ts.map +1 -0
- package/src/errors/base.js +11 -0
- package/src/errors/base.js.map +1 -0
- package/src/errors/context-error.d.ts +50 -0
- package/src/errors/context-error.d.ts.map +1 -0
- package/src/errors/context-error.js +93 -0
- package/src/errors/context-error.js.map +1 -0
- package/src/errors/enhanced-error-base.d.ts +125 -0
- package/src/errors/enhanced-error-base.d.ts.map +1 -0
- package/src/errors/enhanced-error-base.js +165 -0
- package/src/errors/enhanced-error-base.js.map +1 -0
- package/src/errors/handleable.d.ts +83 -0
- package/src/errors/handleable.d.ts.map +1 -0
- package/src/errors/handleable.js +136 -0
- package/src/errors/handleable.js.map +1 -0
- package/src/errors/i18n-error.d.ts +211 -0
- package/src/errors/i18n-error.d.ts.map +1 -0
- package/src/errors/i18n-error.js +358 -0
- package/src/errors/i18n-error.js.map +1 -0
- package/src/errors/{index.ts → index.d.ts} +1 -4
- package/src/errors/index.d.ts.map +1 -0
- package/src/errors/index.js +17 -0
- package/src/errors/index.js.map +1 -0
- package/src/errors/simple-typed-error.d.ts +53 -0
- package/src/errors/simple-typed-error.d.ts.map +1 -0
- package/src/errors/simple-typed-error.js +51 -0
- package/src/errors/simple-typed-error.js.map +1 -0
- package/src/errors/{translatable-exports.ts → translatable-exports.d.ts} +1 -1
- package/src/errors/translatable-exports.d.ts.map +1 -0
- package/src/errors/translatable-exports.js +15 -0
- package/src/errors/translatable-exports.js.map +1 -0
- package/src/errors/translatable-generic.d.ts +87 -0
- package/src/errors/translatable-generic.d.ts.map +1 -0
- package/src/errors/translatable-generic.js +139 -0
- package/src/errors/translatable-generic.js.map +1 -0
- package/src/errors/translatable-handleable-generic.d.ts +116 -0
- package/src/errors/translatable-handleable-generic.d.ts.map +1 -0
- package/src/errors/translatable-handleable-generic.js +121 -0
- package/src/errors/translatable-handleable-generic.js.map +1 -0
- package/src/errors/translatable.d.ts +63 -0
- package/src/errors/translatable.d.ts.map +1 -0
- package/src/errors/translatable.js +85 -0
- package/src/errors/translatable.js.map +1 -0
- package/src/errors/typed-handleable.d.ts +62 -0
- package/src/errors/typed-handleable.d.ts.map +1 -0
- package/src/errors/typed-handleable.js +108 -0
- package/src/errors/typed-handleable.js.map +1 -0
- package/src/errors/typed.d.ts +206 -0
- package/src/errors/typed.d.ts.map +1 -0
- package/src/errors/typed.js +458 -0
- package/src/errors/typed.js.map +1 -0
- package/src/gender/{gender-categories.ts → gender-categories.d.ts} +2 -6
- package/src/gender/gender-categories.d.ts.map +1 -0
- package/src/gender/gender-categories.js +15 -0
- package/src/gender/gender-categories.js.map +1 -0
- package/src/gender/gender-resolver.d.ts +14 -0
- package/src/gender/gender-resolver.d.ts.map +1 -0
- package/src/gender/gender-resolver.js +35 -0
- package/src/gender/gender-resolver.js.map +1 -0
- package/src/gender/{index.ts → index.d.ts} +1 -0
- package/src/gender/index.d.ts.map +1 -0
- package/src/gender/index.js +6 -0
- package/src/gender/index.js.map +1 -0
- package/src/global-active-context.d.ts +50 -0
- package/src/global-active-context.d.ts.map +1 -0
- package/src/global-active-context.js +185 -0
- package/src/global-active-context.js.map +1 -0
- package/src/icu/ast.d.ts +48 -0
- package/src/icu/ast.d.ts.map +1 -0
- package/src/icu/ast.js +16 -0
- package/src/icu/ast.js.map +1 -0
- package/src/icu/compiler.d.ts +16 -0
- package/src/icu/compiler.d.ts.map +1 -0
- package/src/icu/compiler.js +87 -0
- package/src/icu/compiler.js.map +1 -0
- package/src/icu/formatter-registry.d.ts +10 -0
- package/src/icu/formatter-registry.d.ts.map +1 -0
- package/src/icu/formatter-registry.js +34 -0
- package/src/icu/formatter-registry.js.map +1 -0
- package/src/icu/formatters/base-formatter.d.ts +8 -0
- package/src/icu/formatters/base-formatter.d.ts.map +1 -0
- package/src/icu/formatters/base-formatter.js +3 -0
- package/src/icu/formatters/base-formatter.js.map +1 -0
- package/src/icu/formatters/date-formatter.d.ts +5 -0
- package/src/icu/formatters/date-formatter.d.ts.map +1 -0
- package/src/icu/formatters/date-formatter.js +31 -0
- package/src/icu/formatters/date-formatter.js.map +1 -0
- package/src/icu/formatters/number-formatter.d.ts +5 -0
- package/src/icu/formatters/number-formatter.d.ts.map +1 -0
- package/src/icu/formatters/number-formatter.js +33 -0
- package/src/icu/formatters/number-formatter.js.map +1 -0
- package/src/icu/formatters/plural-formatter.d.ts +5 -0
- package/src/icu/formatters/plural-formatter.d.ts.map +1 -0
- package/src/icu/formatters/plural-formatter.js +15 -0
- package/src/icu/formatters/plural-formatter.js.map +1 -0
- package/src/icu/formatters/select-formatter.d.ts +5 -0
- package/src/icu/formatters/select-formatter.d.ts.map +1 -0
- package/src/icu/formatters/select-formatter.js +10 -0
- package/src/icu/formatters/select-formatter.js.map +1 -0
- package/src/icu/formatters/selectordinal-formatter.d.ts +5 -0
- package/src/icu/formatters/selectordinal-formatter.d.ts.map +1 -0
- package/src/icu/formatters/selectordinal-formatter.js +22 -0
- package/src/icu/formatters/selectordinal-formatter.js.map +1 -0
- package/src/icu/formatters/time-formatter.d.ts +5 -0
- package/src/icu/formatters/time-formatter.d.ts.map +1 -0
- package/src/icu/formatters/time-formatter.js +31 -0
- package/src/icu/formatters/time-formatter.js.map +1 -0
- package/src/icu/helpers.d.ts +9 -0
- package/src/icu/helpers.d.ts.map +1 -0
- package/src/icu/helpers.js +31 -0
- package/src/icu/helpers.js.map +1 -0
- package/src/icu/parser.d.ts +31 -0
- package/src/icu/parser.d.ts.map +1 -0
- package/src/icu/parser.js +203 -0
- package/src/icu/parser.js.map +1 -0
- package/src/icu/runtime.d.ts +10 -0
- package/src/icu/runtime.d.ts.map +1 -0
- package/src/icu/runtime.js +33 -0
- package/src/icu/runtime.js.map +1 -0
- package/src/icu/tokenizer.d.ts +37 -0
- package/src/icu/tokenizer.d.ts.map +1 -0
- package/src/icu/tokenizer.js +187 -0
- package/src/icu/tokenizer.js.map +1 -0
- package/src/icu/validator.d.ts +11 -0
- package/src/icu/validator.d.ts.map +1 -0
- package/src/icu/validator.js +140 -0
- package/src/icu/validator.js.map +1 -0
- package/src/{index.ts → index.d.ts} +6 -38
- package/src/index.d.ts.map +1 -0
- package/src/index.js +76 -0
- package/src/index.js.map +1 -0
- package/src/interfaces/active-context.interface.d.ts +36 -0
- package/src/interfaces/active-context.interface.d.ts.map +1 -0
- package/src/interfaces/active-context.interface.js +3 -0
- package/src/interfaces/active-context.interface.js.map +1 -0
- package/src/interfaces/component-config.interface.d.ts +16 -0
- package/src/interfaces/component-config.interface.d.ts.map +1 -0
- package/src/interfaces/component-config.interface.js +6 -0
- package/src/interfaces/component-config.interface.js.map +1 -0
- package/src/interfaces/engine-config.interface.d.ts +22 -0
- package/src/interfaces/engine-config.interface.d.ts.map +1 -0
- package/src/interfaces/engine-config.interface.js +6 -0
- package/src/interfaces/engine-config.interface.js.map +1 -0
- package/src/interfaces/global-active-context.d.ts +23 -0
- package/src/interfaces/global-active-context.d.ts.map +1 -0
- package/src/interfaces/global-active-context.js +3 -0
- package/src/interfaces/global-active-context.js.map +1 -0
- package/src/interfaces/handleable-error-options.d.ts +14 -0
- package/src/interfaces/handleable-error-options.d.ts.map +1 -0
- package/src/interfaces/handleable-error-options.js +3 -0
- package/src/interfaces/handleable-error-options.js.map +1 -0
- package/src/interfaces/handleable.d.ts +21 -0
- package/src/interfaces/handleable.d.ts.map +1 -0
- package/src/interfaces/handleable.js +3 -0
- package/src/interfaces/handleable.js.map +1 -0
- package/src/interfaces/i18n-engine.interface.d.ts +46 -0
- package/src/interfaces/i18n-engine.interface.d.ts.map +1 -0
- package/src/interfaces/i18n-engine.interface.js +6 -0
- package/src/interfaces/i18n-engine.interface.js.map +1 -0
- package/src/interfaces/{index.ts → index.d.ts} +1 -1
- package/src/interfaces/index.d.ts.map +1 -0
- package/src/interfaces/index.js +7 -0
- package/src/interfaces/index.js.map +1 -0
- package/src/interfaces/language-definition.interface.d.ts +17 -0
- package/src/interfaces/language-definition.interface.d.ts.map +1 -0
- package/src/interfaces/language-definition.interface.js +6 -0
- package/src/interfaces/language-definition.interface.js.map +1 -0
- package/src/interfaces/translation-options.interface.d.ts +15 -0
- package/src/interfaces/translation-options.interface.d.ts.map +1 -0
- package/src/interfaces/translation-options.interface.js +6 -0
- package/src/interfaces/translation-options.interface.js.map +1 -0
- package/src/interfaces/validation-result.interface.d.ts +24 -0
- package/src/interfaces/validation-result.interface.d.ts.map +1 -0
- package/src/interfaces/validation-result.interface.js +6 -0
- package/src/interfaces/validation-result.interface.js.map +1 -0
- package/src/language-codes.d.ts +28 -0
- package/src/language-codes.d.ts.map +1 -0
- package/src/language-codes.js +32 -0
- package/src/language-codes.js.map +1 -0
- package/src/language-definition.d.ts +14 -0
- package/src/language-definition.d.ts.map +1 -0
- package/src/language-definition.js +3 -0
- package/src/language-definition.js.map +1 -0
- package/src/plugin-i18n-engine.d.ts +164 -0
- package/src/plugin-i18n-engine.d.ts.map +1 -0
- package/src/plugin-i18n-engine.js +493 -0
- package/src/plugin-i18n-engine.js.map +1 -0
- package/src/pluralization/{index.ts → index.d.ts} +1 -1
- package/src/pluralization/index.d.ts.map +1 -0
- package/src/pluralization/index.js +10 -0
- package/src/pluralization/index.js.map +1 -0
- package/src/pluralization/language-plural-map.d.ts +29 -0
- package/src/pluralization/language-plural-map.d.ts.map +1 -0
- package/src/pluralization/language-plural-map.js +155 -0
- package/src/pluralization/language-plural-map.js.map +1 -0
- package/src/pluralization/{plural-categories.ts → plural-categories.d.ts} +3 -5
- package/src/pluralization/plural-categories.d.ts.map +1 -0
- package/src/pluralization/plural-categories.js +8 -0
- package/src/pluralization/plural-categories.js.map +1 -0
- package/src/pluralization/plural-rules.d.ts +102 -0
- package/src/pluralization/plural-rules.d.ts.map +1 -0
- package/src/pluralization/plural-rules.js +263 -0
- package/src/pluralization/plural-rules.js.map +1 -0
- package/src/registry-config.d.ts +16 -0
- package/src/registry-config.d.ts.map +1 -0
- package/src/registry-config.js +3 -0
- package/src/registry-config.js.map +1 -0
- package/src/registry-error-type.d.ts +20 -0
- package/src/registry-error-type.d.ts.map +1 -0
- package/src/registry-error-type.js +24 -0
- package/src/registry-error-type.js.map +1 -0
- package/src/registry-error.d.ts +25 -0
- package/src/registry-error.d.ts.map +1 -0
- package/src/registry-error.js +63 -0
- package/src/registry-error.js.map +1 -0
- package/src/strict-types.d.ts +19 -0
- package/src/strict-types.d.ts.map +1 -0
- package/src/strict-types.js +18 -0
- package/src/strict-types.js.map +1 -0
- package/src/strings/de.d.ts +3 -0
- package/src/strings/de.d.ts.map +1 -0
- package/src/strings/de.js +57 -0
- package/src/strings/de.js.map +1 -0
- package/src/strings/en-GB.d.ts +3 -0
- package/src/strings/en-GB.d.ts.map +1 -0
- package/src/strings/en-GB.js +57 -0
- package/src/strings/en-GB.js.map +1 -0
- package/src/strings/en-US.d.ts +3 -0
- package/src/strings/en-US.d.ts.map +1 -0
- package/src/strings/en-US.js +57 -0
- package/src/strings/en-US.js.map +1 -0
- package/src/strings/es.d.ts +3 -0
- package/src/strings/es.d.ts.map +1 -0
- package/src/strings/es.js +57 -0
- package/src/strings/es.js.map +1 -0
- package/src/strings/fr.d.ts +3 -0
- package/src/strings/fr.d.ts.map +1 -0
- package/src/strings/fr.js +57 -0
- package/src/strings/fr.js.map +1 -0
- package/src/strings/ja.d.ts +3 -0
- package/src/strings/ja.d.ts.map +1 -0
- package/src/strings/ja.js +57 -0
- package/src/strings/ja.js.map +1 -0
- package/src/strings/uk.d.ts +3 -0
- package/src/strings/uk.d.ts.map +1 -0
- package/src/strings/uk.js +57 -0
- package/src/strings/uk.js.map +1 -0
- package/src/strings/zh-CN.d.ts +3 -0
- package/src/strings/zh-CN.d.ts.map +1 -0
- package/src/strings/zh-CN.js +57 -0
- package/src/strings/zh-CN.js.map +1 -0
- package/src/template.d.ts +13 -0
- package/src/template.d.ts.map +1 -0
- package/src/template.js +40 -0
- package/src/template.js.map +1 -0
- package/src/translation-engine.d.ts +9 -0
- package/src/translation-engine.d.ts.map +1 -0
- package/src/translation-engine.js +3 -0
- package/src/translation-engine.js.map +1 -0
- package/src/translation-request.d.ts +10 -0
- package/src/translation-request.d.ts.map +1 -0
- package/src/translation-request.js +3 -0
- package/src/translation-request.js.map +1 -0
- package/src/translation-response.d.ts +9 -0
- package/src/translation-response.d.ts.map +1 -0
- package/src/translation-response.js +3 -0
- package/src/translation-response.js.map +1 -0
- package/src/types/engine.d.ts +47 -0
- package/src/types/engine.d.ts.map +1 -0
- package/src/types/engine.js +8 -0
- package/src/types/engine.js.map +1 -0
- package/src/types/{index.ts → index.d.ts} +1 -1
- package/src/types/index.d.ts.map +1 -0
- package/src/types/index.js +9 -0
- package/src/types/index.js.map +1 -0
- package/src/types/{plural-types.ts → plural-types.d.ts} +3 -29
- package/src/types/plural-types.d.ts.map +1 -0
- package/src/types/plural-types.js +39 -0
- package/src/types/plural-types.js.map +1 -0
- package/src/{types.ts → types.d.ts} +21 -72
- package/src/types.d.ts.map +1 -0
- package/src/types.js +23 -0
- package/src/types.js.map +1 -0
- package/src/utils/currency.d.ts +81 -0
- package/src/utils/currency.d.ts.map +1 -0
- package/src/utils/currency.js +99 -0
- package/src/utils/currency.js.map +1 -0
- package/src/utils/html-escape.d.ts +22 -0
- package/src/utils/html-escape.d.ts.map +1 -0
- package/src/utils/html-escape.js +53 -0
- package/src/utils/html-escape.js.map +1 -0
- package/src/utils/{index.ts → index.d.ts} +1 -0
- package/src/utils/index.d.ts.map +1 -0
- package/src/utils/index.js +12 -0
- package/src/utils/index.js.map +1 -0
- package/src/utils/lru-cache.d.ts +42 -0
- package/src/utils/lru-cache.d.ts.map +1 -0
- package/src/utils/lru-cache.js +73 -0
- package/src/utils/lru-cache.js.map +1 -0
- package/src/utils/{plural-helpers.ts → plural-helpers.d.ts} +4 -14
- package/src/utils/plural-helpers.d.ts.map +1 -0
- package/src/utils/plural-helpers.js +35 -0
- package/src/utils/plural-helpers.js.map +1 -0
- package/src/utils/safe-object.d.ts +39 -0
- package/src/utils/safe-object.d.ts.map +1 -0
- package/src/utils/{safe-object.ts → safe-object.js} +34 -37
- package/src/utils/safe-object.js.map +1 -0
- package/src/utils/string-utils.d.ts +28 -0
- package/src/utils/string-utils.d.ts.map +1 -0
- package/src/utils/string-utils.js +63 -0
- package/src/utils/string-utils.js.map +1 -0
- package/src/utils/timezone.d.ts +50 -0
- package/src/utils/timezone.d.ts.map +1 -0
- package/src/utils/timezone.js +74 -0
- package/src/utils/timezone.js.map +1 -0
- package/src/utils/validation.d.ts +40 -0
- package/src/utils/validation.d.ts.map +1 -0
- package/src/utils/validation.js +69 -0
- package/src/utils/validation.js.map +1 -0
- package/src/utils.d.ts +65 -0
- package/src/utils.d.ts.map +1 -0
- package/src/utils.js +129 -0
- package/src/utils.js.map +1 -0
- package/src/validation/{index.ts → index.d.ts} +1 -0
- package/src/validation/index.d.ts.map +1 -0
- package/src/validation/index.js +5 -0
- package/src/validation/index.js.map +1 -0
- package/src/validation/plural-validator.d.ts +46 -0
- package/src/validation/plural-validator.d.ts.map +1 -0
- package/src/validation/plural-validator.js +123 -0
- package/src/validation/plural-validator.js.map +1 -0
- package/src/validation-config.d.ts +12 -0
- package/src/validation-config.d.ts.map +1 -0
- package/src/validation-config.js +3 -0
- package/src/validation-config.js.map +1 -0
- package/src/validation-result.d.ts +13 -0
- package/src/validation-result.d.ts.map +1 -0
- package/src/validation-result.js +3 -0
- package/src/validation-result.js.map +1 -0
- package/LICENSE +0 -21
- package/src/builders/i18n-builder.ts +0 -82
- package/src/component-definition.ts +0 -11
- package/src/component-registration.ts +0 -29
- package/src/component-registry.ts +0 -432
- package/src/context-error-type.ts +0 -7
- package/src/core/component-store.ts +0 -241
- package/src/core/context-manager.ts +0 -113
- package/src/core/enum-registry.ts +0 -106
- package/src/core/i18n-engine.ts +0 -710
- package/src/core/language-registry.ts +0 -345
- package/src/core-i18n.ts +0 -270
- package/src/core-plugin-factory.ts +0 -111
- package/src/core-string-key.ts +0 -59
- package/src/create-translation-adapter.ts +0 -93
- package/src/enum-registry.ts +0 -152
- package/src/errors/context-error.ts +0 -122
- package/src/errors/enhanced-error-base.ts +0 -260
- package/src/errors/handleable.ts +0 -152
- package/src/errors/i18n-error.ts +0 -494
- package/src/errors/simple-typed-error.ts +0 -81
- package/src/errors/translatable-generic.ts +0 -245
- package/src/errors/translatable-handleable-generic.ts +0 -222
- package/src/errors/translatable.ts +0 -138
- package/src/errors/typed-handleable.ts +0 -138
- package/src/errors/typed.ts +0 -617
- package/src/gender/gender-resolver.ts +0 -40
- package/src/global-active-context.ts +0 -266
- package/src/icu/ast.ts +0 -56
- package/src/icu/compiler.ts +0 -96
- package/src/icu/formatter-registry.ts +0 -36
- package/src/icu/formatters/base-formatter.ts +0 -8
- package/src/icu/formatters/date-formatter.ts +0 -30
- package/src/icu/formatters/number-formatter.ts +0 -32
- package/src/icu/formatters/plural-formatter.ts +0 -12
- package/src/icu/formatters/select-formatter.ts +0 -7
- package/src/icu/formatters/selectordinal-formatter.ts +0 -17
- package/src/icu/formatters/time-formatter.ts +0 -30
- package/src/icu/helpers.ts +0 -34
- package/src/icu/parser.ts +0 -242
- package/src/icu/runtime.ts +0 -37
- package/src/icu/tokenizer.ts +0 -212
- package/src/icu/validator.ts +0 -163
- package/src/interfaces/active-context.interface.ts +0 -41
- package/src/interfaces/component-config.interface.ts +0 -17
- package/src/interfaces/engine-config.interface.ts +0 -22
- package/src/interfaces/global-active-context.ts +0 -39
- package/src/interfaces/handleable-error-options.ts +0 -13
- package/src/interfaces/handleable.ts +0 -20
- package/src/interfaces/i18n-engine.interface.ts +0 -57
- package/src/interfaces/language-definition.interface.ts +0 -17
- package/src/interfaces/translation-options.interface.ts +0 -15
- package/src/interfaces/validation-result.interface.ts +0 -24
- package/src/language-codes.ts +0 -40
- package/src/language-definition.ts +0 -13
- package/src/plugin-i18n-engine.ts +0 -707
- package/src/pluralization/language-plural-map.ts +0 -186
- package/src/pluralization/plural-rules.ts +0 -228
- package/src/registry-config.ts +0 -16
- package/src/registry-error-type.ts +0 -19
- package/src/registry-error.ts +0 -100
- package/src/strict-types.ts +0 -35
- package/src/strings/de.ts +0 -75
- package/src/strings/en-GB.ts +0 -74
- package/src/strings/en-US.ts +0 -74
- package/src/strings/es.ts +0 -74
- package/src/strings/fr.ts +0 -75
- package/src/strings/ja.ts +0 -73
- package/src/strings/uk.ts +0 -73
- package/src/strings/zh-CN.ts +0 -72
- package/src/template.ts +0 -72
- package/src/translation-engine.ts +0 -18
- package/src/translation-request.ts +0 -12
- package/src/translation-response.ts +0 -8
- package/src/types/engine.ts +0 -55
- package/src/utils/currency.ts +0 -141
- package/src/utils/html-escape.ts +0 -55
- package/src/utils/lru-cache.ts +0 -76
- package/src/utils/string-utils.ts +0 -77
- package/src/utils/timezone.ts +0 -76
- package/src/utils/validation.ts +0 -66
- package/src/utils.ts +0 -215
- package/src/validation/plural-validator.ts +0 -168
- package/src/validation-config.ts +0 -11
- package/src/validation-result.ts +0 -12
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import { ContextErrorType } from './context-error-type';
|
|
2
|
-
import { ContextError } from './errors/context-error';
|
|
3
|
-
import type { IActiveContext } from './interfaces/active-context.interface';
|
|
4
|
-
import type { IGlobalActiveContext } from './interfaces/global-active-context';
|
|
5
|
-
import {
|
|
6
|
-
DefaultCurrencyCode,
|
|
7
|
-
DefaultTimezone,
|
|
8
|
-
LanguageContextSpace,
|
|
9
|
-
} from './types';
|
|
10
|
-
import { CurrencyCode } from './utils/currency';
|
|
11
|
-
import { Timezone } from './utils/timezone';
|
|
12
|
-
|
|
13
|
-
export class GlobalActiveContext<
|
|
14
|
-
TLanguage extends string,
|
|
15
|
-
TActiveContext extends IActiveContext<TLanguage>,
|
|
16
|
-
> implements IGlobalActiveContext<TLanguage, TActiveContext>
|
|
17
|
-
{
|
|
18
|
-
protected static _contextMap: Map<string, IActiveContext<any>> = new Map();
|
|
19
|
-
public static readonly defaultContextKey = 'default';
|
|
20
|
-
public static readonly defaultLanguage: string = 'en-US';
|
|
21
|
-
|
|
22
|
-
private static _instance: GlobalActiveContext<any, any> | undefined;
|
|
23
|
-
public static get instance(): GlobalActiveContext<any, any> {
|
|
24
|
-
if (!this._instance) {
|
|
25
|
-
this._instance = new GlobalActiveContext<any, any>();
|
|
26
|
-
this._instance.createContext(this.defaultLanguage);
|
|
27
|
-
}
|
|
28
|
-
return this._instance;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Register in globalThis for cross-module access
|
|
32
|
-
static {
|
|
33
|
-
if (typeof globalThis !== 'undefined') {
|
|
34
|
-
globalThis.GlobalActiveContext = GlobalActiveContext;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
public static getInstance<
|
|
38
|
-
TLanguage extends string,
|
|
39
|
-
TActiveContext extends IActiveContext<TLanguage>,
|
|
40
|
-
>(): GlobalActiveContext<TLanguage, TActiveContext> {
|
|
41
|
-
if (!this._instance) {
|
|
42
|
-
this._instance = new GlobalActiveContext<TLanguage, TActiveContext>();
|
|
43
|
-
this._instance.createContext(this.defaultLanguage);
|
|
44
|
-
}
|
|
45
|
-
return this._instance as GlobalActiveContext<TLanguage, TActiveContext>;
|
|
46
|
-
}
|
|
47
|
-
public static overrideInstance(
|
|
48
|
-
instance: GlobalActiveContext<any, any>,
|
|
49
|
-
): void {
|
|
50
|
-
this._instance = instance;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public createContext(
|
|
54
|
-
defaultLanguage: TLanguage,
|
|
55
|
-
defaultAdminLanguage: TLanguage = defaultLanguage,
|
|
56
|
-
key: string = GlobalActiveContext.defaultContextKey,
|
|
57
|
-
): TActiveContext {
|
|
58
|
-
const newContext: IActiveContext<TLanguage> = {
|
|
59
|
-
/**
|
|
60
|
-
* The language to use for translations in the user facing ui
|
|
61
|
-
*/
|
|
62
|
-
language: defaultLanguage,
|
|
63
|
-
/**
|
|
64
|
-
* The language to use for console/admin logs
|
|
65
|
-
*/
|
|
66
|
-
adminLanguage: defaultAdminLanguage,
|
|
67
|
-
currencyCode: new CurrencyCode(DefaultCurrencyCode),
|
|
68
|
-
/**
|
|
69
|
-
* The current default context for language translations
|
|
70
|
-
*/
|
|
71
|
-
currentContext: 'user',
|
|
72
|
-
/**
|
|
73
|
-
* The timezone for the user facing UI
|
|
74
|
-
*/
|
|
75
|
-
timezone: new Timezone(DefaultTimezone),
|
|
76
|
-
/**
|
|
77
|
-
* The timezone for the admin console
|
|
78
|
-
*/
|
|
79
|
-
adminTimezone: new Timezone('UTC'),
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
GlobalActiveContext._contextMap.set(key, newContext);
|
|
83
|
-
return newContext as TActiveContext;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public getContext(
|
|
87
|
-
key: string = GlobalActiveContext.defaultContextKey,
|
|
88
|
-
): TActiveContext {
|
|
89
|
-
const context = GlobalActiveContext._contextMap.get(key) as TActiveContext;
|
|
90
|
-
if (context) {
|
|
91
|
-
return context;
|
|
92
|
-
}
|
|
93
|
-
throw new ContextError(ContextErrorType.InvalidContext, key);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public get context(): TActiveContext {
|
|
97
|
-
return this.getContext(GlobalActiveContext.defaultContextKey);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public set context(ctx: TActiveContext) {
|
|
101
|
-
GlobalActiveContext._contextMap.set(
|
|
102
|
-
GlobalActiveContext.defaultContextKey,
|
|
103
|
-
ctx,
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public setUserLanguage(
|
|
108
|
-
language: TLanguage,
|
|
109
|
-
key: string = GlobalActiveContext.defaultContextKey,
|
|
110
|
-
): void {
|
|
111
|
-
const context = GlobalActiveContext._contextMap.get(
|
|
112
|
-
key,
|
|
113
|
-
) as IActiveContext<TLanguage>;
|
|
114
|
-
if (context) {
|
|
115
|
-
context.language = language;
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
throw new ContextError(ContextErrorType.InvalidContext, key);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public get userLanguage(): TLanguage {
|
|
122
|
-
return this.context.language;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public set userLanguage(lang: TLanguage) {
|
|
126
|
-
this.context.language = lang;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public setCurrencyCode(
|
|
130
|
-
code: CurrencyCode,
|
|
131
|
-
key: string = GlobalActiveContext.defaultContextKey,
|
|
132
|
-
): void {
|
|
133
|
-
const context = GlobalActiveContext._contextMap.get(
|
|
134
|
-
key,
|
|
135
|
-
) as IActiveContext<TLanguage>;
|
|
136
|
-
if (context) {
|
|
137
|
-
context.currencyCode = code;
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
throw new ContextError(ContextErrorType.InvalidContext, key);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
public get currencyCode(): CurrencyCode {
|
|
144
|
-
return this.context.currencyCode;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
public set currencyCode(code: CurrencyCode) {
|
|
148
|
-
this.context.currencyCode = code;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Sets the admin language for console operations
|
|
153
|
-
* @param language The language to set for admin operations
|
|
154
|
-
*/
|
|
155
|
-
public setAdminLanguage(
|
|
156
|
-
language: TLanguage,
|
|
157
|
-
key: string = GlobalActiveContext.defaultContextKey,
|
|
158
|
-
): void {
|
|
159
|
-
const context = GlobalActiveContext._contextMap.get(
|
|
160
|
-
key,
|
|
161
|
-
) as IActiveContext<TLanguage>;
|
|
162
|
-
if (context) {
|
|
163
|
-
context.adminLanguage = language;
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
throw new ContextError(ContextErrorType.InvalidContext, key);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public get adminLanguage(): TLanguage {
|
|
170
|
-
return this.context.adminLanguage;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
public set adminLanguage(lang: TLanguage) {
|
|
174
|
-
this.context.adminLanguage = lang;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Sets the language context for the current context
|
|
179
|
-
* @param context The language context to set
|
|
180
|
-
*/
|
|
181
|
-
public setLanguageContextSpace(
|
|
182
|
-
context: LanguageContextSpace,
|
|
183
|
-
key: string = GlobalActiveContext.defaultContextKey,
|
|
184
|
-
): void {
|
|
185
|
-
const ctx = GlobalActiveContext._contextMap.get(
|
|
186
|
-
key,
|
|
187
|
-
) as IActiveContext<TLanguage>;
|
|
188
|
-
if (ctx) {
|
|
189
|
-
ctx.currentContext = context;
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
throw new ContextError(ContextErrorType.InvalidContext, key);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
public getLanguageContextSpace(
|
|
196
|
-
key: string = GlobalActiveContext.defaultContextKey,
|
|
197
|
-
): LanguageContextSpace {
|
|
198
|
-
const ctx = GlobalActiveContext._contextMap.get(
|
|
199
|
-
key,
|
|
200
|
-
) as IActiveContext<TLanguage>;
|
|
201
|
-
if (ctx) {
|
|
202
|
-
return ctx.currentContext;
|
|
203
|
-
}
|
|
204
|
-
throw new ContextError(ContextErrorType.InvalidContext, key);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
public get languageContextSpace(): LanguageContextSpace {
|
|
208
|
-
return this.context.currentContext;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public set languageContextSpace(context: LanguageContextSpace) {
|
|
212
|
-
this.context.currentContext = context;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
public setUserTimezone(
|
|
216
|
-
tz: Timezone,
|
|
217
|
-
key: string = GlobalActiveContext.defaultContextKey,
|
|
218
|
-
): void {
|
|
219
|
-
const ctx = GlobalActiveContext._contextMap.get(
|
|
220
|
-
key,
|
|
221
|
-
) as IActiveContext<TLanguage>;
|
|
222
|
-
if (ctx) {
|
|
223
|
-
ctx.timezone = tz;
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
throw new ContextError(ContextErrorType.InvalidContext, key);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
public get userTimezone(): Timezone {
|
|
230
|
-
return this.context.timezone;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
public set userTimezone(tz: Timezone) {
|
|
234
|
-
this.context.timezone = tz;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
public setAdminTimezone(
|
|
238
|
-
tz: Timezone,
|
|
239
|
-
key: string = GlobalActiveContext.defaultContextKey,
|
|
240
|
-
): void {
|
|
241
|
-
const ctx = GlobalActiveContext._contextMap.get(
|
|
242
|
-
key,
|
|
243
|
-
) as IActiveContext<TLanguage>;
|
|
244
|
-
if (ctx) {
|
|
245
|
-
ctx.adminTimezone = tz;
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
throw new ContextError(ContextErrorType.InvalidContext, key);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
public get adminTimezone(): Timezone {
|
|
252
|
-
return this.context.adminTimezone;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
public set adminTimezone(tz: Timezone) {
|
|
256
|
-
this.context.adminTimezone = tz;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Clear all contexts (useful for testing)
|
|
261
|
-
*/
|
|
262
|
-
public static clearAll(): void {
|
|
263
|
-
GlobalActiveContext._contextMap.clear();
|
|
264
|
-
GlobalActiveContext._instance = undefined;
|
|
265
|
-
}
|
|
266
|
-
}
|
package/src/icu/ast.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ICU MessageFormat Abstract Syntax Tree (AST) types
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export enum NodeType {
|
|
6
|
-
MESSAGE = 'MESSAGE',
|
|
7
|
-
LITERAL = 'LITERAL',
|
|
8
|
-
ARGUMENT = 'ARGUMENT',
|
|
9
|
-
PLURAL = 'PLURAL',
|
|
10
|
-
SELECT = 'SELECT',
|
|
11
|
-
SELECTORDINAL = 'SELECTORDINAL',
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface BaseNode {
|
|
15
|
-
type: NodeType;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface MessageNode extends BaseNode {
|
|
19
|
-
type: NodeType.MESSAGE;
|
|
20
|
-
elements: Array<LiteralNode | ArgumentNode | PluralNode | SelectNode | SelectOrdinalNode>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface LiteralNode extends BaseNode {
|
|
24
|
-
type: NodeType.LITERAL;
|
|
25
|
-
value: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface ArgumentNode extends BaseNode {
|
|
29
|
-
type: NodeType.ARGUMENT;
|
|
30
|
-
name: string;
|
|
31
|
-
format?: string;
|
|
32
|
-
style?: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface PluralNode extends BaseNode {
|
|
36
|
-
type: NodeType.PLURAL;
|
|
37
|
-
name: string;
|
|
38
|
-
offset?: number;
|
|
39
|
-
cases: Record<string, MessageNode>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface SelectNode extends BaseNode {
|
|
43
|
-
type: NodeType.SELECT;
|
|
44
|
-
name: string;
|
|
45
|
-
cases: Record<string, MessageNode>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface SelectOrdinalNode extends BaseNode {
|
|
49
|
-
type: NodeType.SELECTORDINAL;
|
|
50
|
-
name: string;
|
|
51
|
-
offset?: number;
|
|
52
|
-
cases: Record<string, MessageNode>;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export type ASTNode = LiteralNode | ArgumentNode | PluralNode | SelectNode | SelectOrdinalNode;
|
|
56
|
-
export type ASTNodeOrMessage = MessageNode | ASTNode;
|
package/src/icu/compiler.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { MessageNode, NodeType, LiteralNode, ArgumentNode, PluralNode, SelectNode, SelectOrdinalNode } from './ast';
|
|
2
|
-
import { FormatterRegistry } from './formatter-registry';
|
|
3
|
-
import { FormatterContext } from './formatters/base-formatter';
|
|
4
|
-
|
|
5
|
-
export type CompiledMessage = (values: Record<string, any>, context: FormatterContext) => string;
|
|
6
|
-
|
|
7
|
-
export class Compiler {
|
|
8
|
-
private registry: FormatterRegistry;
|
|
9
|
-
|
|
10
|
-
constructor(registry?: FormatterRegistry) {
|
|
11
|
-
this.registry = registry || new FormatterRegistry();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
compile(ast: MessageNode): CompiledMessage {
|
|
15
|
-
return (values: Record<string, any>, context: FormatterContext) => {
|
|
16
|
-
return this.compileMessage(ast, values, context);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private compileMessage(node: MessageNode, values: Record<string, any>, context: FormatterContext): string {
|
|
21
|
-
return node.elements.map(el => this.compileNode(el, values, context)).join('');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private compileNode(node: any, values: Record<string, any>, context: FormatterContext): string {
|
|
25
|
-
switch (node.type) {
|
|
26
|
-
case NodeType.LITERAL:
|
|
27
|
-
return (node as LiteralNode).value;
|
|
28
|
-
case NodeType.ARGUMENT:
|
|
29
|
-
return this.compileArgument(node as ArgumentNode, values, context);
|
|
30
|
-
case NodeType.PLURAL:
|
|
31
|
-
return this.compilePlural(node as PluralNode, values, context);
|
|
32
|
-
case NodeType.SELECT:
|
|
33
|
-
return this.compileSelect(node as SelectNode, values, context);
|
|
34
|
-
case NodeType.SELECTORDINAL:
|
|
35
|
-
return this.compileSelectOrdinal(node as SelectOrdinalNode, values, context);
|
|
36
|
-
default:
|
|
37
|
-
return '';
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private compileArgument(node: ArgumentNode, values: Record<string, any>, context: FormatterContext): string {
|
|
42
|
-
const value = values[node.name];
|
|
43
|
-
if (value === undefined) return `{${node.name}}`;
|
|
44
|
-
|
|
45
|
-
if (!node.format) return String(value);
|
|
46
|
-
|
|
47
|
-
const formatter = this.registry.get(node.format);
|
|
48
|
-
if (!formatter) return String(value);
|
|
49
|
-
|
|
50
|
-
return formatter.format(value, node.style, context);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private compilePlural(node: PluralNode, values: Record<string, any>, context: FormatterContext): string {
|
|
54
|
-
const value = values[node.name];
|
|
55
|
-
const num = Number(value);
|
|
56
|
-
if (isNaN(num)) return this.compileMessage(node.cases.other || node.cases.one, values, context);
|
|
57
|
-
|
|
58
|
-
const formatter = this.registry.get('plural');
|
|
59
|
-
const category = formatter ? formatter.format(num, undefined, context) : 'other';
|
|
60
|
-
const caseNode = node.cases[category] || node.cases.other;
|
|
61
|
-
|
|
62
|
-
if (!caseNode) return '';
|
|
63
|
-
|
|
64
|
-
const result = this.compileMessage(caseNode, values, context);
|
|
65
|
-
// Format number with thousand separators using Intl.NumberFormat
|
|
66
|
-
const locale = context.locale || 'en-US';
|
|
67
|
-
const formattedNum = new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(num);
|
|
68
|
-
return result.replace(/#/g, formattedNum);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private compileSelect(node: SelectNode, values: Record<string, any>, context: FormatterContext): string {
|
|
72
|
-
const value = String(values[node.name] || '');
|
|
73
|
-
const caseNode = node.cases[value] || node.cases.other;
|
|
74
|
-
|
|
75
|
-
if (!caseNode) return '';
|
|
76
|
-
return this.compileMessage(caseNode, values, context);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private compileSelectOrdinal(node: SelectOrdinalNode, values: Record<string, any>, context: FormatterContext): string {
|
|
80
|
-
const value = values[node.name];
|
|
81
|
-
const num = Number(value);
|
|
82
|
-
if (isNaN(num)) return this.compileMessage(node.cases.other, values, context);
|
|
83
|
-
|
|
84
|
-
const formatter = this.registry.get('selectordinal');
|
|
85
|
-
const category = formatter ? formatter.format(num, undefined, context) : 'other';
|
|
86
|
-
const caseNode = node.cases[category] || node.cases.other;
|
|
87
|
-
|
|
88
|
-
if (!caseNode) return '';
|
|
89
|
-
|
|
90
|
-
const result = this.compileMessage(caseNode, values, context);
|
|
91
|
-
// Format number with thousand separators using Intl.NumberFormat
|
|
92
|
-
const locale = context.locale || 'en-US';
|
|
93
|
-
const formattedNum = new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(num);
|
|
94
|
-
return result.replace(/#/g, formattedNum);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Formatter } from './formatters/base-formatter';
|
|
2
|
-
import { NumberFormatter } from './formatters/number-formatter';
|
|
3
|
-
import { DateFormatter } from './formatters/date-formatter';
|
|
4
|
-
import { TimeFormatter } from './formatters/time-formatter';
|
|
5
|
-
import { PluralFormatter } from './formatters/plural-formatter';
|
|
6
|
-
import { SelectFormatter } from './formatters/select-formatter';
|
|
7
|
-
import { SelectOrdinalFormatter } from './formatters/selectordinal-formatter';
|
|
8
|
-
|
|
9
|
-
export class FormatterRegistry {
|
|
10
|
-
private formatters = new Map<string, Formatter>();
|
|
11
|
-
|
|
12
|
-
constructor() {
|
|
13
|
-
this.registerDefaults();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
private registerDefaults(): void {
|
|
17
|
-
this.register('number', new NumberFormatter());
|
|
18
|
-
this.register('date', new DateFormatter());
|
|
19
|
-
this.register('time', new TimeFormatter());
|
|
20
|
-
this.register('plural', new PluralFormatter());
|
|
21
|
-
this.register('select', new SelectFormatter());
|
|
22
|
-
this.register('selectordinal', new SelectOrdinalFormatter());
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
register(type: string, formatter: Formatter): void {
|
|
26
|
-
this.formatters.set(type, formatter);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get(type: string): Formatter | undefined {
|
|
30
|
-
return this.formatters.get(type);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
has(type: string): boolean {
|
|
34
|
-
return this.formatters.has(type);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Formatter, FormatterContext } from './base-formatter';
|
|
2
|
-
|
|
3
|
-
export class DateFormatter implements Formatter {
|
|
4
|
-
format(value: any, style?: string, context?: FormatterContext): string {
|
|
5
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
6
|
-
if (isNaN(date.getTime())) return String(value);
|
|
7
|
-
|
|
8
|
-
const locale = context?.locale || 'en-US';
|
|
9
|
-
const options: Intl.DateTimeFormatOptions = {};
|
|
10
|
-
|
|
11
|
-
switch (style) {
|
|
12
|
-
case 'short':
|
|
13
|
-
options.dateStyle = 'short';
|
|
14
|
-
break;
|
|
15
|
-
case 'medium':
|
|
16
|
-
options.dateStyle = 'medium';
|
|
17
|
-
break;
|
|
18
|
-
case 'long':
|
|
19
|
-
options.dateStyle = 'long';
|
|
20
|
-
break;
|
|
21
|
-
case 'full':
|
|
22
|
-
options.dateStyle = 'full';
|
|
23
|
-
break;
|
|
24
|
-
default:
|
|
25
|
-
options.dateStyle = 'medium';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return new Intl.DateTimeFormat(locale, options).format(date);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Formatter, FormatterContext } from './base-formatter';
|
|
2
|
-
|
|
3
|
-
export class NumberFormatter implements Formatter {
|
|
4
|
-
format(value: any, style?: string, context?: FormatterContext): string {
|
|
5
|
-
const num = Number(value);
|
|
6
|
-
if (isNaN(num)) return String(value);
|
|
7
|
-
|
|
8
|
-
const locale = context?.locale || 'en-US';
|
|
9
|
-
const options: Intl.NumberFormatOptions = {};
|
|
10
|
-
|
|
11
|
-
switch (style) {
|
|
12
|
-
case 'integer':
|
|
13
|
-
options.maximumFractionDigits = 0;
|
|
14
|
-
break;
|
|
15
|
-
case 'currency':
|
|
16
|
-
options.style = 'currency';
|
|
17
|
-
options.currency = context?.currency || 'USD';
|
|
18
|
-
break;
|
|
19
|
-
case 'percent':
|
|
20
|
-
options.style = 'percent';
|
|
21
|
-
// Show up to 2 decimal places for percent, but don't force trailing zeros
|
|
22
|
-
options.minimumFractionDigits = 0;
|
|
23
|
-
options.maximumFractionDigits = 2;
|
|
24
|
-
break;
|
|
25
|
-
case 'decimal':
|
|
26
|
-
default:
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return new Intl.NumberFormat(locale, options).format(num);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Formatter, FormatterContext } from './base-formatter';
|
|
2
|
-
import { getPluralCategory } from '../../pluralization/language-plural-map';
|
|
3
|
-
|
|
4
|
-
export class PluralFormatter implements Formatter {
|
|
5
|
-
format(value: any, style?: string, context?: FormatterContext): string {
|
|
6
|
-
const num = Number(value);
|
|
7
|
-
if (isNaN(num)) return 'other';
|
|
8
|
-
|
|
9
|
-
const locale = context?.locale || 'en-US';
|
|
10
|
-
return getPluralCategory(locale, num);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Formatter, FormatterContext } from './base-formatter';
|
|
2
|
-
|
|
3
|
-
export class SelectOrdinalFormatter implements Formatter {
|
|
4
|
-
format(value: any, style?: string, context?: FormatterContext): string {
|
|
5
|
-
const num = Number(value);
|
|
6
|
-
if (isNaN(num)) return 'other';
|
|
7
|
-
|
|
8
|
-
// English ordinal rules (1st, 2nd, 3rd, 4th, etc.)
|
|
9
|
-
const mod10 = num % 10;
|
|
10
|
-
const mod100 = num % 100;
|
|
11
|
-
|
|
12
|
-
if (mod10 === 1 && mod100 !== 11) return 'one';
|
|
13
|
-
if (mod10 === 2 && mod100 !== 12) return 'two';
|
|
14
|
-
if (mod10 === 3 && mod100 !== 13) return 'few';
|
|
15
|
-
return 'other';
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Formatter, FormatterContext } from './base-formatter';
|
|
2
|
-
|
|
3
|
-
export class TimeFormatter implements Formatter {
|
|
4
|
-
format(value: any, style?: string, context?: FormatterContext): string {
|
|
5
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
6
|
-
if (isNaN(date.getTime())) return String(value);
|
|
7
|
-
|
|
8
|
-
const locale = context?.locale || 'en-US';
|
|
9
|
-
const options: Intl.DateTimeFormatOptions = {};
|
|
10
|
-
|
|
11
|
-
switch (style) {
|
|
12
|
-
case 'short':
|
|
13
|
-
options.timeStyle = 'short';
|
|
14
|
-
break;
|
|
15
|
-
case 'medium':
|
|
16
|
-
options.timeStyle = 'medium';
|
|
17
|
-
break;
|
|
18
|
-
case 'long':
|
|
19
|
-
options.timeStyle = 'long';
|
|
20
|
-
break;
|
|
21
|
-
case 'full':
|
|
22
|
-
options.timeStyle = 'full';
|
|
23
|
-
break;
|
|
24
|
-
default:
|
|
25
|
-
options.timeStyle = 'medium';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return new Intl.DateTimeFormat(locale, options).format(date);
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/icu/helpers.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { parse } from './parser';
|
|
2
|
-
import { validate, ValidationOptions } from './validator';
|
|
3
|
-
import { Compiler } from './compiler';
|
|
4
|
-
import { Runtime } from './runtime';
|
|
5
|
-
import { MessageNode } from './ast';
|
|
6
|
-
|
|
7
|
-
const defaultRuntime = new Runtime();
|
|
8
|
-
|
|
9
|
-
export function isICUMessage(message: string): boolean {
|
|
10
|
-
return /\{[^}]{1,100}\}/.test(message);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function parseICUMessage(message: string): MessageNode {
|
|
14
|
-
return parse(message);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function compileICUMessage(message: string): ReturnType<Compiler['compile']> {
|
|
18
|
-
const ast = parse(message);
|
|
19
|
-
const compiler = new Compiler();
|
|
20
|
-
return compiler.compile(ast);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function formatICUMessage(
|
|
24
|
-
message: string,
|
|
25
|
-
values: Record<string, any>,
|
|
26
|
-
locale: string = 'en-US'
|
|
27
|
-
): string {
|
|
28
|
-
return defaultRuntime.format(message, values, { locale });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function validateICUMessage(message: string, options?: ValidationOptions): void {
|
|
32
|
-
const ast = parse(message);
|
|
33
|
-
validate(ast, options);
|
|
34
|
-
}
|