@shoelace-style/localize 2.1.2 → 2.1.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/CHANGELOG.md +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/package.json +1 -1
- package/src/index.ts +4 -4
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare function term<K extends keyof Translation>(lang: string, key: K,
|
|
|
11
11
|
export declare function date(lang: string, dateToFormat: Date | string, options?: Intl.DateTimeFormatOptions): string;
|
|
12
12
|
export declare function number(lang: string, numberToFormat: number | string, options?: Intl.NumberFormatOptions): string;
|
|
13
13
|
export declare function relativeTime(lang: string, value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string;
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function update(): void;
|
|
15
15
|
export declare class LocalizeController implements ReactiveController {
|
|
16
16
|
host: ReactiveControllerHost & HTMLElement;
|
|
17
17
|
constructor(host: ReactiveControllerHost & HTMLElement);
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const connectedElements = new Set();
|
|
2
|
-
const documentElementObserver = new MutationObserver(
|
|
2
|
+
const documentElementObserver = new MutationObserver(update);
|
|
3
3
|
const translations = new Map();
|
|
4
4
|
let documentLanguage = document.documentElement.lang || navigator.language;
|
|
5
5
|
let fallback;
|
|
@@ -15,7 +15,7 @@ export function registerTranslation(...translation) {
|
|
|
15
15
|
fallback = t;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
|
|
18
|
+
update();
|
|
19
19
|
}
|
|
20
20
|
export function term(lang, key, ...args) {
|
|
21
21
|
const code = lang.toLowerCase().slice(0, 2);
|
|
@@ -52,7 +52,7 @@ export function number(lang, numberToFormat, options) {
|
|
|
52
52
|
export function relativeTime(lang, value, unit, options) {
|
|
53
53
|
return new Intl.RelativeTimeFormat(lang, options).format(value, unit);
|
|
54
54
|
}
|
|
55
|
-
export function
|
|
55
|
+
export function update() {
|
|
56
56
|
documentLanguage = document.documentElement.lang || navigator.language;
|
|
57
57
|
[...connectedElements.keys()].map((el) => {
|
|
58
58
|
if (typeof el.requestUpdate === 'function') {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface Translation {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const connectedElements = new Set<HTMLElement>();
|
|
13
|
-
const documentElementObserver = new MutationObserver(
|
|
13
|
+
const documentElementObserver = new MutationObserver(update);
|
|
14
14
|
const translations: Map<string, Translation> = new Map();
|
|
15
15
|
let documentLanguage = document.documentElement.lang || navigator.language;
|
|
16
16
|
let fallback: Translation;
|
|
@@ -35,7 +35,7 @@ export function registerTranslation(...translation: Translation[]) {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
update();
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
//
|
|
@@ -97,9 +97,9 @@ export function relativeTime(
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
//
|
|
100
|
-
// Updates
|
|
100
|
+
// Updates all localized elements that are currently connected
|
|
101
101
|
//
|
|
102
|
-
export function
|
|
102
|
+
export function update() {
|
|
103
103
|
documentLanguage = document.documentElement.lang || navigator.language;
|
|
104
104
|
|
|
105
105
|
[...connectedElements.keys()].map((el: LitElement) => {
|