kotori 5.0.3 → 5.0.5
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/index.cjs +1 -5
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +1 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -16,11 +16,7 @@ const kotori = (props) => {
|
|
|
16
16
|
listeners.delete(listener);
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
const t = (dict, ...args) => {
|
|
20
|
-
let locale = dict().translation[language];
|
|
21
|
-
for (const objKey in args[0]) locale = locale.replace(new RegExp(`\\{\\{\\s*${objKey}\\s*\\}\\}`, "g"), () => String(args[0]?.[objKey]));
|
|
22
|
-
return locale;
|
|
23
|
-
};
|
|
19
|
+
const t = (dict, ...args) => (dict().translation[language] || "").replace(/\{\{\s*([\w-]+)\s*\}\}/g, (_, key) => String(args[0]?.[key]));
|
|
24
20
|
return {
|
|
25
21
|
setLanguage,
|
|
26
22
|
t,
|
package/dist/index.d.cts
CHANGED
|
@@ -7,19 +7,19 @@ type SubTags = BCP47LanguageTagName extends `${infer SubTag}-${string}` ? SubTag
|
|
|
7
7
|
type AllTags = Tags | SubTags;
|
|
8
8
|
type Trim<T extends string> = T extends ` ${infer R}` ? Trim<R> : T extends `${infer L} ` ? Trim<L> : T;
|
|
9
9
|
type ExtractVariables<T extends string> = T extends `${string}{{${infer P}}}${infer Q}` ? Trim<P> | ExtractVariables<Q> : never;
|
|
10
|
-
declare const
|
|
10
|
+
declare const _args: unique symbol;
|
|
11
11
|
declare const kotori: <const PrimaryTag extends AllTags, const SecondaryTags extends Exclude<AllTags, PrimaryTag>>(props: {
|
|
12
12
|
primaryLanguageTag: PrimaryTag;
|
|
13
13
|
secondaryLanguageTags: SecondaryTags[];
|
|
14
14
|
}) => {
|
|
15
15
|
setLanguage: (tag: PrimaryTag | SecondaryTags) => void;
|
|
16
|
-
t: <
|
|
16
|
+
t: <Dict extends () => Readonly<{
|
|
17
17
|
translation: Record<PrimaryTag | SecondaryTags, string>;
|
|
18
|
-
[
|
|
19
|
-
}>>(dict:
|
|
18
|
+
[_args]?: Record<string, string | number>;
|
|
19
|
+
}>>(dict: Dict, ...args: keyof NonNullable<ReturnType<Dict>[typeof _args]> extends never ? [] : [NonNullable<ReturnType<Dict>[typeof _args]>]) => string;
|
|
20
20
|
dict: <const PrimaryString extends string, const SecondaryObject extends { [Key in SecondaryTags]: ExtractVariables<PrimaryString> extends infer PrimaryVariables ? ExtractVariables<SecondaryObject[Key] & string> extends infer SecondaryVariables ? PrimaryVariables[] extends SecondaryVariables[] ? SecondaryVariables[] extends PrimaryVariables[] ? SecondaryObject[Key] : "variables not match!" : "variables not match!!" : never : never }>(translation: { [Key in PrimaryTag]: PrimaryString } & SecondaryObject) => <const ArgsType extends Record<ExtractVariables<PrimaryString>, string | number> = Record<ExtractVariables<PrimaryString>, string | number>>() => Readonly<{
|
|
21
21
|
translation: typeof translation;
|
|
22
|
-
[
|
|
22
|
+
[_args]?: ArgsType;
|
|
23
23
|
}>;
|
|
24
24
|
useT: () => PrimaryTag | SecondaryTags;
|
|
25
25
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -7,19 +7,19 @@ type SubTags = BCP47LanguageTagName extends `${infer SubTag}-${string}` ? SubTag
|
|
|
7
7
|
type AllTags = Tags | SubTags;
|
|
8
8
|
type Trim<T extends string> = T extends ` ${infer R}` ? Trim<R> : T extends `${infer L} ` ? Trim<L> : T;
|
|
9
9
|
type ExtractVariables<T extends string> = T extends `${string}{{${infer P}}}${infer Q}` ? Trim<P> | ExtractVariables<Q> : never;
|
|
10
|
-
declare const
|
|
10
|
+
declare const _args: unique symbol;
|
|
11
11
|
declare const kotori: <const PrimaryTag extends AllTags, const SecondaryTags extends Exclude<AllTags, PrimaryTag>>(props: {
|
|
12
12
|
primaryLanguageTag: PrimaryTag;
|
|
13
13
|
secondaryLanguageTags: SecondaryTags[];
|
|
14
14
|
}) => {
|
|
15
15
|
setLanguage: (tag: PrimaryTag | SecondaryTags) => void;
|
|
16
|
-
t: <
|
|
16
|
+
t: <Dict extends () => Readonly<{
|
|
17
17
|
translation: Record<PrimaryTag | SecondaryTags, string>;
|
|
18
|
-
[
|
|
19
|
-
}>>(dict:
|
|
18
|
+
[_args]?: Record<string, string | number>;
|
|
19
|
+
}>>(dict: Dict, ...args: keyof NonNullable<ReturnType<Dict>[typeof _args]> extends never ? [] : [NonNullable<ReturnType<Dict>[typeof _args]>]) => string;
|
|
20
20
|
dict: <const PrimaryString extends string, const SecondaryObject extends { [Key in SecondaryTags]: ExtractVariables<PrimaryString> extends infer PrimaryVariables ? ExtractVariables<SecondaryObject[Key] & string> extends infer SecondaryVariables ? PrimaryVariables[] extends SecondaryVariables[] ? SecondaryVariables[] extends PrimaryVariables[] ? SecondaryObject[Key] : "variables not match!" : "variables not match!!" : never : never }>(translation: { [Key in PrimaryTag]: PrimaryString } & SecondaryObject) => <const ArgsType extends Record<ExtractVariables<PrimaryString>, string | number> = Record<ExtractVariables<PrimaryString>, string | number>>() => Readonly<{
|
|
21
21
|
translation: typeof translation;
|
|
22
|
-
[
|
|
22
|
+
[_args]?: ArgsType;
|
|
23
23
|
}>;
|
|
24
24
|
useT: () => PrimaryTag | SecondaryTags;
|
|
25
25
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -15,11 +15,7 @@ const kotori = (props) => {
|
|
|
15
15
|
listeners.delete(listener);
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
const t = (dict, ...args) => {
|
|
19
|
-
let locale = dict().translation[language];
|
|
20
|
-
for (const objKey in args[0]) locale = locale.replace(new RegExp(`\\{\\{\\s*${objKey}\\s*\\}\\}`, "g"), () => String(args[0]?.[objKey]));
|
|
21
|
-
return locale;
|
|
22
|
-
};
|
|
18
|
+
const t = (dict, ...args) => (dict().translation[language] || "").replace(/\{\{\s*([\w-]+)\s*\}\}/g, (_, key) => String(args[0]?.[key]));
|
|
23
19
|
return {
|
|
24
20
|
setLanguage,
|
|
25
21
|
t,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kotori",
|
|
3
3
|
"description": "Strongly-typed and composable internationalization library for React",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.5",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"setup": "rm -rf node_modules && npm i && git init && husky",
|
|
7
7
|
"prepublishOnly": "npm i && npx tsc && npm run build",
|