@italia/i18n 1.0.0-alpha.9 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -60
- package/custom-elements.json +0 -0
- package/dist/src/controllers/localize.d.ts +0 -0
- package/dist/src/controllers/localize.d.ts.map +1 -1
- package/dist/src/index.d.ts +0 -0
- package/dist/src/index.d.ts.map +0 -0
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/mixins/localization.d.ts +0 -0
- package/dist/src/mixins/localization.d.ts.map +0 -0
- package/package.json +20 -20
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@italia/i18n`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This zero-dependency micro-library provides a lightweight Reactive Controller for sharing and applying translations within custom elements. It is not intended to replace full-featured i18n tools such as i18next.
|
|
4
|
+
|
|
5
|
+
It is the foundation of Web Components that need translations in [`@italia/dev-kit-italia`](https://italia.github.io/dev-kit-italia).
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -37,7 +39,7 @@ Majority of use cases appear to favor a single language per page. However, multi
|
|
|
37
39
|
$name: 'Italiano',
|
|
38
40
|
$dir: 'ltr',
|
|
39
41
|
|
|
40
|
-
//
|
|
42
|
+
// your translations
|
|
41
43
|
video_consent_accept: 'Accetto i cookie',
|
|
42
44
|
},
|
|
43
45
|
{
|
|
@@ -45,7 +47,7 @@ Majority of use cases appear to favor a single language per page. However, multi
|
|
|
45
47
|
$name: 'English',
|
|
46
48
|
$dir: 'ltr',
|
|
47
49
|
|
|
48
|
-
//
|
|
50
|
+
// your translations
|
|
49
51
|
video_consent_accept: 'Accept',
|
|
50
52
|
},
|
|
51
53
|
);
|
|
@@ -199,59 +201,3 @@ Now you can import `MyLocalizeController` and get strongly typed translations wh
|
|
|
199
201
|
- Intuitive API for custom element authors
|
|
200
202
|
- Consumers only need to load the translations they want and set the `lang` attribute
|
|
201
203
|
- Translations can be loaded up front or on demand
|
|
202
|
-
|
|
203
|
-
## Linting and formatting
|
|
204
|
-
|
|
205
|
-
To scan the project for linting and formatting errors, run
|
|
206
|
-
|
|
207
|
-
```bash
|
|
208
|
-
npm run lint
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
To automatically fix linting and formatting errors, run
|
|
212
|
-
|
|
213
|
-
```bash
|
|
214
|
-
npm run format
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
## Testing with Web Test Runner
|
|
218
|
-
|
|
219
|
-
To execute a single test run:
|
|
220
|
-
|
|
221
|
-
```bash
|
|
222
|
-
npm run test
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
To run the tests in interactive watch mode run:
|
|
226
|
-
|
|
227
|
-
```bash
|
|
228
|
-
npm run test:watch
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
## Demoing with Storybook
|
|
232
|
-
|
|
233
|
-
To run a local instance of Storybook for your component, run
|
|
234
|
-
|
|
235
|
-
```bash
|
|
236
|
-
npm run storybook
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
To build a production version of Storybook, run
|
|
240
|
-
|
|
241
|
-
```bash
|
|
242
|
-
npm run storybook:build
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
## Tooling configs
|
|
246
|
-
|
|
247
|
-
For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
|
|
248
|
-
|
|
249
|
-
If you customize the configuration a lot, you can consider moving them to individual files.
|
|
250
|
-
|
|
251
|
-
## Local Demo with `web-dev-server`
|
|
252
|
-
|
|
253
|
-
```bash
|
|
254
|
-
npm start
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
To run a local development server that serves the basic demo located in `demo/index.html`
|
package/custom-elements.json
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localize.d.ts","sourceRoot":"","sources":["../../../src/controllers/localize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAElF,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;AAEhF,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC;CACrB;AAED,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,OAAO,CAAC;CAC1B;AAID,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;KACzC;CACF;AAuBD,kEAAkE;AAClE,wBAAgB,MAAM,SAYrB;AAcD,yCAAyC;AACzC,wBAAgB,mBAAmB,CAAC,GAAG,WAAW,EAAE,WAAW,EAAE,QAkBhE;AACD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,mBAAmB,EAAE,OAAO,mBAAmB,CAAC;KACjD;CACF;
|
|
1
|
+
{"version":3,"file":"localize.d.ts","sourceRoot":"","sources":["../../../src/controllers/localize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAElF,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;AAEhF,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,K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AAC,YAAY,EAAE,IAAI,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GAAG,MAAM;IAK/E,0DAA0D;IAC1D,MAAM,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM;IAKnF,mDAAmD;IACnD,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,yBAAyB,GAAG,MAAM;CAGjH"}
|
package/dist/src/index.d.ts
CHANGED
|
File without changes
|
package/dist/src/index.d.ts.map
CHANGED
|
File without changes
|
package/dist/src/index.js
CHANGED
|
@@ -52,7 +52,9 @@ function registerTranslation(...translation) {
|
|
|
52
52
|
});
|
|
53
53
|
update();
|
|
54
54
|
}
|
|
55
|
-
window
|
|
55
|
+
if (typeof window !== 'undefined') {
|
|
56
|
+
window.registerTranslation = registerTranslation;
|
|
57
|
+
}
|
|
56
58
|
/**
|
|
57
59
|
* Localize Reactive Controller for components built with Lit
|
|
58
60
|
*
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/controllers/localize.ts","../../../src/mixins/localization.ts"],"sourcesContent":["import type { LitElement, ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport type FunctionParams<T> = T extends (...args: infer U) => string ? U : [];\n\nexport interface Translation {\n $code: string; // e.g. en, en-GB\n $name: string; // e.g. English, Español\n $dir: 'ltr' | 'rtl';\n}\n\nexport interface DefaultTranslation extends Translation {\n [key: string]: any;\n}\n\nexport interface ExistsOptions {\n lang: string;\n includeFallback: boolean;\n}\n\nconst connectedElements = new Set<HTMLElement>();\n\ndeclare global {\n interface Window {\n translations?: Map<string, Translation>;\n }\n}\n\nif (window && !window.translations) {\n window.translations = new Map<string, Translation>();\n}\n\nconst { translations }: { translations: Map<string, Translation> } = window as Window & {\n translations: Map<string, Translation>;\n};\n\nlet fallback: Translation;\n\n// TODO: We need some way for users to be able to set these on the server.\nlet documentDirection = 'ltr';\n\n// Fallback for server.\nlet documentLanguage = 'en';\n\nconst isClient =\n typeof MutationObserver !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof document.documentElement !== 'undefined';\n\n/** Updates all localized elements that are currently connected */\nexport function update() {\n if (isClient) {\n documentDirection = document.documentElement.dir || 'ltr';\n documentLanguage = document.documentElement.lang || navigator.language;\n }\n\n [...connectedElements.keys()].forEach((el) => {\n const litEl = el as unknown as LitElement;\n if (typeof litEl.requestUpdate === 'function') {\n litEl.requestUpdate();\n }\n });\n}\n\nif (isClient) {\n const documentElementObserver = new MutationObserver(update);\n documentDirection = document.documentElement.dir || 'ltr';\n documentLanguage = document.documentElement.lang || navigator.language;\n\n // Watch for changes on <html lang>\n documentElementObserver.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['dir', 'lang'],\n });\n}\n\n/** Registers one or more translations */\nexport function registerTranslation(...translation: Translation[]) {\n translation.forEach((t) => {\n const code = t.$code.toLowerCase();\n\n if (translations.has(code)) {\n // Merge translations that share the same language code\n translations.set(code, { ...translations.get(code), ...t });\n } else {\n translations.set(code, t);\n }\n\n // The first translation that's registered is the fallback\n if (!fallback) {\n fallback = t;\n }\n });\n\n update();\n}\ndeclare global {\n interface Window {\n registerTranslation: typeof registerTranslation;\n }\n}\n\nwindow.registerTranslation = registerTranslation;\n\n/**\n * Localize Reactive Controller for components built with Lit\n *\n * To use this controller, import the class and instantiate it in a custom element constructor:\n *\n * private localize = new LocalizeController(this);\n *\n * This will add the element to the set and make it respond to changes to <html dir|lang> automatically. To make it\n * respond to changes to its own dir|lang properties, make it a property:\n *\n * @property() dir: string;\n * @property() lang: string;\n *\n * To use a translation method, call it like this:\n *\n * ${this.localize.term('term_key_here')}\n * ${this.localize.date('2021-12-03')}\n * ${this.localize.number(1000000)}\n */\nexport class LocalizeController<\n UserTranslation extends Translation = DefaultTranslation,\n> implements ReactiveController {\n host: ReactiveControllerHost & HTMLElement;\n\n constructor(host: ReactiveControllerHost & HTMLElement) {\n this.host = host;\n this.host.addController(this);\n }\n\n hostConnected() {\n connectedElements.add(this.host);\n }\n\n hostDisconnected() {\n connectedElements.delete(this.host);\n }\n\n /**\n * Gets the host element's directionality as determined by the `dir` attribute. The return value is transformed to\n * lowercase.\n */\n dir() {\n return `${this.host.dir || documentDirection}`.toLowerCase();\n }\n\n /**\n * Gets the host element's language as determined by the `lang` attribute. The return value is transformed to\n * lowercase.\n */\n lang() {\n return `${this.host.lang || documentLanguage}`.toLowerCase();\n }\n\n // eslint-disable-next-line class-methods-use-this\n private getTranslationData(lang: string) {\n // Convert \"en_US\" to \"en-US\". Note that both underscores and dashes are allowed per spec, but underscores result in\n // a RangeError by the call to `new Intl.Locale()`. See: https://unicode.org/reports/tr35/#unicode-locale-identifier\n const locale = new Intl.Locale(lang.replace(/_/g, '-'));\n const language = locale?.language.toLowerCase();\n const region = locale?.region?.toLowerCase() ?? '';\n const primary = <UserTranslation>translations.get(`${language}-${region}`);\n const secondary = <UserTranslation>translations.get(language);\n\n return { locale, language, region, primary, secondary };\n }\n\n /** Determines if the specified term exists, optionally checking the fallback translation. */\n exists<K extends keyof UserTranslation>(key: K, options: Partial<ExistsOptions>): boolean {\n const { primary, secondary } = this.getTranslationData(options.lang ?? this.lang());\n\n const mergedOptions = {\n includeFallback: false,\n ...options,\n };\n\n if (\n (primary && primary[key]) ||\n (secondary && secondary[key]) ||\n (mergedOptions.includeFallback && fallback && fallback[key as keyof Translation])\n ) {\n return true;\n }\n\n return false;\n }\n\n /** Outputs a translated term. */\n term<K extends keyof UserTranslation>(key: K, ...args: FunctionParams<UserTranslation[K]>): string {\n const { primary, secondary } = this.getTranslationData(this.lang());\n let term: any;\n\n // Look for a matching term using regionCode, code, then the fallback\n if (primary && primary[key]) {\n term = primary[key];\n } else if (secondary && secondary[key]) {\n term = secondary[key];\n } else if (fallback && fallback[key as keyof Translation]) {\n term = fallback[key as keyof Translation];\n } else {\n // eslint-disable-next-line no-console\n console.error(`No translation found for: ${String(key)}`);\n return String(key);\n }\n\n if (typeof term === 'function') {\n return term(...args) as string;\n }\n\n return term;\n }\n\n /** Outputs a localized date in the specified format. */\n date(dateToFormat: Date | string, options?: Intl.DateTimeFormatOptions): string {\n const date = new Date(dateToFormat);\n return new Intl.DateTimeFormat(this.lang(), options).format(date);\n }\n\n /** Outputs a localized number in the specified format. */\n number(numberToFormat: number | string, options?: Intl.NumberFormatOptions): string {\n const num = Number(numberToFormat);\n return Number.isNaN(num) ? '' : new Intl.NumberFormat(this.lang(), options).format(num);\n }\n\n /** Outputs a localized time in relative format. */\n relativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string {\n return new Intl.RelativeTimeFormat(this.lang(), options).format(value, unit);\n }\n}\n","import { ReactiveControllerHost } from 'lit';\nimport { LocalizeController } from '../controllers/localize.js';\nimport { Constructor } from '../index.js';\n\n/**\n * @param Base The base class.\n * @returns A mix-in implementing `localizations` method.\n *\n *@example\n * <!-- Terms -->\n ${this.$localize.term('hello')}\n or\n ${this.$t('hello')}\n\n <!-- Dates -->\n ${this.$localize.date('2021-09-15 14:00:00 ET', { month: 'long', day: 'numeric', year: 'numeric' })}\n or\n ${this.$d('2021-09-15 14:00:00 ET', { month: 'long', day: 'numeric', year: 'numeric' })}\n\n <!-- Numbers/currency -->\n ${this.$localize.number(1000, { style: 'currency', currency: 'USD'})}\n or\n ${this.$n(1000,{ style: 'currency', currency: 'USD'})}\n\n <!-- Determining language -->\n ${this.$localize.lang()}\n\n <!-- Determining directionality, e.g. 'ltr' or 'rtl' -->\n ${this.$localize.dir()}\n\n\n *** HOW TO DEFINE TRANSLATIONS: ***\n // Simple terms\n upload: 'Upload',\n\n // Terms with placeholders\n greetUser: (name: string) => `Hello, ${name}!`,\n\n // Plurals\n numFilesSelected: (count: number) => {\n if (count === 0) return 'No files selected';\n if (count === 1) return '1 file selected';\n return `${count} files selected`;\n }\n */\n\nconst LocalizeMixin = <T extends Constructor<ReactiveControllerHost & HTMLElement>>(Base: T) =>\n class extends Base {\n public localize: LocalizeController = new LocalizeController(this);\n\n // Provide default values to avoid definite assignment errors and avoid decorators\n // commentati perchè danno problemi su React.js. Sono attributi nativi, e assegnare un valore di default a react da fastidio\n // dir: string = '';\n // lang: string = '';\n\n /**\n * Restituisce tutta l'utility di traduzione\n *\n\n *\n * @returns tutta l'utility di traduzione\n *\n * @example\n * this.$localize.lang() -> ritorna la lingua corrente\n * this.$localize.dir() -> ritorna la direzione della lingua corrente\n */\n get $localize() {\n return this.localize;\n }\n\n /**\n * Restituisce una stringa localizzata a partire da una chiave di termine.\n *\n * Utilizza il `LocalizeController` per accedere al dizionario corrente e\n * tradurre la chiave fornita secondo la lingua attiva.\n *\n * @param t - La chiave del termine da localizzare (es. 'hello', 'submit', ecc.).\n * @returns La stringa tradotta in base alla lingua attiva. Se la chiave non è trovata, restituisce la chiave stessa.\n *\n * @example\n * this.$t('hello'); // → \"Ciao\" (in locale it-IT)\n */\n public $t(t: string) {\n // format term\n return this.localize.term(t);\n }\n\n /**\n * Formatta una data in base alla localizzazione attiva.\n *\n * Utilizza il `LocalizeController` per restituire una stringa localizzata\n * secondo le opzioni fornite (es. mese esteso, anno, ecc.).\n *\n * @param n - La data da formattare come stringa compatibile (es. ISO o con timezone, es. '2021-09-15 14:00:00 ET').\n * @param p - Le opzioni di formattazione per `Intl.DateTimeFormat` (es. { year: 'numeric', month: 'long', day: 'numeric' }).\n * @returns Una stringa rappresentante la data formattata secondo la localizzazione attiva.\n *\n * @example\n * this.$d('2021-09-15 14:00:00 ET', { year: 'numeric', month: 'long', day: 'numeric' });\n * // → \"15 settembre 2021\" (in locale it-IT)\n */\n public $d(d: Date | string, p: Intl.DateTimeFormatOptions) {\n // format date\n return this.localize.date(d, p);\n }\n\n /**\n * Formatta un numero secondo le impostazioni locali dell'utente corrente.\n *\n * Utilizza il `LocalizeController` per applicare formattazione numerica,\n * incluse opzioni come separatori, decimali, valute, ecc.\n *\n * @param d - Il numero da formattare.\n * @param p - Le opzioni di formattazione (es. { style: 'currency', currency: 'EUR' }).\n * @returns Una stringa rappresentante il numero formattato secondo la localizzazione attiva.\n *\n * @example\n * this.$n(1234.56, { style: 'currency', currency: 'USD' }); // → \"$1,234.56\" (in locale en-US)\n */\n public $n(d: number, p: Intl.NumberFormatOptions) {\n return this.localize.number(d, p);\n }\n };\n\nexport default LocalizeMixin;\n\n// export interface LocalizedComponent {\n// $t(t: string): string;\n// $d(d: Date | string, p?: Intl.DateTimeFormatOptions): string;\n// $n(n: number, p?: Intl.NumberFormatOptions): string;\n// $localize: LocalizeController;\n// }\n"],"names":[],"mappings":"AAmBA,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAe;AAQhD,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;AAClC,IAAA,MAAM,CAAC,YAAY,GAAG,IAAI,GAAG,EAAuB;AACtD;AAEA,MAAM,EAAE,YAAY,EAAE,GAA+C,MAEpE;AAED,IAAI,QAAqB;AAEzB;AACA,IAAI,iBAAiB,GAAG,KAAK;AAE7B;AACA,IAAI,gBAAgB,GAAG,IAAI;AAE3B,MAAM,QAAQ,GACZ,OAAO,gBAAgB,KAAK,WAAW;IACvC,OAAO,QAAQ,KAAK,WAAW;AAC/B,IAAA,OAAO,QAAQ,CAAC,eAAe,KAAK,WAAW;AAEjD;SACgB,MAAM,GAAA;IACpB,IAAI,QAAQ,EAAE;QACZ,iBAAiB,GAAG,QAAQ,CAAC,eAAe,CAAC,GAAG,IAAI,KAAK;QACzD,gBAAgB,GAAG,QAAQ,CAAC,eAAe,CAAC,IAAI,IAAI,SAAS,CAAC,QAAQ;IACxE;AAEA,IAAA,CAAC,GAAG,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,KAAI;QAC3C,MAAM,KAAK,GAAG,EAA2B;A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AA6B,EAAA;;QAEvD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;IACjC;AAEA;;;;;;;;;;;;AAYG;IACI,EAAE,CAAC,CAAS,EAAE,CAA2B,EAAA;QAC9C,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IACnC;;AAKJ;AACA;AACA;AACA;AACA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/controllers/localize.ts","../../../src/mixins/localization.ts"],"sourcesContent":["import type { LitElement, ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport type FunctionParams<T> = T extends (...args: infer U) => string ? U : [];\n\nexport interface Translation {\n $code: string; // e.g. en, en-GB\n $name: string; // e.g. English, Español\n $dir: 'ltr' | 'rtl';\n}\n\nexport interface DefaultTranslation extends Translation {\n [key: string]: any;\n}\n\nexport interface ExistsOptions {\n lang: string;\n includeFallback: boolean;\n}\n\nconst connectedElements = new Set<HTMLElement>();\n\ndeclare global {\n interface Window {\n translations?: Map<string, Translation>;\n }\n}\n\nif (window && !window.translations) {\n window.translations = new Map<string, Translation>();\n}\n\nconst { translations }: { translations: Map<string, Translation> } = window as Window & {\n translations: Map<string, Translation>;\n};\n\nlet fallback: Translation;\n\n// TODO: We need some way for users to be able to set these on the server.\nlet documentDirection = 'ltr';\n\n// Fallback for server.\nlet documentLanguage = 'en';\n\nconst isClient =\n typeof MutationObserver !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof document.documentElement !== 'undefined';\n\n/** Updates all localized elements that are currently connected */\nexport function update() {\n if (isClient) {\n documentDirection = document.documentElement.dir || 'ltr';\n documentLanguage = document.documentElement.lang || navigator.language;\n }\n\n [...connectedElements.keys()].forEach((el) => {\n const litEl = el as unknown as LitElement;\n if (typeof litEl.requestUpdate === 'function') {\n litEl.requestUpdate();\n }\n });\n}\n\nif (isClient) {\n const documentElementObserver = new MutationObserver(update);\n documentDirection = document.documentElement.dir || 'ltr';\n documentLanguage = document.documentElement.lang || navigator.language;\n\n // Watch for changes on <html lang>\n documentElementObserver.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['dir', 'lang'],\n });\n}\n\n/** Registers one or more translations */\nexport function registerTranslation(...translation: Translation[]) {\n translation.forEach((t) => {\n const code = t.$code.toLowerCase();\n\n if (translations.has(code)) {\n // Merge translations that share the same language code\n translations.set(code, { ...translations.get(code), ...t });\n } else {\n translations.set(code, t);\n }\n\n // The first translation that's registered is the fallback\n if (!fallback) {\n fallback = t;\n }\n });\n\n update();\n}\ndeclare global {\n interface Window {\n registerTranslation: typeof registerTranslation;\n }\n}\n\nif (typeof window !== 'undefined') {\n window.registerTranslation = registerTranslation;\n}\n/**\n * Localize Reactive Controller for components built with Lit\n *\n * To use this controller, import the class and instantiate it in a custom element constructor:\n *\n * private localize = new LocalizeController(this);\n *\n * This will add the element to the set and make it respond to changes to <html dir|lang> automatically. To make it\n * respond to changes to its own dir|lang properties, make it a property:\n *\n * @property() dir: string;\n * @property() lang: string;\n *\n * To use a translation method, call it like this:\n *\n * ${this.localize.term('term_key_here')}\n * ${this.localize.date('2021-12-03')}\n * ${this.localize.number(1000000)}\n */\nexport class LocalizeController<\n UserTranslation extends Translation = DefaultTranslation,\n> implements ReactiveController {\n host: ReactiveControllerHost & HTMLElement;\n\n constructor(host: ReactiveControllerHost & HTMLElement) {\n this.host = host;\n this.host.addController(this);\n }\n\n hostConnected() {\n connectedElements.add(this.host);\n }\n\n hostDisconnected() {\n connectedElements.delete(this.host);\n }\n\n /**\n * Gets the host element's directionality as determined by the `dir` attribute. The return value is transformed to\n * lowercase.\n */\n dir() {\n return `${this.host.dir || documentDirection}`.toLowerCase();\n }\n\n /**\n * Gets the host element's language as determined by the `lang` attribute. The return value is transformed to\n * lowercase.\n */\n lang() {\n return `${this.host.lang || documentLanguage}`.toLowerCase();\n }\n\n // eslint-disable-next-line class-methods-use-this\n private getTranslationData(lang: string) {\n // Convert \"en_US\" to \"en-US\". Note that both underscores and dashes are allowed per spec, but underscores result in\n // a RangeError by the call to `new Intl.Locale()`. See: https://unicode.org/reports/tr35/#unicode-locale-identifier\n const locale = new Intl.Locale(lang.replace(/_/g, '-'));\n const language = locale?.language.toLowerCase();\n const region = locale?.region?.toLowerCase() ?? '';\n const primary = <UserTranslation>translations.get(`${language}-${region}`);\n const secondary = <UserTranslation>translations.get(language);\n\n return { locale, language, region, primary, secondary };\n }\n\n /** Determines if the specified term exists, optionally checking the fallback translation. */\n exists<K extends keyof UserTranslation>(key: K, options: Partial<ExistsOptions>): boolean {\n const { primary, secondary } = this.getTranslationData(options.lang ?? this.lang());\n\n const mergedOptions = {\n includeFallback: false,\n ...options,\n };\n\n if (\n (primary && primary[key]) ||\n (secondary && secondary[key]) ||\n (mergedOptions.includeFallback && fallback && fallback[key as keyof Translation])\n ) {\n return true;\n }\n\n return false;\n }\n\n /** Outputs a translated term. */\n term<K extends keyof UserTranslation>(key: K, ...args: FunctionParams<UserTranslation[K]>): string {\n const { primary, secondary } = this.getTranslationData(this.lang());\n let term: any;\n\n // Look for a matching term using regionCode, code, then the fallback\n if (primary && primary[key]) {\n term = primary[key];\n } else if (secondary && secondary[key]) {\n term = secondary[key];\n } else if (fallback && fallback[key as keyof Translation]) {\n term = fallback[key as keyof Translation];\n } else {\n // eslint-disable-next-line no-console\n console.error(`No translation found for: ${String(key)}`);\n return String(key);\n }\n\n if (typeof term === 'function') {\n return term(...args) as string;\n }\n\n return term;\n }\n\n /** Outputs a localized date in the specified format. */\n date(dateToFormat: Date | string, options?: Intl.DateTimeFormatOptions): string {\n const date = new Date(dateToFormat);\n return new Intl.DateTimeFormat(this.lang(), options).format(date);\n }\n\n /** Outputs a localized number in the specified format. */\n number(numberToFormat: number | string, options?: Intl.NumberFormatOptions): string {\n const num = Number(numberToFormat);\n return Number.isNaN(num) ? '' : new Intl.NumberFormat(this.lang(), options).format(num);\n }\n\n /** Outputs a localized time in relative format. */\n relativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string {\n return new Intl.RelativeTimeFormat(this.lang(), options).format(value, unit);\n }\n}\n","import { ReactiveControllerHost } from 'lit';\nimport { LocalizeController } from '../controllers/localize.js';\nimport { Constructor } from '../index.js';\n\n/**\n * @param Base The base class.\n * @returns A mix-in implementing `localizations` method.\n *\n *@example\n * <!-- Terms -->\n ${this.$localize.term('hello')}\n or\n ${this.$t('hello')}\n\n <!-- Dates -->\n ${this.$localize.date('2021-09-15 14:00:00 ET', { month: 'long', day: 'numeric', year: 'numeric' })}\n or\n ${this.$d('2021-09-15 14:00:00 ET', { month: 'long', day: 'numeric', year: 'numeric' })}\n\n <!-- Numbers/currency -->\n ${this.$localize.number(1000, { style: 'currency', currency: 'USD'})}\n or\n ${this.$n(1000,{ style: 'currency', currency: 'USD'})}\n\n <!-- Determining language -->\n ${this.$localize.lang()}\n\n <!-- Determining directionality, e.g. 'ltr' or 'rtl' -->\n ${this.$localize.dir()}\n\n\n *** HOW TO DEFINE TRANSLATIONS: ***\n // Simple terms\n upload: 'Upload',\n\n // Terms with placeholders\n greetUser: (name: string) => `Hello, ${name}!`,\n\n // Plurals\n numFilesSelected: (count: number) => {\n if (count === 0) return 'No files selected';\n if (count === 1) return '1 file selected';\n return `${count} files selected`;\n }\n */\n\nconst LocalizeMixin = <T extends Constructor<ReactiveControllerHost & HTMLElement>>(Base: T) =>\n class extends Base {\n public localize: LocalizeController = new LocalizeController(this);\n\n // Provide default values to avoid definite assignment errors and avoid decorators\n // commentati perchè danno problemi su React.js. Sono attributi nativi, e assegnare un valore di default a react da fastidio\n // dir: string = '';\n // lang: string = '';\n\n /**\n * Restituisce tutta l'utility di traduzione\n *\n\n *\n * @returns tutta l'utility di traduzione\n *\n * @example\n * this.$localize.lang() -> ritorna la lingua corrente\n * this.$localize.dir() -> ritorna la direzione della lingua corrente\n */\n get $localize() {\n return this.localize;\n }\n\n /**\n * Restituisce una stringa localizzata a partire da una chiave di termine.\n *\n * Utilizza il `LocalizeController` per accedere al dizionario corrente e\n * tradurre la chiave fornita secondo la lingua attiva.\n *\n * @param t - La chiave del termine da localizzare (es. 'hello', 'submit', ecc.).\n * @returns La stringa tradotta in base alla lingua attiva. Se la chiave non è trovata, restituisce la chiave stessa.\n *\n * @example\n * this.$t('hello'); // → \"Ciao\" (in locale it-IT)\n */\n public $t(t: string) {\n // format term\n return this.localize.term(t);\n }\n\n /**\n * Formatta una data in base alla localizzazione attiva.\n *\n * Utilizza il `LocalizeController` per restituire una stringa localizzata\n * secondo le opzioni fornite (es. mese esteso, anno, ecc.).\n *\n * @param n - La data da formattare come stringa compatibile (es. ISO o con timezone, es. '2021-09-15 14:00:00 ET').\n * @param p - Le opzioni di formattazione per `Intl.DateTimeFormat` (es. { year: 'numeric', month: 'long', day: 'numeric' }).\n * @returns Una stringa rappresentante la data formattata secondo la localizzazione attiva.\n *\n * @example\n * this.$d('2021-09-15 14:00:00 ET', { year: 'numeric', month: 'long', day: 'numeric' });\n * // → \"15 settembre 2021\" (in locale it-IT)\n */\n public $d(d: Date | string, p: Intl.DateTimeFormatOptions) {\n // format date\n return this.localize.date(d, p);\n }\n\n /**\n * Formatta un numero secondo le impostazioni locali dell'utente corrente.\n *\n * Utilizza il `LocalizeController` per applicare formattazione numerica,\n * incluse opzioni come separatori, decimali, valute, ecc.\n *\n * @param d - Il numero da formattare.\n * @param p - Le opzioni di formattazione (es. { style: 'currency', currency: 'EUR' }).\n * @returns Una stringa rappresentante il numero formattato secondo la localizzazione attiva.\n *\n * @example\n * this.$n(1234.56, { style: 'currency', currency: 'USD' }); // → \"$1,234.56\" (in locale en-US)\n */\n public $n(d: number, p: Intl.NumberFormatOptions) {\n return this.localize.number(d, p);\n }\n };\n\nexport default LocalizeMixin;\n\n// export interface LocalizedComponent {\n// $t(t: string): string;\n// $d(d: Date | string, p?: Intl.DateTimeFormatOptions): string;\n// $n(n: number, p?: Intl.NumberFormatOptions): string;\n// $localize: LocalizeController;\n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"description": "Translations utility del Design system .italia",
|
|
4
|
-
"version": "1.0.0-
|
|
4
|
+
"version": "1.0.0-beta.1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -31,32 +31,32 @@
|
|
|
31
31
|
"LICENSE",
|
|
32
32
|
"custom-elements.json"
|
|
33
33
|
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"analyze": "cem analyze --litelement --exclude dist",
|
|
36
|
+
"build": "rollup --config rollup.config.js",
|
|
37
|
+
"clean": "rimraf node_modules .turbo .rollup.cache dist coverage",
|
|
38
|
+
"prepublish": "pnpm build",
|
|
39
|
+
"lint": "eslint --ext .ts \"src/**/*.ts\" \"test/**/*.ts\" && prettier \"src/**/*.ts\" \"test/**/*.ts\" --check",
|
|
40
|
+
"format": "eslint --ext .ts \"src/**/*.ts\" \"test/**/*.ts\" --fix && prettier \"src/**/*.ts\" \"test/**/*.ts\" --write",
|
|
41
|
+
"test": "wtr --coverage --node-resolve --config web-test-runner.config.js",
|
|
42
|
+
"test:watch": "wtr --coverage --node-resolve --config web-test-runner.config.js --watch"
|
|
43
|
+
},
|
|
34
44
|
"dependencies": {
|
|
35
|
-
"lit": "
|
|
45
|
+
"lit": "catalog:"
|
|
36
46
|
},
|
|
37
47
|
"devDependencies": {
|
|
38
48
|
"@custom-elements-manifest/analyzer": "^0.10.3",
|
|
39
|
-
"@
|
|
49
|
+
"@italia/test-config": "workspace:^",
|
|
50
|
+
"@italia/typescript-config": "workspace:^",
|
|
51
|
+
"@open-wc/testing": "catalog:",
|
|
40
52
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
41
53
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
42
|
-
"@types/mocha": "
|
|
43
|
-
"@web/test-runner": "
|
|
54
|
+
"@types/mocha": "catalog:",
|
|
55
|
+
"@web/test-runner": "catalog:",
|
|
44
56
|
"rimraf": "^6.0.1",
|
|
45
57
|
"rollup": "^4.42.0",
|
|
46
58
|
"tslib": "^2.6.3",
|
|
47
|
-
"typescript": "
|
|
48
|
-
"@italia/test-config": "^0.0.0",
|
|
49
|
-
"@italia/typescript-config": "^0.0.0"
|
|
59
|
+
"typescript": "catalog:"
|
|
50
60
|
},
|
|
51
|
-
"customElements": "custom-elements.json"
|
|
52
|
-
|
|
53
|
-
"analyze": "cem analyze --litelement --exclude dist",
|
|
54
|
-
"build": "rollup --config rollup.config.js",
|
|
55
|
-
"clean": "rimraf node_modules .turbo .rollup.cache dist coverage",
|
|
56
|
-
"prepublish": "pnpm build",
|
|
57
|
-
"lint": "eslint --ext .ts \"src/**/*.ts\" \"test/**/*.ts\" && prettier \"src/**/*.ts\" \"test/**/*.ts\" --check",
|
|
58
|
-
"format": "eslint --ext .ts \"src/**/*.ts\" \"test/**/*.ts\" --fix && prettier \"src/**/*.ts\" \"test/**/*.ts\" --write",
|
|
59
|
-
"test": "wtr --coverage --node-resolve --config web-test-runner.config.js",
|
|
60
|
-
"test:watch": "wtr --coverage --node-resolve --config web-test-runner.config.js --watch"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
61
|
+
"customElements": "custom-elements.json"
|
|
62
|
+
}
|