@prosopo/locale 3.2.7 → 3.2.8

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.
Files changed (37) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +20 -20
  2. package/.turbo/turbo-build$colon$tsc.log +5 -5
  3. package/.turbo/turbo-build.log +22 -19
  4. package/CHANGELOG.md +6 -0
  5. package/dist/_virtual/_rolldown/runtime.js +3 -0
  6. package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
  7. package/dist/cjs/i18SharedOptions.cjs +8 -10
  8. package/dist/cjs/i18nBackend.cjs +29 -29
  9. package/dist/cjs/i18nFrontend.cjs +54 -61
  10. package/dist/cjs/i18nMiddleware.cjs +7 -6
  11. package/dist/cjs/index.cjs +13 -14
  12. package/dist/cjs/loadI18next.cjs +23 -33
  13. package/dist/cjs/locales/en/translation.cjs +487 -0
  14. package/dist/cjs/translationKey.cjs +14 -22
  15. package/dist/cjs/translations.cjs +39 -39
  16. package/dist/cjs/useTranslation.cjs +10 -6
  17. package/dist/cjs/util.cjs +6 -6
  18. package/dist/i18SharedOptions.js +9 -11
  19. package/dist/i18nBackend.js +25 -28
  20. package/dist/i18nFrontend.js +45 -57
  21. package/dist/i18nMiddleware.d.ts +2 -1
  22. package/dist/i18nMiddleware.d.ts.map +1 -1
  23. package/dist/i18nMiddleware.js +5 -6
  24. package/dist/i18nMiddleware.js.map +1 -1
  25. package/dist/index.js +5 -12
  26. package/dist/loadI18next.js +23 -34
  27. package/dist/locales/en/translation.js +473 -0
  28. package/dist/translationKey.js +15 -23
  29. package/dist/translations.js +37 -40
  30. package/dist/useTranslation.js +10 -8
  31. package/dist/util.js +7 -8
  32. package/package.json +6 -6
  33. package/src/i18nMiddleware.ts +6 -1
  34. package/tsconfig.tsbuildinfo +1 -1
  35. package/.turbo/turbo-typecheck.log +0 -4
  36. package/dist/cjs/locales/en/translation.json.cjs +0 -47
  37. package/dist/locales/en/translation.json.js +0 -47
@@ -1,32 +1,29 @@
1
- import path from "node:path";
1
+ import "./_virtual/_rolldown/runtime.js";
2
+ import { isServerSide } from "./util.js";
3
+ import { i18nSharedOptions } from "./i18SharedOptions.js";
4
+ import { LanguageDetector } from "i18next-http-middleware";
2
5
  import i18n from "i18next";
6
+ import path from "node:path";
3
7
  import FSBackend from "i18next-fs-backend/cjs";
4
- import { LanguageDetector } from "i18next-http-middleware";
5
- import { i18nSharedOptions } from "./i18SharedOptions.js";
6
- import { isServerSide } from "./util.js";
7
- const loadPath = `${path.dirname(import.meta.url)}/locales/{{lng}}/{{ns}}.json`.replace(
8
- "file://",
9
- ""
10
- );
8
+ //#region src/i18nBackend.ts
9
+ var loadPath = `${path.dirname(import.meta.url)}/locales/{{lng}}/{{ns}}.json`.replace("file://", "");
11
10
  function initializeI18n(i18nLoadedCallback) {
12
- if (!i18n.isInitialized && isServerSide()) {
13
- const lngDetector = new LanguageDetector(null, {
14
- order: ["header", "query", "cookie"]
15
- });
16
- i18n.use(FSBackend).use(lngDetector).init({
17
- ...i18nSharedOptions,
18
- ns: ["translation"],
19
- backend: {
20
- loadPath
21
- }
22
- });
23
- i18n.on("loaded", () => {
24
- i18nLoadedCallback?.(i18n);
25
- });
26
- }
27
- return i18n;
11
+ if (!i18n.isInitialized && isServerSide()) {
12
+ const lngDetector = new LanguageDetector(null, { order: [
13
+ "header",
14
+ "query",
15
+ "cookie"
16
+ ] });
17
+ i18n.use(FSBackend).use(lngDetector).init({
18
+ ...i18nSharedOptions,
19
+ ns: ["translation"],
20
+ backend: { loadPath }
21
+ });
22
+ i18n.on("loaded", () => {
23
+ i18nLoadedCallback?.(i18n);
24
+ });
25
+ }
26
+ return i18n;
28
27
  }
29
- export {
30
- initializeI18n as default,
31
- initializeI18n
32
- };
28
+ //#endregion
29
+ export { initializeI18n as default, initializeI18n };
@@ -1,66 +1,54 @@
1
+ import "./_virtual/_rolldown/runtime.js";
2
+ import { i18nSharedOptions } from "./i18SharedOptions.js";
3
+ import { initReactI18next } from "react-i18next";
1
4
  import i18n from "i18next";
