next-translate 2.4.0 → 2.4.2

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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "appdiri18nprovider",
3
+ "private": true,
4
+ "main": "../lib/cjs/AppDirI18nProvider.js",
5
+ "module": "../lib/esm/AppDirI18nProvider.js",
6
+ "types": "../AppDirI18nProvider.d.ts"
7
+ }
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { I18nDictionary, LoaderConfig } from '.';
3
+ type AppDirI18nProviderProps = {
4
+ lang: string;
5
+ namespaces: Record<string, I18nDictionary>;
6
+ config: LoaderConfig;
7
+ children: React.ReactNode;
8
+ };
9
+ export default function AppDirI18nProvider({ lang, namespaces, config, children, }: AppDirI18nProviderProps): import("react").ReactNode;
10
+ export {};
package/README.md CHANGED
@@ -963,7 +963,7 @@ At Next-translate, we have chosen not to re-implement this functionality, as we
963
963
 
964
964
  - Add the dynamic path `[lang]` to the first level. That is, all your pages will be inside `/app/[lang]`.
965
965
  - If you need more control over which languages to support, or to detect the browser language, use the [middleware](https://nextjs.org/docs/app/building-your-application/routing/internationalization#routing-overview) that the Next.js team [recommends here](https://nextjs.org/docs/app/building-your-application/routing/internationalization#routing-overview).
966
- - Update all the pages inside `i18n.(js|ts)` file to contain the `/[lang]` at the beginning.
966
+ - Update all the pages inside `i18n.(js|json)` file to contain the `/[lang]` at the beginning.
967
967
 
968
968
  ```diff
969
969
  module.exports = {
package/appWithI18n.d.ts CHANGED
@@ -17,7 +17,7 @@ export default function appWithI18n(AppToTranslate: NextComponentType, config?:
17
17
  (props: Props): React.JSX.Element;
18
18
  getInitialProps(appCtx: any): Promise<{
19
19
  __lang: string;
20
- __namespaces?: Record<string, object> | undefined;
20
+ __namespaces?: Record<string, import(".").I18nDictionary> | undefined;
21
21
  }>;
22
22
  };
23
23
  export {};
package/index.d.ts CHANGED
@@ -91,7 +91,7 @@ declare global {
91
91
  var __NEXT_TRANSLATE__: {
92
92
  namespaces: Record<string, I18nDictionary>;
93
93
  lang: string;
94
- pathname?: string;
94
+ config: LoaderConfig;
95
95
  };
96
96
  namespace NodeJS {
97
97
  interface Global {
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ function AppDirI18nProvider(_a) {
5
+ var lang = _a.lang, _b = _a.namespaces, namespaces = _b === void 0 ? {} : _b, config = _a.config, children = _a.children;
6
+ globalThis.__NEXT_TRANSLATE__ = { lang: lang, namespaces: namespaces, config: config };
7
+ return children;
8
+ }
9
+ exports.default = AppDirI18nProvider;
package/lib/cjs/getT.js CHANGED
@@ -41,7 +41,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var getConfig_1 = __importDefault(require("./getConfig"));
43
43
  var transCore_1 = __importDefault(require("./transCore"));
44
- var _store_1 = __importDefault(require("./_store"));
45
44
  var wrapTWithDefaultNs_1 = __importDefault(require("./wrapTWithDefaultNs"));
46
45
  function getT(locale, namespace) {
47
46
  var _a;
@@ -53,7 +52,7 @@ function getT(locale, namespace) {
53
52
  return __generator(this, function (_b) {
54
53
  switch (_b.label) {
55
54
  case 0:
56
- appDir = _store_1.default.get();
55
+ appDir = globalThis.__NEXT_TRANSLATE__;
57
56
  config = (_a = appDir === null || appDir === void 0 ? void 0 : appDir.config) !== null && _a !== void 0 ? _a : (0, getConfig_1.default)();
58
57
  defaultLoader = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
59
58
  return [2, Promise.resolve({})];
@@ -15,7 +15,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  var react_1 = require("react");
18
- var _store_1 = __importDefault(require("./_store"));
19
18
  var wrapTWithDefaultNs_1 = __importDefault(require("./wrapTWithDefaultNs"));
20
19
  var context_1 = __importDefault(require("./context"));
21
20
  var transCore_1 = __importDefault(require("./transCore"));
@@ -24,7 +23,8 @@ function useTranslationInPages(defaultNS) {
24
23
  return (0, react_1.useMemo)(function () { return (__assign(__assign({}, ctx), { t: (0, wrapTWithDefaultNs_1.default)(ctx.t, defaultNS) })); }, [ctx, defaultNS]);
25
24
  }
26
25
  function useTranslationAppDir(defaultNS) {
27
- var _a = _store_1.default.get(), lang = _a.lang, namespaces = _a.namespaces, config = _a.config;
26
+ var _a;
27
+ var _b = (_a = globalThis.__NEXT_TRANSLATE__) !== null && _a !== void 0 ? _a : {}, lang = _b.lang, namespaces = _b.namespaces, config = _b.config;
28
28
  var localesToIgnore = config.localesToIgnore || ['default'];
29
29
  var ignoreLang = localesToIgnore.includes(lang);
30
30
  var t = (0, transCore_1.default)({
@@ -36,7 +36,7 @@ function useTranslationAppDir(defaultNS) {
36
36
  return { t: (0, wrapTWithDefaultNs_1.default)(t, defaultNS), lang: lang };
37
37
  }
38
38
  function useTranslation(defaultNS) {
39
- var appDir = _store_1.default.get();
39
+ var appDir = globalThis.__NEXT_TRANSLATE__;
40
40
  var useT = (appDir === null || appDir === void 0 ? void 0 : appDir.config) ? useTranslationAppDir : useTranslationInPages;
41
41
  return useT(defaultNS);
42
42
  }
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+ export default function AppDirI18nProvider(_a) {
3
+ var lang = _a.lang, _b = _a.namespaces, namespaces = _b === void 0 ? {} : _b, config = _a.config, children = _a.children;
4
+ globalThis.__NEXT_TRANSLATE__ = { lang: lang, namespaces: namespaces, config: config };
5
+ return children;
6
+ }
package/lib/esm/getT.js CHANGED
@@ -36,7 +36,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  import getConfig from './getConfig';
38
38
  import transCore from './transCore';
39
- import store from './_store';
40
39
  import wrapTWithDefaultNs from './wrapTWithDefaultNs';
41
40
  export default function getT(locale, namespace) {
42
41
  var _a;
@@ -48,7 +47,7 @@ export default function getT(locale, namespace) {
48
47
  return __generator(this, function (_b) {
49
48
  switch (_b.label) {
50
49
  case 0:
51
- appDir = store.get();
50
+ appDir = globalThis.__NEXT_TRANSLATE__;
52
51
  config = (_a = appDir === null || appDir === void 0 ? void 0 : appDir.config) !== null && _a !== void 0 ? _a : getConfig();
53
52
  defaultLoader = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
54
53
  return [2, Promise.resolve({})];
@@ -10,7 +10,6 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { useContext, useMemo } from 'react';
13
- import store from './_store';
14
13
  import wrapTWithDefaultNs from './wrapTWithDefaultNs';
15
14
  import I18nContext from './context';
16
15
  import transCore from './transCore';
@@ -19,7 +18,8 @@ function useTranslationInPages(defaultNS) {
19
18
  return useMemo(function () { return (__assign(__assign({}, ctx), { t: wrapTWithDefaultNs(ctx.t, defaultNS) })); }, [ctx, defaultNS]);
20
19
  }
21
20
  function useTranslationAppDir(defaultNS) {
22
- var _a = store.get(), lang = _a.lang, namespaces = _a.namespaces, config = _a.config;
21
+ var _a;
22
+ var _b = (_a = globalThis.__NEXT_TRANSLATE__) !== null && _a !== void 0 ? _a : {}, lang = _b.lang, namespaces = _b.namespaces, config = _b.config;
23
23
  var localesToIgnore = config.localesToIgnore || ['default'];
24
24
  var ignoreLang = localesToIgnore.includes(lang);
25
25
  var t = transCore({
@@ -31,7 +31,7 @@ function useTranslationAppDir(defaultNS) {
31
31
  return { t: wrapTWithDefaultNs(t, defaultNS), lang: lang };
32
32
  }
33
33
  export default function useTranslation(defaultNS) {
34
- var appDir = store.get();
34
+ var appDir = globalThis.__NEXT_TRANSLATE__;
35
35
  var useT = (appDir === null || appDir === void 0 ? void 0 : appDir.config) ? useTranslationAppDir : useTranslationInPages;
36
36
  return useT(defaultNS);
37
37
  }
@@ -1,7 +1,7 @@
1
- import { LoaderConfig } from '.';
1
+ import { I18nDictionary, LoaderConfig } from '.';
2
2
  export default function loadNamespaces(config?: LoaderConfig): Promise<{
3
3
  __lang: string;
4
- __namespaces?: Record<string, object>;
4
+ __namespaces?: Record<string, I18nDictionary>;
5
5
  }>;
6
6
  type LogProps = {
7
7
  page: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-translate",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "Tiny and powerful i18n tools (Next plugin + API) to translate your Next.js pages.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -42,12 +42,12 @@
42
42
  "useTranslation*",
43
43
  "setLanguage*",
44
44
  "index*",
45
- "_store*"
45
+ "AppDirI18nProvider*"
46
46
  ],
47
47
  "scripts": {
48
48
  "build": "yarn clean && cross-env NODE_ENV=production && yarn tsc",
49
49
  "clean": "yarn clean:build && yarn clean:examples",
50
- "clean:build": "rm -rf lib appWith* Dynamic* I18n* index context loadNa* setLang* Trans* useT* withT* getP* getC* *.d.ts getT transC* wrapT* types formatElements _store*",
50
+ "clean:build": "rm -rf lib appWith* Dynamic* I18n* index context loadNa* setLang* Trans* useT* withT* getP* getC* *.d.ts getT transC* wrapT* types formatElements AppDirI18nProvider*",
51
51
  "clean:examples": "rm -rf examples/**/.next && rm -rf examples/**/node_modules && rm -rf examples/**/yarn.lock",
52
52
  "example": "yarn example:complex",
53
53
  "example:basic": "yarn build && yarn --cwd examples/basic && yarn --cwd examples/basic dev",
@@ -1,7 +0,0 @@
1
- {
2
- "name": "_store",
3
- "private": true,
4
- "main": "../lib/cjs/_store.js",
5
- "module": "../lib/esm/_store.js",
6
- "types": "../_store.d.ts"
7
- }
package/_store.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { DataForStoreType } from '.';
2
- declare const _default: {
3
- set(storeData: DataForStoreType): void;
4
- get(): DataForStoreType;
5
- };
6
- export default _default;
package/lib/cjs/_store.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- var data;
15
- exports.default = {
16
- set: function (storeData) {
17
- data = __assign(__assign({}, storeData), { namespaces: __assign(__assign({}, ((data === null || data === void 0 ? void 0 : data.namespaces) || {})), ((storeData === null || storeData === void 0 ? void 0 : storeData.namespaces) || {})) });
18
- },
19
- get: function () {
20
- return data;
21
- },
22
- };
package/lib/esm/_store.js DELETED
@@ -1,20 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var data;
13
- export default {
14
- set: function (storeData) {
15
- data = __assign(__assign({}, storeData), { namespaces: __assign(__assign({}, ((data === null || data === void 0 ? void 0 : data.namespaces) || {})), ((storeData === null || storeData === void 0 ? void 0 : storeData.namespaces) || {})) });
16
- },
17
- get: function () {
18
- return data;
19
- },
20
- };