@nimpl/i18n 0.0.0-experimental-7639e49 → 0.0.0-experimental-b4eb49b
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/cjs/initialize.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ export declare const initialize: (config: Config) => {
|
|
|
7
7
|
Transmitter: (options: Omit<TransmitterCoreProps, "dictionary" | "language"> & {
|
|
8
8
|
language?: string;
|
|
9
9
|
}) => Promise<React.JSX.Element>;
|
|
10
|
-
ServerTranslation: (
|
|
10
|
+
ServerTranslation: (props: Omit<TranslationCoreProps, "dictionary" | "language"> & {
|
|
11
11
|
language?: string;
|
|
12
12
|
}) => Promise<React.JSX.Element>;
|
|
13
|
-
getTranslation: (options
|
|
13
|
+
getTranslation: (options?: Omit<GetTranslationCoreOptions, "dictionary" | "language"> & {
|
|
14
14
|
language?: string;
|
|
15
15
|
}) => Promise<import("./lib/get-translation-core").GetTranslationCoreReturnType>;
|
|
16
|
-
revalidate: (language: string, background?: boolean) => Promise<Translates>;
|
|
16
|
+
revalidate: (language: string, mode?: "background" | "foreground", optional?: boolean) => Promise<Translates>;
|
|
17
17
|
};
|
package/dist/cjs/initialize.js
CHANGED
|
@@ -7,11 +7,15 @@ var transmitterCore = require('./lib/transmitter-core.js');
|
|
|
7
7
|
|
|
8
8
|
const initialize = (config) => {
|
|
9
9
|
const cache = new Map();
|
|
10
|
-
const loadTranslates = async (language,
|
|
10
|
+
const loadTranslates = async (language, optional) => {
|
|
11
11
|
const item = cache.get(language);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const isPromise = item instanceof Promise;
|
|
13
|
+
if (item && (isPromise || optional)) {
|
|
14
|
+
if (isPromise) {
|
|
15
|
+
const dictionary = await item;
|
|
16
|
+
cache.set(language, dictionary);
|
|
17
|
+
return dictionary;
|
|
18
|
+
}
|
|
15
19
|
return item;
|
|
16
20
|
}
|
|
17
21
|
const newData = await config.load(language);
|
|
@@ -21,29 +25,17 @@ const initialize = (config) => {
|
|
|
21
25
|
const getTranslation = async (options) => {
|
|
22
26
|
const { language, ...rest } = options || {};
|
|
23
27
|
const targetLanguage = language || (await config.getLanguage());
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
dictionary = await loadTranslates(targetLanguage);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
dictionary = await revalidate(targetLanguage);
|
|
30
|
-
}
|
|
31
|
-
if (!language) {
|
|
28
|
+
const dictionary = await revalidate(targetLanguage, "foreground", config.cache);
|
|
29
|
+
if (!targetLanguage) {
|
|
32
30
|
throw new Error("Unable to get the language in getTranslation. Please check the getLanguage method in the configuration file or pass the language as an argument.");
|
|
33
31
|
}
|
|
34
32
|
return getTranslationCore.getTranslationCore({ ...rest, language: targetLanguage, dictionary });
|
|
35
33
|
};
|
|
36
|
-
const ServerTranslation = async (
|
|
37
|
-
const { language, ...rest } =
|
|
34
|
+
const ServerTranslation = async (props) => {
|
|
35
|
+
const { language, ...rest } = props || {};
|
|
38
36
|
const targetLanguage = language || (await config.getLanguage());
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
dictionary = await loadTranslates(targetLanguage);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
dictionary = await revalidate(targetLanguage);
|
|
45
|
-
}
|
|
46
|
-
if (!language) {
|
|
37
|
+
const dictionary = await revalidate(targetLanguage, "foreground", config.cache);
|
|
38
|
+
if (!targetLanguage) {
|
|
47
39
|
throw new Error("Unable to get the language in ServerTranslation. Please check the getLanguage method in the configuration file or pass the language as an argument.");
|
|
48
40
|
}
|
|
49
41
|
return React.createElement(translationCore.TranslationCore, { ...rest, language: targetLanguage, dictionary: dictionary });
|
|
@@ -51,27 +43,18 @@ const initialize = (config) => {
|
|
|
51
43
|
const Transmitter = async (options) => {
|
|
52
44
|
const { language, ...rest } = options || {};
|
|
53
45
|
const targetLanguage = language || (await config.getLanguage());
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
dictionary = await loadTranslates(targetLanguage);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
dictionary = await revalidate(targetLanguage);
|
|
60
|
-
}
|
|
61
|
-
if (!language) {
|
|
46
|
+
const dictionary = await revalidate(targetLanguage, "foreground", config.cache);
|
|
47
|
+
if (!targetLanguage) {
|
|
62
48
|
throw new Error("Unable to get the language in Transmitter. Please check the getLanguage method in the configuration file or pass the language as an argument.");
|
|
63
49
|
}
|
|
64
50
|
return React.createElement(transmitterCore.TransmitterCore, { ...rest, language: targetLanguage, dictionary: dictionary });
|
|
65
51
|
};
|
|
66
|
-
const revalidate = async (language,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return item;
|
|
70
|
-
if (background) {
|
|
71
|
-
const newData = await loadTranslates(language, true);
|
|
52
|
+
const revalidate = async (language, mode, optional) => {
|
|
53
|
+
if (mode === "background") {
|
|
54
|
+
const newData = await loadTranslates(language, optional);
|
|
72
55
|
return newData;
|
|
73
56
|
}
|
|
74
|
-
const newDataPromise = loadTranslates(language,
|
|
57
|
+
const newDataPromise = loadTranslates(language, optional);
|
|
75
58
|
cache.set(language, newDataPromise);
|
|
76
59
|
return newDataPromise;
|
|
77
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sources":["../../../src/initialize.tsx"],"sourcesContent":["import React from \"react\";\n\nimport { type Config, type Translates } from \"./types\";\nimport { getTranslationCore, type GetTranslationCoreOptions } from \"./lib/get-translation-core\";\nimport { TranslationCore, type TranslationCoreProps } from \"./lib/translation-core\";\nimport { TransmitterCore, type TransmitterCoreProps } from \"./lib/transmitter-core\";\n\nexport const initialize = (config: Config) => {\n const cache = new Map<string, Translates | Promise<Translates>>();\n\n const loadTranslates = async (language: string,
|
|
1
|
+
{"version":3,"file":"initialize.js","sources":["../../../src/initialize.tsx"],"sourcesContent":["import React from \"react\";\n\nimport { type Config, type Translates } from \"./types\";\nimport { getTranslationCore, type GetTranslationCoreOptions } from \"./lib/get-translation-core\";\nimport { TranslationCore, type TranslationCoreProps } from \"./lib/translation-core\";\nimport { TransmitterCore, type TransmitterCoreProps } from \"./lib/transmitter-core\";\n\nexport const initialize = (config: Config) => {\n const cache = new Map<string, Translates | Promise<Translates>>();\n\n const loadTranslates = async (language: string, optional?: boolean) => {\n const item = cache.get(language);\n\n const isPromise = item instanceof Promise;\n if (item && (isPromise || optional)) {\n if (isPromise) {\n const dictionary = await item;\n cache.set(language, dictionary);\n return dictionary;\n }\n return item;\n }\n\n const newData = await config.load(language);\n cache.set(language, newData);\n return newData;\n };\n\n const getTranslation = async (\n options?: Omit<GetTranslationCoreOptions, \"dictionary\" | \"language\"> & { language?: string },\n ) => {\n const { language, ...rest } = options || {};\n const targetLanguage = language || (await config.getLanguage());\n const dictionary = await revalidate(targetLanguage, \"foreground\", config.cache);\n\n if (!targetLanguage) {\n throw new Error(\n \"Unable to get the language in getTranslation. Please check the getLanguage method in the configuration file or pass the language as an argument.\",\n );\n }\n\n return getTranslationCore({ ...rest, language: targetLanguage, dictionary });\n };\n\n const ServerTranslation = async (\n props: Omit<TranslationCoreProps, \"dictionary\" | \"language\"> & { language?: string },\n ) => {\n const { language, ...rest } = props || {};\n const targetLanguage = language || (await config.getLanguage());\n const dictionary = await revalidate(targetLanguage, \"foreground\", config.cache);\n\n if (!targetLanguage) {\n throw new Error(\n \"Unable to get the language in ServerTranslation. Please check the getLanguage method in the configuration file or pass the language as an argument.\",\n );\n }\n\n return <TranslationCore {...rest} language={targetLanguage} dictionary={dictionary} />;\n };\n\n const Transmitter = async (\n options: Omit<TransmitterCoreProps, \"dictionary\" | \"language\"> & { language?: string },\n ) => {\n const { language, ...rest } = options || {};\n const targetLanguage = language || (await config.getLanguage());\n const dictionary = await revalidate(targetLanguage, \"foreground\", config.cache);\n\n if (!targetLanguage) {\n throw new Error(\n \"Unable to get the language in Transmitter. Please check the getLanguage method in the configuration file or pass the language as an argument.\",\n );\n }\n\n return <TransmitterCore {...rest} language={targetLanguage} dictionary={dictionary} />;\n };\n\n const revalidate = async (language: string, mode?: \"background\" | \"foreground\", optional?: boolean) => {\n if (mode === \"background\") {\n const newData = await loadTranslates(language, optional);\n return newData;\n }\n\n const newDataPromise = loadTranslates(language, optional);\n cache.set(language, newDataPromise);\n return newDataPromise;\n };\n\n return {\n Transmitter,\n ServerTranslation,\n getTranslation,\n revalidate,\n };\n};\n"],"names":["getTranslationCore","TranslationCore","TransmitterCore"],"mappings":";;;;;;;AAOO,MAAM,UAAU,GAAG,CAAC,MAAc,KAAI;AACzC,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,EAA4C;IAEjE,MAAM,cAAc,GAAG,OAAO,QAAgB,EAAE,QAAkB,KAAI;QAClE,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC;AAEhC,QAAA,MAAM,SAAS,GAAG,IAAI,YAAY,OAAO;QACzC,IAAI,IAAI,KAAK,SAAS,IAAI,QAAQ,CAAC,EAAE;YACjC,IAAI,SAAS,EAAE;AACX,gBAAA,MAAM,UAAU,GAAG,MAAM,IAAI;AAC7B,gBAAA,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC;AAC/B,gBAAA,OAAO,UAAU;YACrB;AACA,YAAA,OAAO,IAAI;QACf;QAEA,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;AAC3C,QAAA,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC;AAC5B,QAAA,OAAO,OAAO;AAClB,IAAA,CAAC;AAED,IAAA,MAAM,cAAc,GAAG,OACnB,OAA4F,KAC5F;QACA,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE;QAC3C,MAAM,cAAc,GAAG,QAAQ,KAAK,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;AAC/D,QAAA,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,c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AI,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,GAAI;AAC1F,IAAA,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,QAAgB,EAAE,IAAkC,EAAE,QAAkB,KAAI;AAClG,QAAA,IAAI,IAAI,KAAK,YAAY,EAAE;YACvB,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC;AACxD,YAAA,OAAO,OAAO;QAClB;QAEA,MAAM,cAAc,GAAG,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC;AACzD,QAAA,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC;AACnC,QAAA,OAAO,cAAc;AACzB,IAAA,CAAC;IAED,OAAO;QACH,WAAW;QACX,iBAAiB;QACjB,cAAc;QACd,UAAU;KACb;AACL;;;;"}
|
package/dist/esm/initialize.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ export declare const initialize: (config: Config) => {
|
|
|
7
7
|
Transmitter: (options: Omit<TransmitterCoreProps, "dictionary" | "language"> & {
|
|
8
8
|
language?: string;
|
|
9
9
|
}) => Promise<React.JSX.Element>;
|
|
10
|
-
ServerTranslation: (
|
|
10
|
+
ServerTranslation: (props: Omit<TranslationCoreProps, "dictionary" | "language"> & {
|
|
11
11
|
language?: string;
|
|
12
12
|
}) => Promise<React.JSX.Element>;
|
|
13
|
-
getTranslation: (options
|
|
13
|
+
getTranslation: (options?: Omit<GetTranslationCoreOptions, "dictionary" | "language"> & {
|
|
14
14
|
language?: string;
|
|
15
15
|
}) => Promise<import("./lib/get-translation-core").GetTranslationCoreReturnType>;
|
|
16
|
-
revalidate: (language: string, background?: boolean) => Promise<Translates>;
|
|
16
|
+
revalidate: (language: string, mode?: "background" | "foreground", optional?: boolean) => Promise<Translates>;
|
|
17
17
|
};
|
package/dist/esm/initialize.mjs
CHANGED
|
@@ -5,11 +5,15 @@ import { TransmitterCore } from './lib/transmitter-core.mjs';
|
|
|
5
5
|
|
|
6
6
|
const initialize = (config) => {
|
|
7
7
|
const cache = new Map();
|
|
8
|
-
const loadTranslates = async (language,
|
|
8
|
+
const loadTranslates = async (language, optional) => {
|
|
9
9
|
const item = cache.get(language);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const isPromise = item instanceof Promise;
|
|
11
|
+
if (item && (isPromise || optional)) {
|
|
12
|
+
if (isPromise) {
|
|
13
|
+
const dictionary = await item;
|
|
14
|
+
cache.set(language, dictionary);
|
|
15
|
+
return dictionary;
|
|
16
|
+
}
|
|
13
17
|
return item;
|
|
14
18
|
}
|
|
15
19
|
const newData = await config.load(language);
|
|
@@ -19,29 +23,17 @@ const initialize = (config) => {
|
|
|
19
23
|
const getTranslation = async (options) => {
|
|
20
24
|
const { language, ...rest } = options || {};
|
|
21
25
|
const targetLanguage = language || (await config.getLanguage());
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
dictionary = await loadTranslates(targetLanguage);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
dictionary = await revalidate(targetLanguage);
|
|
28
|
-
}
|
|
29
|
-
if (!language) {
|
|
26
|
+
const dictionary = await revalidate(targetLanguage, "foreground", config.cache);
|
|
27
|
+
if (!targetLanguage) {
|
|
30
28
|
throw new Error("Unable to get the language in getTranslation. Please check the getLanguage method in the configuration file or pass the language as an argument.");
|
|
31
29
|
}
|
|
32
30
|
return getTranslationCore({ ...rest, language: targetLanguage, dictionary });
|
|
33
31
|
};
|
|
34
|
-
const ServerTranslation = async (
|
|
35
|
-
const { language, ...rest } =
|
|
32
|
+
const ServerTranslation = async (props) => {
|
|
33
|
+
const { language, ...rest } = props || {};
|
|
36
34
|
const targetLanguage = language || (await config.getLanguage());
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
dictionary = await loadTranslates(targetLanguage);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
dictionary = await revalidate(targetLanguage);
|
|
43
|
-
}
|
|
44
|
-
if (!language) {
|
|
35
|
+
const dictionary = await revalidate(targetLanguage, "foreground", config.cache);
|
|
36
|
+
if (!targetLanguage) {
|
|
45
37
|
throw new Error("Unable to get the language in ServerTranslation. Please check the getLanguage method in the configuration file or pass the language as an argument.");
|
|
46
38
|
}
|
|
47
39
|
return React.createElement(TranslationCore, { ...rest, language: targetLanguage, dictionary: dictionary });
|
|
@@ -49,27 +41,18 @@ const initialize = (config) => {
|
|
|
49
41
|
const Transmitter = async (options) => {
|
|
50
42
|
const { language, ...rest } = options || {};
|
|
51
43
|
const targetLanguage = language || (await config.getLanguage());
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
dictionary = await loadTranslates(targetLanguage);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
dictionary = await revalidate(targetLanguage);
|
|
58
|
-
}
|
|
59
|
-
if (!language) {
|
|
44
|
+
const dictionary = await revalidate(targetLanguage, "foreground", config.cache);
|
|
45
|
+
if (!targetLanguage) {
|
|
60
46
|
throw new Error("Unable to get the language in Transmitter. Please check the getLanguage method in the configuration file or pass the language as an argument.");
|
|
61
47
|
}
|
|
62
48
|
return React.createElement(TransmitterCore, { ...rest, language: targetLanguage, dictionary: dictionary });
|
|
63
49
|
};
|
|
64
|
-
const revalidate = async (language,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return item;
|
|
68
|
-
if (background) {
|
|
69
|
-
const newData = await loadTranslates(language, true);
|
|
50
|
+
const revalidate = async (language, mode, optional) => {
|
|
51
|
+
if (mode === "background") {
|
|
52
|
+
const newData = await loadTranslates(language, optional);
|
|
70
53
|
return newData;
|
|
71
54
|
}
|
|
72
|
-
const newDataPromise = loadTranslates(language,
|
|
55
|
+
const newDataPromise = loadTranslates(language, optional);
|
|
73
56
|
cache.set(language, newDataPromise);
|
|
74
57
|
return newDataPromise;
|
|
75
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.mjs","sources":["../../../src/initialize.tsx"],"sourcesContent":["import React from \"react\";\n\nimport { type Config, type Translates } from \"./types\";\nimport { getTranslationCore, type GetTranslationCoreOptions } from \"./lib/get-translation-core\";\nimport { TranslationCore, type TranslationCoreProps } from \"./lib/translation-core\";\nimport { TransmitterCore, type TransmitterCoreProps } from \"./lib/transmitter-core\";\n\nexport const initialize = (config: Config) => {\n const cache = new Map<string, Translates | Promise<Translates>>();\n\n const loadTranslates = async (language: string,
|
|
1
|
+
{"version":3,"file":"initialize.mjs","sources":["../../../src/initialize.tsx"],"sourcesContent":["import React from \"react\";\n\nimport { type Config, type Translates } from \"./types\";\nimport { getTranslationCore, type GetTranslationCoreOptions } from \"./lib/get-translation-core\";\nimport { TranslationCore, type TranslationCoreProps } from \"./lib/translation-core\";\nimport { TransmitterCore, type TransmitterCoreProps } from \"./lib/transmitter-core\";\n\nexport const initialize = (config: Config) => {\n const cache = new Map<string, Translates | Promise<Translates>>();\n\n const loadTranslates = async (language: string, optional?: boolean) => {\n const item = cache.get(language);\n\n const isPromise = item instanceof Promise;\n if (item && (isPromise || optional)) {\n if (isPromise) {\n const dictionary = await item;\n cache.set(language, dictionary);\n return dictionary;\n }\n return item;\n }\n\n const newData = await config.load(language);\n cache.set(language, newData);\n return newData;\n };\n\n const getTranslation = async (\n options?: Omit<GetTranslationCoreOptions, \"dictionary\" | \"language\"> & { language?: string },\n ) => {\n const { language, ...rest } = options || {};\n const targetLanguage = language || (await config.getLanguage());\n const dictionary = await revalidate(targetLanguage, \"foreground\", config.cache);\n\n if (!targetLanguage) {\n throw new Error(\n \"Unable to get the language in getTranslation. Please check the getLanguage method in the configuration file or pass the language as an argument.\",\n );\n }\n\n return getTranslationCore({ ...rest, language: targetLanguage, dictionary });\n };\n\n const ServerTranslation = async (\n props: Omit<TranslationCoreProps, \"dictionary\" | \"language\"> & { language?: string },\n ) => {\n const { language, ...rest } = props || {};\n const targetLanguage = language || (await config.getLanguage());\n const dictionary = await revalidate(targetLanguage, \"foreground\", config.cache);\n\n if (!targetLanguage) {\n throw new Error(\n \"Unable to get the language in ServerTranslation. Please check the getLanguage method in the configuration file or pass the language as an argument.\",\n );\n }\n\n return <TranslationCore {...rest} language={targetLanguage} dictionary={dictionary} />;\n };\n\n const Transmitter = async (\n options: Omit<TransmitterCoreProps, \"dictionary\" | \"language\"> & { language?: string },\n ) => {\n const { language, ...rest } = options || {};\n const targetLanguage = language || (await config.getLanguage());\n const dictionary = await revalidate(targetLanguage, \"foreground\", config.cache);\n\n if (!targetLanguage) {\n throw new Error(\n \"Unable to get the language in Transmitter. Please check the getLanguage method in the configuration file or pass the language as an argument.\",\n );\n }\n\n return <TransmitterCore {...rest} language={targetLanguage} dictionary={dictionary} />;\n };\n\n const revalidate = async (language: string, mode?: \"background\" | \"foreground\", optional?: boolean) => {\n if (mode === \"background\") {\n const newData = await loadTranslates(language, optional);\n return newData;\n }\n\n const newDataPromise = loadTranslates(language, optional);\n cache.set(language, newDataPromise);\n return newDataPromise;\n };\n\n return {\n Transmitter,\n ServerTranslation,\n getTranslation,\n revalidate,\n };\n};\n"],"names":[],"mappings":";;;;;AAOO,MAAM,UAAU,GAAG,CAAC,MAAc,KAAI;AACzC,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,EAA4C;IAEjE,MAAM,cAAc,GAAG,OAAO,QAAgB,EAAE,QAAkB,KAAI;QAClE,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC;AAEhC,QAAA,MAAM,SAAS,GAAG,IAAI,YAAY,OAAO;QACzC,IAAI,IAAI,KAAK,SAAS,IAAI,QAAQ,CAAC,EAAE;YACjC,IAAI,SAAS,EAAE;AACX,gBAAA,MAAM,UAAU,GAAG,MAAM,IAAI;AAC7B,gBAAA,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC;AAC/B,gBAAA,OAAO,UAAU;YACrB;AACA,YAAA,OAAO,IAAI;QACf;QAEA,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;AAC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OAAO,IAAI,EAAE;QAC3C,MAAM,cAAc,GAAG,QAAQ,KAAK,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;AAC/D,QAAA,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,cAAc,EAAE,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC;QAE/E,IAAI,CAAC,cAAc,EAAE;AACjB,YAAA,MAAM,IAAI,KAAK,CACX,+IAA+I,CAClJ;QACL;AAEA,QAAA,OAAO,KAAA,CAAA,aAAA,CAAC,eAAe,EAAA,EAAA,GAAK,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,GAAI;AAC1F,IAAA,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,QAAgB,EAAE,IAAkC,EAAE,QAAkB,KAAI;AAClG,QAAA,IAAI,IAAI,KAAK,YAAY,EAAE;YACvB,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC;AACxD,YAAA,OAAO,OAAO;QAClB;QAEA,MAAM,cAAc,GAAG,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC;AACzD,QAAA,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC;AACnC,QAAA,OAAO,cAAc;AACzB,IAAA,CAAC;IAED,OAAO;QACH,WAAW;QACX,iBAAiB;QACjB,cAAc;QACd,UAAU;KACb;AACL;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimpl/i18n",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-b4eb49b",
|
|
4
4
|
"description": "i18n library for working with translations in server and client components",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"module": "dist/esm/initialize.mjs",
|
|
10
10
|
"types": "dist/cjs/initialize.d.ts",
|
|
11
11
|
"exports": {
|
|
12
|
-
"
|
|
13
|
-
"types": "./dist/cjs/
|
|
14
|
-
"import": "./dist/esm/
|
|
15
|
-
"require": "./dist/cjs/
|
|
16
|
-
"default": "./dist/esm/
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/cjs/initialize.d.ts",
|
|
14
|
+
"import": "./dist/esm/initialize.mjs",
|
|
15
|
+
"require": "./dist/cjs/initialize.js",
|
|
16
|
+
"default": "./dist/esm/initialize.mjs"
|
|
17
17
|
},
|
|
18
18
|
"./initialize": {
|
|
19
19
|
"types": "./dist/cjs/initialize.d.ts",
|
|
@@ -21,6 +21,12 @@
|
|
|
21
21
|
"require": "./dist/cjs/initialize.js",
|
|
22
22
|
"default": "./dist/esm/initialize.mjs"
|
|
23
23
|
},
|
|
24
|
+
"./client-translation": {
|
|
25
|
+
"types": "./dist/cjs/client-translation.d.ts",
|
|
26
|
+
"import": "./dist/esm/client-translation.mjs",
|
|
27
|
+
"require": "./dist/cjs/client-translation.js",
|
|
28
|
+
"default": "./dist/esm/client-translation.mjs"
|
|
29
|
+
},
|
|
24
30
|
"./types": {
|
|
25
31
|
"types": "./dist/cjs/types.d.ts",
|
|
26
32
|
"import": "./dist/esm/types.mjs",
|