2
5
  import I18nextBrowserLanguageDetector from "i18next-browser-languagedetector";
3
6
  import ChainedBackend from "i18next-chained-backend";
4
7
  import HttpBackend from "i18next-http-backend";
5
8
  import resourcesToBackend from "i18next-resources-to-backend";
6
- import { initReactI18next } from "react-i18next";
7
- import { i18nSharedOptions } from "./i18SharedOptions.js";
8
- const reactOptions = {
9
- react: {
10
- useSuspense: true
11
- },
12
- detection: {
13
- order: ["navigator", "htmlTag", "path", "subdomain"],
14
- caches: ["localStorage", "cookie"]
15
- }
9
+ //#region src/i18nFrontend.ts
10
+ var reactOptions = {
11
+ react: { useSuspense: true },
12
+ detection: {
13
+ order: [
14
+ "navigator",
15
+ "htmlTag",
16
+ "path",
17
+ "subdomain"
18
+ ],
19
+ caches: ["localStorage", "cookie"]
20
+ }
16
21
  };
17
- const getLoadPath = (language, namespace) => {
18
- const filename = import.meta.url.split("/").pop();
19
- return `${import.meta.url.replace(`/${filename}`, "")}/locales/${language}/${namespace}.json`;
22
+ var getLoadPath = (language, namespace) => {
23
+ const filename = import.meta.url.split("/").pop();
24
+ return `${import.meta.url.replace(`/${filename}`, "")}/locales/${language}/${namespace}.json`;
20
25
  };
21
26
  function initializeI18n(i18nLoadedCallback, lng) {
22
- if (!i18n.isInitialized) {
23
- i18n.use(ChainedBackend).use(
24
- new I18nextBrowserLanguageDetector(null, {
25
- order: ["cookie", "localStorage", "navigator"],
26
- lookupQuerystring: "lng",
27
- lookupCookie: "i18next",
28
- lookupLocalStorage: "i18nextLng",
29
- caches: ["localStorage", "cookie"]
30
- })
31
- ).use(initReactI18next).init({
32
- ...i18nSharedOptions,
33
- // When the site owner has resolved a language upfront (via widget
34
- // config or data-language) we set `lng` explicitly so i18next skips
35
- // browser detection. This is the single source of truth for the
36
- // widget language and prevents the flash-of-wrong-language race
37
- // where child components read the browser-detected language on
38
- // first render before an effect can call changeLanguage().
39
- ...lng ? { lng } : {},
40
- backend: {
41
- backends: [
42
- HttpBackend,
43
- // if a namespace can't be loaded via normal http-backend loadPath, then the inMemoryLocalBackend will try to return the correct resources
44
- // with dynamic import, you have to use the "default" key of the module ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#importing_defaults )
45
- resourcesToBackend(
46
- (language, namespace) => import(getLoadPath(language, namespace))
47
- )
48
- ],
49
- backendOptions: [
50
- {
51
- loadPath: getLoadPath("{{lng}}", "{{ns}}")
52
- }
53
- ]
54
- },
55
- ...reactOptions
56
- });
57
- i18n.on("loaded", () => {
58
- i18nLoadedCallback?.(i18n);
59
- });
60
- }
61
- return i18n;
27
+ if (!i18n.isInitialized) {
28
+ i18n.use(ChainedBackend).use(new I18nextBrowserLanguageDetector(null, {
29
+ order: [
30
+ "cookie",
31
+ "localStorage",
32
+ "navigator"
33
+ ],
34
+ lookupQuerystring: "lng",
35
+ lookupCookie: "i18next",
36
+ lookupLocalStorage: "i18nextLng",
37
+ caches: ["localStorage", "cookie"]
38
+ })).use(initReactI18next).init({
39
+ ...i18nSharedOptions,
40
+ ...lng ? { lng } : {},
41
+ backend: {
42
+ backends: [HttpBackend, resourcesToBackend((language, namespace) => import(getLoadPath(language, namespace)))],
43
+ backendOptions: [{ loadPath: getLoadPath("{{lng}}", "{{ns}}") }]
44
+ },
45
+ ...reactOptions
46
+ });
47
+ i18n.on("loaded", () => {
48
+ i18nLoadedCallback?.(i18n);
49
+ });
50
+ }
51
+ return i18n;
62
52
  }
63
- export {
64
- initializeI18n as default,
65
- initializeI18n
66
- };
53
+ //#endregion
54
+ export { initializeI18n as default, initializeI18n };
@@ -1,4 +1,5 @@
1
- import { type HandleOptions, handle } from "i18next-http-middleware";
1
+ import { handle } from "i18next-http-middleware";
2
+ type HandleOptions = NonNullable<Parameters<typeof handle>[1]>;
2
3
  declare function i18nMiddleware(options: HandleOptions): Promise<ReturnType<typeof handle>>;
3
4
  export default i18nMiddleware;
4
5
  //# sourceMappingURL=i18nMiddleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"i18nMiddleware.d.ts","sourceRoot":"","sources":["../src/i18nMiddleware.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGrE,iBAAe,cAAc,CAC5B,OAAO,EAAE,aAAa,GACpB,OAAO,CAAC,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAGpC;AAED,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"i18nMiddleware.d.ts","sourceRoot":"","sources":["../src/i18nMiddleware.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAMjD,KAAK,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/D,iBAAe,cAAc,CAC5B,OAAO,EAAE,aAAa,GACpB,OAAO,CAAC,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAGpC;AAED,eAAe,cAAc,CAAC"}
@@ -1,9 +1,8 @@
1
- import { handle } from "i18next-http-middleware";
2
1
  import loadI18next from "./loadI18next.js";
2
+ import { handle } from "i18next-http-middleware";
3
+ //#region src/i18nMiddleware.ts
3
4
  async function i18nMiddleware(options) {
4
- const i18n = await loadI18next(true);
5
- return handle(i18n, { ...options });
5
+ return handle(await loadI18next(true), { ...options });
6
6
  }
7
- export {
8
- i18nMiddleware as default
9
- };
7
+ //#endregion
8
+ export { i18nMiddleware as default };
@@ -1 +1 @@
1
- {"version":3,"file":"i18nMiddleware.js","sourceRoot":"","sources":["../src/i18nMiddleware.ts"],"names":[],"mappings":"AAcA,OAAO,EAAsB,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAE3C,KAAK,UAAU,cAAc,CAC5B,OAAsB;IAEtB,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"i18nMiddleware.js","sourceRoot":"","sources":["../src/i18nMiddleware.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAO3C,KAAK,UAAU,cAAc,CAC5B,OAAsB;IAEtB,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,eAAe,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,15 +1,8 @@
1
- import { default as default2 } from "./i18nMiddleware.js";
2
- import { default as default3 } from "./loadI18next.js";
1
+ import "./_virtual/_rolldown/runtime.js";
2
+ import loadI18next from "./loadI18next.js";
3
+ import i18nMiddleware from "./i18nMiddleware.js";
3
4
  import { LanguageSchema, Languages } from "./translations.js";
4
5
  import { isClientSide } from "./util.js";
5
6
  import { TranslationKeysSchema } from "./translationKey.js";
6
- import { default as default4 } from "./useTranslation.js";
7
- export {
8
- LanguageSchema,
9
- Languages,
10
- TranslationKeysSchema,
11
- default2 as i18nMiddleware,
12
- isClientSide,
13
- default3 as loadI18next,
14
- default4 as useTranslation
15
- };
7
+ import useTranslation from "./useTranslation.js";
8
+ export { LanguageSchema, Languages, TranslationKeysSchema, i18nMiddleware, isClientSide, loadI18next, useTranslation };
@@ -1,37 +1,26 @@
1
- let i18nInstance;
2
- const reconcileLanguage = async (instance, lng) => {
3
- if (lng && instance.language !== lng) {
4
- await instance.changeLanguage(lng);
5
- }
6
- return instance;
1
+ //#region src/loadI18next.ts
2
+ var i18nInstance;
3
+ var reconcileLanguage = async (instance, lng) => {
4
+ if (lng && instance.language !== lng) await instance.changeLanguage(lng);
5
+ return instance;
7
6
  };
8
7
  async function loadI18next(backend, lng) {
9
- return new Promise((resolve, reject) => {
10
- try {
11
- if (backend) {
12
- import("./i18nBackend.js").then(({ default: initializeI18n }) => {
13
- if (!i18nInstance) {
14
- i18nInstance = initializeI18n(resolve);
15
- } else {
16
- resolve(i18nInstance);
17
- }
18
- });
19
- } else {
20
- import("./i18nFrontend.js").then(({ default: initializeI18n }) => {
21
- if (!i18nInstance) {
22
- i18nInstance = initializeI18n((instance) => {
23
- void reconcileLanguage(instance, lng).then(resolve);
24
- }, lng);
25
- } else {
26
- void reconcileLanguage(i18nInstance, lng).then(resolve);
27
- }
28
- });
29
- }
30
- } catch (e) {
31
- reject(e);
32
- }
33
- });
8
+ return new Promise((resolve, reject) => {
9
+ try {
10
+ if (backend) import("./i18nBackend.js").then(({ default: initializeI18n }) => {
11
+ if (!i18nInstance) i18nInstance = initializeI18n(resolve);
12
+ else resolve(i18nInstance);
13
+ });
14
+ else import("./i18nFrontend.js").then(({ default: initializeI18n }) => {
15
+ if (!i18nInstance) i18nInstance = initializeI18n((instance) => {
16
+ reconcileLanguage(instance, lng).then(resolve);
17
+ }, lng);
18
+ else reconcileLanguage(i18nInstance, lng).then(resolve);
19
+ });
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ });
34
24
  }
35
- export {
36
- loadI18next as default
37
- };
25
+ //#endregion
26
+ export { loadI18next as default };