@hyvor/design 0.0.53 → 0.0.54
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/dist/components/Internationalization/InternationalizationProvider.svelte +4 -1
- package/dist/components/Internationalization/T.svelte +8 -7
- package/dist/components/Internationalization/T.svelte.d.ts +2 -2
- package/dist/components/Internationalization/i18n.js +2 -1
- package/dist/components/Internationalization/t.d.ts +7 -0
- package/dist/components/Internationalization/t.js +18 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/package.json +1 -1
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import { InternationalizationService } from "./i18n.js";
|
|
3
3
|
export let languages;
|
|
4
4
|
const i18n = new InternationalizationService(languages);
|
|
5
|
+
const locale = i18n.locale;
|
|
5
6
|
setContext("i18n", i18n);
|
|
6
7
|
</script>
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
{#key $locale}
|
|
10
|
+
<slot />
|
|
11
|
+
{/key}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { getStringByKey, InternationalizationService } from "./i18n.js";
|
|
3
3
|
import { IntlMessageFormat } from "intl-messageformat";
|
|
4
4
|
import { browser } from "$app/environment";
|
|
5
|
+
import { getMessage as getMessageBase } from "./t.js";
|
|
5
6
|
export let key;
|
|
6
7
|
export let params = {};
|
|
7
8
|
let hasComponentParams = false;
|
|
@@ -53,12 +54,12 @@ const locale = i18n.locale;
|
|
|
53
54
|
const strings = i18n.strings;
|
|
54
55
|
let message = getMessage(getParamsForBackend());
|
|
55
56
|
function getMessage(processedParams) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
return getMessageBase(
|
|
58
|
+
key,
|
|
59
|
+
processedParams,
|
|
60
|
+
$strings,
|
|
61
|
+
$locale
|
|
62
|
+
);
|
|
62
63
|
}
|
|
63
64
|
function bindComponents() {
|
|
64
65
|
for (let [id, binding] of componentBindings) {
|
|
@@ -81,7 +82,7 @@ async function renderFrontend() {
|
|
|
81
82
|
}
|
|
82
83
|
let mounted = false;
|
|
83
84
|
$: {
|
|
84
|
-
|
|
85
|
+
params;
|
|
85
86
|
if (browser && mounted) {
|
|
86
87
|
renderFrontend();
|
|
87
88
|
}
|
|
@@ -4,10 +4,10 @@ import { type PrimitiveType } from 'intl-messageformat';
|
|
|
4
4
|
declare const __propDef: {
|
|
5
5
|
props: {
|
|
6
6
|
key: string;
|
|
7
|
-
params?: Record<string, {
|
|
7
|
+
params?: Record<string, PrimitiveType | {
|
|
8
8
|
component: ComponentType;
|
|
9
9
|
props?: Record<string, any> | undefined;
|
|
10
|
-
}
|
|
10
|
+
}> | undefined;
|
|
11
11
|
};
|
|
12
12
|
events: {
|
|
13
13
|
[evt: string]: CustomEvent<any>;
|
|
@@ -32,14 +32,15 @@ export class InternationalizationService {
|
|
|
32
32
|
this.strings.set(merged);
|
|
33
33
|
}
|
|
34
34
|
setLocale(code) {
|
|
35
|
-
this.locale.set(code);
|
|
36
35
|
if (this.stringsCache.has(code)) {
|
|
37
36
|
this.setStrings(code);
|
|
37
|
+
this.locale.set(code);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
this.languageByCode(code)?.loader().then(({ default: strings }) => {
|
|
41
41
|
this.stringsCache.set(code, strings);
|
|
42
42
|
this.setStrings(code);
|
|
43
|
+
this.locale.set(code);
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PrimitiveType } from "intl-messageformat";
|
|
2
|
+
import { type InternationalizationService } from "./i18n.js";
|
|
3
|
+
type ParamValue = PrimitiveType | ((chunks: string | string[]) => string);
|
|
4
|
+
type ParamsType = Record<string, ParamValue>;
|
|
5
|
+
export declare function getMessage(key: string, params: ParamsType, $strings: Record<string, any>, $locale: string): string;
|
|
6
|
+
export declare function t(key: string, params?: Record<string, PrimitiveType>, i18n?: InternationalizationService | null): string;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IntlMessageFormat } from "intl-messageformat";
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
import { get } from "svelte/store";
|
|
4
|
+
import { getStringByKey } from "./i18n.js";
|
|
5
|
+
export function getMessage(key, params, $strings, $locale) {
|
|
6
|
+
const string = getStringByKey($strings, key);
|
|
7
|
+
if (string) {
|
|
8
|
+
const formatter = new IntlMessageFormat(string, $locale);
|
|
9
|
+
return formatter.format(params);
|
|
10
|
+
}
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
export function t(key, params = {}, i18n = null) {
|
|
14
|
+
i18n = i18n || getContext('i18n');
|
|
15
|
+
const $locale = get(i18n.locale);
|
|
16
|
+
const $strings = get(i18n.strings);
|
|
17
|
+
return getMessage(key, params, $strings, $locale);
|
|
18
|
+
}
|
|
@@ -45,3 +45,4 @@ export { default as InternationalizationProvider } from './Internationalization/
|
|
|
45
45
|
export { default as LanguageToggle } from './Internationalization/LanguageToggle.svelte';
|
|
46
46
|
export { default as T } from './Internationalization/T.svelte';
|
|
47
47
|
export { type Language as InternationalizationLanguage, InternationalizationService } from './Internationalization/i18n.js';
|
|
48
|
+
export { t } from './Internationalization/t.js';
|
package/dist/components/index.js
CHANGED
|
@@ -47,3 +47,4 @@ export { default as InternationalizationProvider } from './Internationalization/
|
|
|
47
47
|
export { default as LanguageToggle } from './Internationalization/LanguageToggle.svelte';
|
|
48
48
|
export { default as T } from './Internationalization/T.svelte';
|
|
49
49
|
export { InternationalizationService } from './Internationalization/i18n.js';
|
|
50
|
+
export { t } from './Internationalization/t.js';
|