@next-core/i18n 1.0.46 → 1.0.48
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/text.js +1 -2
- package/dist/cjs/text.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/init.js +3 -3
- package/dist/esm/init.js.map +1 -1
- package/dist/esm/react.js +1 -1
- package/dist/esm/text.js +4 -5
- package/dist/esm/text.js.map +1 -1
- package/package.json +5 -5
package/dist/cjs/text.js
CHANGED
|
@@ -7,11 +7,10 @@ exports.i18nText = i18nText;
|
|
|
7
7
|
var _i18n = require("@next-core/i18n");
|
|
8
8
|
var _general = require("@next-core/utils/general");
|
|
9
9
|
function i18nText(data) {
|
|
10
|
-
var _i18n$language;
|
|
11
10
|
if (!data) {
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
14
|
-
const language =
|
|
13
|
+
const language = _i18n.i18n.language ?? "zh-CN";
|
|
15
14
|
// First, make a perfect match.
|
|
16
15
|
if ((0, _general.hasOwnProperty)(data, language)) {
|
|
17
16
|
return data[language];
|
package/dist/cjs/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","names":["_i18n","require","_general","i18nText","data","
|
|
1
|
+
{"version":3,"file":"text.js","names":["_i18n","require","_general","i18nText","data","language","i18n","hasOwnProperty","primaryLanguage","split","undefined","prefix","key","Object","keys","startsWith"],"sources":["../../src/text.ts"],"sourcesContent":["import { i18n } from \"@next-core/i18n\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { I18nData } from \"@next-core/types\";\n\nexport function i18nText(\n data: I18nData | null | undefined\n): string | undefined {\n if (!data) {\n return;\n }\n const language = i18n.language ?? \"zh-CN\";\n // First, make a perfect match.\n if (hasOwnProperty(data, language)) {\n return data[language];\n }\n // https://en.wikipedia.org/wiki/IETF_language_tag\n const primaryLanguage = language.split(\"-\")[0];\n if (primaryLanguage !== language) {\n // Then, match the primary language (which omits other subtags).\n // E.g., match `zh` if the current language is `zh-CN`.\n return hasOwnProperty(data, primaryLanguage)\n ? data[primaryLanguage]\n : undefined;\n }\n // At last, match the first key which starts with the primary language,\n // if the current language contains primary subtag only.\n // E.g., match `zh-CN` if the current language is `zh`.\n const prefix = `${primaryLanguage}-`;\n for (const key of Object.keys(data)) {\n if (key.startsWith(prefix)) {\n return data[key];\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAGO,SAASE,QAAQA,CACtBC,IAAiC,EACb;EACpB,IAAI,CAACA,IAAI,EAAE;IACT;EACF;EACA,MAAMC,QAAQ,GAAGC,UAAI,CAACD,QAAQ,IAAI,OAAO;EACzC;EACA,IAAI,IAAAE,uBAAc,EAACH,IAAI,EAAEC,QAAQ,CAAC,EAAE;IAClC,OAAOD,IAAI,CAACC,QAAQ,CAAC;EACvB;EACA;EACA,MAAMG,eAAe,GAAGH,QAAQ,CAACI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EAC9C,IAAID,eAAe,KAAKH,QAAQ,EAAE;IAChC;IACA;IACA,OAAO,IAAAE,uBAAc,EAACH,IAAI,EAAEI,eAAe,CAAC,GACxCJ,IAAI,CAACI,eAAe,CAAC,GACrBE,SAAS;EACf;EACA;EACA;EACA;EACA,MAAMC,MAAM,GAAG,GAAGH,eAAe,GAAG;EACpC,KAAK,MAAMI,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACV,IAAI,CAAC,EAAE;IACnC,IAAIQ,GAAG,CAACG,UAAU,CAACJ,MAAM,CAAC,EAAE;MAC1B,OAAOP,IAAI,CAACQ,GAAG,CAAC;IAClB;EACF;AACF","ignoreList":[]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import i18next from "i18next";
|
|
2
|
-
export
|
|
2
|
+
export const i18n = process.env.NODE_ENV === "test" ? i18next : /* istanbul ignore next */i18next.default;
|
|
3
3
|
export * from "./init.js";
|
|
4
4
|
export * from "./text.js";
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["i18next","i18n","process","env","NODE_ENV","default"],"sources":["../../src/index.ts"],"sourcesContent":["import i18next from \"i18next\";\n\nexport const i18n =\n process.env.NODE_ENV === \"test\"\n ? (i18next as unknown as typeof i18next.default)\n : /* istanbul ignore next */ i18next.default;\n\nexport * from \"./init.js\";\nexport * from \"./text.js\";\n"],"mappings":"AAAA,OAAOA,OAAO,MAAM,SAAS;AAE7B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","names":["i18next","i18n","process","env","NODE_ENV","default"],"sources":["../../src/index.ts"],"sourcesContent":["import i18next from \"i18next\";\n\nexport const i18n =\n process.env.NODE_ENV === \"test\"\n ? (i18next as unknown as typeof i18next.default)\n : /* istanbul ignore next */ i18next.default;\n\nexport * from \"./init.js\";\nexport * from \"./text.js\";\n"],"mappings":"AAAA,OAAOA,OAAO,MAAM,SAAS;AAE7B,OAAO,MAAMC,IAAI,GACfC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,GAC1BJ,OAAO,GACR,0BAA2BA,OAAO,CAACK,OAAO;AAEhD,cAAc,WAAW;AACzB,cAAc,WAAW","ignoreList":[]}
|
package/dist/esm/init.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i18n } from "@next-core/i18n";
|
|
2
2
|
import LanguageDetector from "i18next-browser-languagedetector";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
let initialized = false;
|
|
4
|
+
const initializedNamespaces = new Set();
|
|
5
5
|
export function initializeI18n(NS, locales) {
|
|
6
6
|
if (!initialized) {
|
|
7
7
|
initialized = true;
|
|
@@ -30,7 +30,7 @@ export function initializeI18n(NS, locales) {
|
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
initializedNamespaces.add(NS);
|
|
33
|
-
for (
|
|
33
|
+
for (const [lang, resources] of Object.entries(locales)) {
|
|
34
34
|
i18n.addResourceBundle(lang, NS, resources);
|
|
35
35
|
}
|
|
36
36
|
}
|
package/dist/esm/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","names":["i18n","LanguageDetector","initialized","initializedNamespaces","Set","initializeI18n","NS","locales","use","process","env","NODE_ENV","default","init","fallbackLng","debug","supportedLngs","nonExplicitSupportedLngs","interpolation","escapeValue","react","useSuspense","compatibilityJSON","resources","has","add","lang","Object","entries","addResourceBundle"],"sources":["../../src/init.ts"],"sourcesContent":["import { i18n } from \"@next-core/i18n\";\nimport LanguageDetector from \"i18next-browser-languagedetector\";\n\nlet initialized = false;\nconst initializedNamespaces = new Set<string>();\n\nexport type Locales = Record<string, Record<string, string | undefined>>;\n\nexport function initializeI18n(): void;\nexport function initializeI18n(NS: string, locales: Locales): void;\nexport function initializeI18n(NS?: string, locales?: Locales) {\n if (!initialized) {\n initialized = true;\n i18n\n // learn more: https://github.com/i18next/i18next-xhr-backend\n // .use(Backend)\n // learn more: https://github.com/i18next/i18next-browser-languageDetector\n .use(\n process.env.NODE_ENV === \"test\"\n ? LanguageDetector\n : /* istanbul ignore next */ (\n LanguageDetector as unknown as { default: LanguageDetector }\n ).default\n )\n // for all options read: https://www.i18next.com/overview/configuration-options\n .init({\n fallbackLng: \"zh\",\n debug: process.env.NODE_ENV === \"development\",\n supportedLngs: [\"zh\", \"en\"],\n nonExplicitSupportedLngs: true,\n interpolation: {\n escapeValue: false, // not needed for react as it escapes by default\n },\n react: {\n useSuspense: false,\n },\n compatibilityJSON: \"v3\",\n resources: {},\n });\n }\n\n if (!NS || !locales || initializedNamespaces.has(NS)) {\n return;\n }\n initializedNamespaces.add(NS);\n for (const [lang, resources] of Object.entries(locales)) {\n i18n.addResourceBundle(lang, NS, resources);\n }\n}\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,iBAAiB;AACtC,OAAOC,gBAAgB,MAAM,kCAAkC;AAE/D,IAAIC,WAAW,GAAG,KAAK;AACvB,
|
|
1
|
+
{"version":3,"file":"init.js","names":["i18n","LanguageDetector","initialized","initializedNamespaces","Set","initializeI18n","NS","locales","use","process","env","NODE_ENV","default","init","fallbackLng","debug","supportedLngs","nonExplicitSupportedLngs","interpolation","escapeValue","react","useSuspense","compatibilityJSON","resources","has","add","lang","Object","entries","addResourceBundle"],"sources":["../../src/init.ts"],"sourcesContent":["import { i18n } from \"@next-core/i18n\";\nimport LanguageDetector from \"i18next-browser-languagedetector\";\n\nlet initialized = false;\nconst initializedNamespaces = new Set<string>();\n\nexport type Locales = Record<string, Record<string, string | undefined>>;\n\nexport function initializeI18n(): void;\nexport function initializeI18n(NS: string, locales: Locales): void;\nexport function initializeI18n(NS?: string, locales?: Locales) {\n if (!initialized) {\n initialized = true;\n i18n\n // learn more: https://github.com/i18next/i18next-xhr-backend\n // .use(Backend)\n // learn more: https://github.com/i18next/i18next-browser-languageDetector\n .use(\n process.env.NODE_ENV === \"test\"\n ? LanguageDetector\n : /* istanbul ignore next */ (\n LanguageDetector as unknown as { default: LanguageDetector }\n ).default\n )\n // for all options read: https://www.i18next.com/overview/configuration-options\n .init({\n fallbackLng: \"zh\",\n debug: process.env.NODE_ENV === \"development\",\n supportedLngs: [\"zh\", \"en\"],\n nonExplicitSupportedLngs: true,\n interpolation: {\n escapeValue: false, // not needed for react as it escapes by default\n },\n react: {\n useSuspense: false,\n },\n compatibilityJSON: \"v3\",\n resources: {},\n });\n }\n\n if (!NS || !locales || initializedNamespaces.has(NS)) {\n return;\n }\n initializedNamespaces.add(NS);\n for (const [lang, resources] of Object.entries(locales)) {\n i18n.addResourceBundle(lang, NS, resources);\n }\n}\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,iBAAiB;AACtC,OAAOC,gBAAgB,MAAM,kCAAkC;AAE/D,IAAIC,WAAW,GAAG,KAAK;AACvB,MAAMC,qBAAqB,GAAG,IAAIC,GAAG,CAAS,CAAC;AAM/C,OAAO,SAASC,cAAcA,CAACC,EAAW,EAAEC,OAAiB,EAAE;EAC7D,IAAI,CAACL,WAAW,EAAE;IAChBA,WAAW,GAAG,IAAI;IAClBF;IACE;IACA;IACA;IAAA,CACCQ,GAAG,CACFC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,GAC3BV,gBAAgB,GAChB,0BACEA,gBAAgB,CAChBW,OACR;IACA;IAAA,CACCC,IAAI,CAAC;MACJC,WAAW,EAAE,IAAI;MACjBC,KAAK,EAAEN,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,aAAa;MAC7CK,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;MAC3BC,wBAAwB,EAAE,IAAI;MAC9BC,aAAa,EAAE;QACbC,WAAW,EAAE,KAAK,CAAE;MACtB,CAAC;MACDC,KAAK,EAAE;QACLC,WAAW,EAAE;MACf,CAAC;MACDC,iBAAiB,EAAE,IAAI;MACvBC,SAAS,EAAE,CAAC;IACd,CAAC,CAAC;EACN;EAEA,IAAI,CAACjB,EAAE,IAAI,CAACC,OAAO,IAAIJ,qBAAqB,CAACqB,GAAG,CAAClB,EAAE,CAAC,EAAE;IACpD;EACF;EACAH,qBAAqB,CAACsB,GAAG,CAACnB,EAAE,CAAC;EAC7B,KAAK,MAAM,CAACoB,IAAI,EAAEH,SAAS,CAAC,IAAII,MAAM,CAACC,OAAO,CAACrB,OAAO,CAAC,EAAE;IACvDP,IAAI,CAAC6B,iBAAiB,CAACH,IAAI,EAAEpB,EAAE,EAAEiB,SAAS,CAAC;EAC7C;AACF","ignoreList":[]}
|
package/dist/esm/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i18n, initializeI18n } from "@next-core/i18n";
|
|
2
2
|
import { initReactI18next, useTranslation } from "react-i18next";
|
|
3
|
-
|
|
3
|
+
let initialized = false;
|
|
4
4
|
export function initializeReactI18n(NS, locales) {
|
|
5
5
|
initializeI18n(NS, locales);
|
|
6
6
|
if (!initialized) {
|
package/dist/esm/text.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { i18n } from "@next-core/i18n";
|
|
2
2
|
import { hasOwnProperty } from "@next-core/utils/general";
|
|
3
3
|
export function i18nText(data) {
|
|
4
|
-
var _i18n$language;
|
|
5
4
|
if (!data) {
|
|
6
5
|
return;
|
|
7
6
|
}
|
|
8
|
-
|
|
7
|
+
const language = i18n.language ?? "zh-CN";
|
|
9
8
|
// First, make a perfect match.
|
|
10
9
|
if (hasOwnProperty(data, language)) {
|
|
11
10
|
return data[language];
|
|
12
11
|
}
|
|
13
12
|
// https://en.wikipedia.org/wiki/IETF_language_tag
|
|
14
|
-
|
|
13
|
+
const primaryLanguage = language.split("-")[0];
|
|
15
14
|
if (primaryLanguage !== language) {
|
|
16
15
|
// Then, match the primary language (which omits other subtags).
|
|
17
16
|
// E.g., match `zh` if the current language is `zh-CN`.
|
|
@@ -20,8 +19,8 @@ export function i18nText(data) {
|
|
|
20
19
|
// At last, match the first key which starts with the primary language,
|
|
21
20
|
// if the current language contains primary subtag only.
|
|
22
21
|
// E.g., match `zh-CN` if the current language is `zh`.
|
|
23
|
-
|
|
24
|
-
for (
|
|
22
|
+
const prefix = `${primaryLanguage}-`;
|
|
23
|
+
for (const key of Object.keys(data)) {
|
|
25
24
|
if (key.startsWith(prefix)) {
|
|
26
25
|
return data[key];
|
|
27
26
|
}
|
package/dist/esm/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","names":["i18n","hasOwnProperty","i18nText","data","
|
|
1
|
+
{"version":3,"file":"text.js","names":["i18n","hasOwnProperty","i18nText","data","language","primaryLanguage","split","undefined","prefix","key","Object","keys","startsWith"],"sources":["../../src/text.ts"],"sourcesContent":["import { i18n } from \"@next-core/i18n\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { I18nData } from \"@next-core/types\";\n\nexport function i18nText(\n data: I18nData | null | undefined\n): string | undefined {\n if (!data) {\n return;\n }\n const language = i18n.language ?? \"zh-CN\";\n // First, make a perfect match.\n if (hasOwnProperty(data, language)) {\n return data[language];\n }\n // https://en.wikipedia.org/wiki/IETF_language_tag\n const primaryLanguage = language.split(\"-\")[0];\n if (primaryLanguage !== language) {\n // Then, match the primary language (which omits other subtags).\n // E.g., match `zh` if the current language is `zh-CN`.\n return hasOwnProperty(data, primaryLanguage)\n ? data[primaryLanguage]\n : undefined;\n }\n // At last, match the first key which starts with the primary language,\n // if the current language contains primary subtag only.\n // E.g., match `zh-CN` if the current language is `zh`.\n const prefix = `${primaryLanguage}-`;\n for (const key of Object.keys(data)) {\n if (key.startsWith(prefix)) {\n return data[key];\n }\n }\n}\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,iBAAiB;AACtC,SAASC,cAAc,QAAQ,0BAA0B;AAGzD,OAAO,SAASC,QAAQA,CACtBC,IAAiC,EACb;EACpB,IAAI,CAACA,IAAI,EAAE;IACT;EACF;EACA,MAAMC,QAAQ,GAAGJ,IAAI,CAACI,QAAQ,IAAI,OAAO;EACzC;EACA,IAAIH,cAAc,CAACE,IAAI,EAAEC,QAAQ,CAAC,EAAE;IAClC,OAAOD,IAAI,CAACC,QAAQ,CAAC;EACvB;EACA;EACA,MAAMC,eAAe,GAAGD,QAAQ,CAACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EAC9C,IAAID,eAAe,KAAKD,QAAQ,EAAE;IAChC;IACA;IACA,OAAOH,cAAc,CAACE,IAAI,EAAEE,eAAe,CAAC,GACxCF,IAAI,CAACE,eAAe,CAAC,GACrBE,SAAS;EACf;EACA;EACA;EACA;EACA,MAAMC,MAAM,GAAG,GAAGH,eAAe,GAAG;EACpC,KAAK,MAAMI,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACR,IAAI,CAAC,EAAE;IACnC,IAAIM,GAAG,CAACG,UAAU,CAACJ,MAAM,CAAC,EAAE;MAC1B,OAAOL,IAAI,CAACM,GAAG,CAAC;IAClB;EACF;AACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/i18n",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.48",
|
|
4
4
|
"homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/i18n",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"repository": {
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@next-core/types": "^1.11.0",
|
|
43
|
-
"@next-core/utils": "^1.7.
|
|
43
|
+
"@next-core/utils": "^1.7.6",
|
|
44
44
|
"i18next": "^22.5.1",
|
|
45
45
|
"i18next-browser-languagedetector": "^7.2.1",
|
|
46
46
|
"react-i18next": "^12.3.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@next-core/build-next-libs": "^1.0.
|
|
50
|
-
"@next-core/test-next": "^1.1.
|
|
49
|
+
"@next-core/build-next-libs": "^1.0.16",
|
|
50
|
+
"@next-core/test-next": "^1.1.2"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "34346d51d4a58dbf496de22f2f06a3dd43dae52d"
|
|
53
53
|
}
|