next-i18next-static-site 0.2.1 → 0.2.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.
- package/package.json +8 -4
- package/dist/index.d.ts +0 -19
- package/dist/index.js +0 -169
- package/dist/index.mjs +0 -131
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-i18next-static-site",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "i18next solution for static sites build with Next.js (static HTML export / next export)",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,9 +16,13 @@
|
|
|
16
16
|
"author": "Marcel Zurreck <marcel.zurreck@gmail.com> (https://marcel.zurreck.com)",
|
|
17
17
|
"keywords": [
|
|
18
18
|
"nextjs",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
19
|
+
"i18n",
|
|
20
|
+
"i18next",
|
|
21
|
+
"react-i18next",
|
|
22
|
+
"locale",
|
|
23
|
+
"translation",
|
|
24
|
+
"static-site",
|
|
25
|
+
"ssg"
|
|
22
26
|
],
|
|
23
27
|
"scripts": {
|
|
24
28
|
"build": "rm -rf dist && mkdir dist && tsup src/index.tsx --format esm,cjs --dts --external react",
|
package/dist/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { i18n } from 'i18next';
|
|
2
|
-
export { Trans, Translation, useTranslation, withTranslation } from 'react-i18next';
|
|
3
|
-
|
|
4
|
-
declare const languages: string[];
|
|
5
|
-
declare const defaultLanguage: string;
|
|
6
|
-
declare const namespaces: string[];
|
|
7
|
-
declare const defaultNamespace: string;
|
|
8
|
-
declare const defaultNamespace2: string;
|
|
9
|
-
declare const cookieName: string;
|
|
10
|
-
declare const i18nextInstance: (language: string, locales: object) => i18n;
|
|
11
|
-
declare const I18nProvider: (props: any) => any;
|
|
12
|
-
declare function getAllLanguageSlugs(): {
|
|
13
|
-
params: {
|
|
14
|
-
lang: string;
|
|
15
|
-
};
|
|
16
|
-
}[];
|
|
17
|
-
declare function getLanguage(lang: string): string;
|
|
18
|
-
|
|
19
|
-
export { I18nProvider, cookieName, defaultLanguage, defaultNamespace, defaultNamespace2, getAllLanguageSlugs, getLanguage, i18nextInstance, languages, namespaces };
|
package/dist/index.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
-
|
|
26
|
-
// src/index.tsx
|
|
27
|
-
var src_exports = {};
|
|
28
|
-
__export(src_exports, {
|
|
29
|
-
I18nProvider: () => I18nProvider,
|
|
30
|
-
Trans: () => import_react_i18next.Trans,
|
|
31
|
-
Translation: () => import_react_i18next.Translation,
|
|
32
|
-
cookieName: () => cookieName,
|
|
33
|
-
defaultLanguage: () => defaultLanguage,
|
|
34
|
-
defaultNamespace: () => defaultNamespace,
|
|
35
|
-
defaultNamespace2: () => defaultNamespace2,
|
|
36
|
-
getAllLanguageSlugs: () => getAllLanguageSlugs,
|
|
37
|
-
getLanguage: () => getLanguage,
|
|
38
|
-
i18nextInstance: () => i18nextInstance,
|
|
39
|
-
languages: () => languages,
|
|
40
|
-
namespaces: () => namespaces,
|
|
41
|
-
useTranslation: () => import_react_i18next.useTranslation,
|
|
42
|
-
withTranslation: () => import_react_i18next.withTranslation
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(src_exports);
|
|
45
|
-
var import_config = __toESM(require("next/config"));
|
|
46
|
-
var import_router = require("next/router");
|
|
47
|
-
var import_react = require("react");
|
|
48
|
-
var import_js_cookie = __toESM(require("js-cookie"));
|
|
49
|
-
var import_i18next = __toESM(require("i18next"));
|
|
50
|
-
var import_react_i18next = require("react-i18next");
|
|
51
|
-
var { publicRuntimeConfig } = (0, import_config.default)();
|
|
52
|
-
var defaultConfig = {
|
|
53
|
-
allowHydration: true,
|
|
54
|
-
languages: ["en"],
|
|
55
|
-
defaultLanguage: "en",
|
|
56
|
-
namespaces: ["common"],
|
|
57
|
-
defaultNamespace: "common",
|
|
58
|
-
cookieName: "lang",
|
|
59
|
-
cookieOptions: { expires: 365, path: "/" }
|
|
60
|
-
};
|
|
61
|
-
var config = {
|
|
62
|
-
...defaultConfig,
|
|
63
|
-
languages: publicRuntimeConfig.i18n.languages,
|
|
64
|
-
defaultLanguage: publicRuntimeConfig.i18n.defaultLanguage,
|
|
65
|
-
namespaces: publicRuntimeConfig.i18n.namespaces,
|
|
66
|
-
defaultNamespace: publicRuntimeConfig.i18n.defaultNamespace
|
|
67
|
-
};
|
|
68
|
-
var languages = config.languages;
|
|
69
|
-
var defaultLanguage = config.defaultLanguage;
|
|
70
|
-
var namespaces = config.namespaces;
|
|
71
|
-
var defaultNamespace = config.defaultNamespace;
|
|
72
|
-
var defaultNamespace2 = config.defaultNamespace;
|
|
73
|
-
var cookieName = config.cookieName;
|
|
74
|
-
var createI18nextInstance = (locales, language) => {
|
|
75
|
-
const plugins = [
|
|
76
|
-
import_react_i18next.initReactI18next
|
|
77
|
-
];
|
|
78
|
-
const i18nInstance = import_i18next.default;
|
|
79
|
-
plugins.map((plugin) => i18nInstance.use(plugin));
|
|
80
|
-
i18nInstance.init({
|
|
81
|
-
resources: locales,
|
|
82
|
-
cleanCode: true,
|
|
83
|
-
lng: language,
|
|
84
|
-
supportedLngs: config.languages,
|
|
85
|
-
fallbackLng: language ? language : config.defaultLanguage,
|
|
86
|
-
ns: config.namespaces,
|
|
87
|
-
defaultNS: config.defaultNamespace,
|
|
88
|
-
interpolation: {
|
|
89
|
-
escapeValue: false
|
|
90
|
-
},
|
|
91
|
-
react: {
|
|
92
|
-
useSuspense: false
|
|
93
|
-
},
|
|
94
|
-
load: "languageOnly"
|
|
95
|
-
});
|
|
96
|
-
return i18nInstance;
|
|
97
|
-
};
|
|
98
|
-
var globalI18nextInstance = null;
|
|
99
|
-
var i18nextInstance = (language, locales) => {
|
|
100
|
-
if (!globalI18nextInstance) {
|
|
101
|
-
globalI18nextInstance = createI18nextInstance(locales, language);
|
|
102
|
-
return globalI18nextInstance;
|
|
103
|
-
} else {
|
|
104
|
-
globalI18nextInstance.changeLanguage(language);
|
|
105
|
-
return globalI18nextInstance;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
var loaded = false;
|
|
109
|
-
var I18nProvider = (props) => {
|
|
110
|
-
var _a;
|
|
111
|
-
const [hydration, setHydration] = (0, import_react.useState)(false);
|
|
112
|
-
const options = { ...config, ...props.i18n };
|
|
113
|
-
if (!((_a = props.i18n) == null ? void 0 : _a.locales)) {
|
|
114
|
-
throw new Error("locales object was not passed into I18nProvider");
|
|
115
|
-
}
|
|
116
|
-
const router = (0, import_router.useRouter)();
|
|
117
|
-
const { asPath, query } = router;
|
|
118
|
-
const slug = asPath.split("/")[1];
|
|
119
|
-
const langSlug = config.languages.includes(slug) && slug;
|
|
120
|
-
const language = (query.lang || langSlug || config.defaultLanguage).toString();
|
|
121
|
-
const pathLocale = (query.lang || langSlug).toString();
|
|
122
|
-
if (pathLocale && pathLocale !== "false") {
|
|
123
|
-
import_js_cookie.default.set(config.cookieName, pathLocale, config.cookieOptions);
|
|
124
|
-
}
|
|
125
|
-
if (!loaded) {
|
|
126
|
-
i18nextInstance(language, props.i18n.locales);
|
|
127
|
-
}
|
|
128
|
-
const { i18n: i18n2 } = (0, import_react_i18next.useTranslation)();
|
|
129
|
-
(0, import_react.useEffect)(() => {
|
|
130
|
-
i18n2.services.resourceStore.data = props.i18n.locales;
|
|
131
|
-
i18n2.changeLanguage(language);
|
|
132
|
-
}, [props.i18n.locales]);
|
|
133
|
-
(0, import_react.useEffect)(() => {
|
|
134
|
-
loaded = true;
|
|
135
|
-
i18n2.changeLanguage(language);
|
|
136
|
-
}, [language]);
|
|
137
|
-
(0, import_react.useEffect)(() => {
|
|
138
|
-
const hasWindow = typeof window !== "undefined";
|
|
139
|
-
if (hasWindow && options.allowHydration) {
|
|
140
|
-
setHydration(true);
|
|
141
|
-
}
|
|
142
|
-
}, []);
|
|
143
|
-
return hydration ? props.children : null;
|
|
144
|
-
};
|
|
145
|
-
function getAllLanguageSlugs() {
|
|
146
|
-
return config.languages.map((lang) => {
|
|
147
|
-
return { params: { lang } };
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
function getLanguage(lang) {
|
|
151
|
-
return config.languages.includes(lang) ? lang : config.defaultLanguage;
|
|
152
|
-
}
|
|
153
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
-
0 && (module.exports = {
|
|
155
|
-
I18nProvider,
|
|
156
|
-
Trans,
|
|
157
|
-
Translation,
|
|
158
|
-
cookieName,
|
|
159
|
-
defaultLanguage,
|
|
160
|
-
defaultNamespace,
|
|
161
|
-
defaultNamespace2,
|
|
162
|
-
getAllLanguageSlugs,
|
|
163
|
-
getLanguage,
|
|
164
|
-
i18nextInstance,
|
|
165
|
-
languages,
|
|
166
|
-
namespaces,
|
|
167
|
-
useTranslation,
|
|
168
|
-
withTranslation
|
|
169
|
-
});
|
package/dist/index.mjs
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
// src/index.tsx
|
|
2
|
-
import getConfig from "next/config";
|
|
3
|
-
import { useRouter } from "next/router";
|
|
4
|
-
import { useEffect, useState } from "react";
|
|
5
|
-
import Cookies from "js-cookie";
|
|
6
|
-
import i18next from "i18next";
|
|
7
|
-
import {
|
|
8
|
-
initReactI18next,
|
|
9
|
-
useTranslation,
|
|
10
|
-
withTranslation,
|
|
11
|
-
Translation,
|
|
12
|
-
Trans
|
|
13
|
-
} from "react-i18next";
|
|
14
|
-
var { publicRuntimeConfig } = getConfig();
|
|
15
|
-
var defaultConfig = {
|
|
16
|
-
allowHydration: true,
|
|
17
|
-
languages: ["en"],
|
|
18
|
-
defaultLanguage: "en",
|
|
19
|
-
namespaces: ["common"],
|
|
20
|
-
defaultNamespace: "common",
|
|
21
|
-
cookieName: "lang",
|
|
22
|
-
cookieOptions: { expires: 365, path: "/" }
|
|
23
|
-
};
|
|
24
|
-
var config = {
|
|
25
|
-
...defaultConfig,
|
|
26
|
-
languages: publicRuntimeConfig.i18n.languages,
|
|
27
|
-
defaultLanguage: publicRuntimeConfig.i18n.defaultLanguage,
|
|
28
|
-
namespaces: publicRuntimeConfig.i18n.namespaces,
|
|
29
|
-
defaultNamespace: publicRuntimeConfig.i18n.defaultNamespace
|
|
30
|
-
};
|
|
31
|
-
var languages = config.languages;
|
|
32
|
-
var defaultLanguage = config.defaultLanguage;
|
|
33
|
-
var namespaces = config.namespaces;
|
|
34
|
-
var defaultNamespace = config.defaultNamespace;
|
|
35
|
-
var defaultNamespace2 = config.defaultNamespace;
|
|
36
|
-
var cookieName = config.cookieName;
|
|
37
|
-
var createI18nextInstance = (locales, language) => {
|
|
38
|
-
const plugins = [
|
|
39
|
-
initReactI18next
|
|
40
|
-
];
|
|
41
|
-
const i18nInstance = i18next;
|
|
42
|
-
plugins.map((plugin) => i18nInstance.use(plugin));
|
|
43
|
-
i18nInstance.init({
|
|
44
|
-
resources: locales,
|
|
45
|
-
cleanCode: true,
|
|
46
|
-
lng: language,
|
|
47
|
-
supportedLngs: config.languages,
|
|
48
|
-
fallbackLng: language ? language : config.defaultLanguage,
|
|
49
|
-
ns: config.namespaces,
|
|
50
|
-
defaultNS: config.defaultNamespace,
|
|
51
|
-
interpolation: {
|
|
52
|
-
escapeValue: false
|
|
53
|
-
},
|
|
54
|
-
react: {
|
|
55
|
-
useSuspense: false
|
|
56
|
-
},
|
|
57
|
-
load: "languageOnly"
|
|
58
|
-
});
|
|
59
|
-
return i18nInstance;
|
|
60
|
-
};
|
|
61
|
-
var globalI18nextInstance = null;
|
|
62
|
-
var i18nextInstance = (language, locales) => {
|
|
63
|
-
if (!globalI18nextInstance) {
|
|
64
|
-
globalI18nextInstance = createI18nextInstance(locales, language);
|
|
65
|
-
return globalI18nextInstance;
|
|
66
|
-
} else {
|
|
67
|
-
globalI18nextInstance.changeLanguage(language);
|
|
68
|
-
return globalI18nextInstance;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
var loaded = false;
|
|
72
|
-
var I18nProvider = (props) => {
|
|
73
|
-
var _a;
|
|
74
|
-
const [hydration, setHydration] = useState(false);
|
|
75
|
-
const options = { ...config, ...props.i18n };
|
|
76
|
-
if (!((_a = props.i18n) == null ? void 0 : _a.locales)) {
|
|
77
|
-
throw new Error("locales object was not passed into I18nProvider");
|
|
78
|
-
}
|
|
79
|
-
const router = useRouter();
|
|
80
|
-
const { asPath, query } = router;
|
|
81
|
-
const slug = asPath.split("/")[1];
|
|
82
|
-
const langSlug = config.languages.includes(slug) && slug;
|
|
83
|
-
const language = (query.lang || langSlug || config.defaultLanguage).toString();
|
|
84
|
-
const pathLocale = (query.lang || langSlug).toString();
|
|
85
|
-
if (pathLocale && pathLocale !== "false") {
|
|
86
|
-
Cookies.set(config.cookieName, pathLocale, config.cookieOptions);
|
|
87
|
-
}
|
|
88
|
-
if (!loaded) {
|
|
89
|
-
i18nextInstance(language, props.i18n.locales);
|
|
90
|
-
}
|
|
91
|
-
const { i18n: i18n2 } = useTranslation();
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
i18n2.services.resourceStore.data = props.i18n.locales;
|
|
94
|
-
i18n2.changeLanguage(language);
|
|
95
|
-
}, [props.i18n.locales]);
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
loaded = true;
|
|
98
|
-
i18n2.changeLanguage(language);
|
|
99
|
-
}, [language]);
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
const hasWindow = typeof window !== "undefined";
|
|
102
|
-
if (hasWindow && options.allowHydration) {
|
|
103
|
-
setHydration(true);
|
|
104
|
-
}
|
|
105
|
-
}, []);
|
|
106
|
-
return hydration ? props.children : null;
|
|
107
|
-
};
|
|
108
|
-
function getAllLanguageSlugs() {
|
|
109
|
-
return config.languages.map((lang) => {
|
|
110
|
-
return { params: { lang } };
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
function getLanguage(lang) {
|
|
114
|
-
return config.languages.includes(lang) ? lang : config.defaultLanguage;
|
|
115
|
-
}
|
|
116
|
-
export {
|
|
117
|
-
I18nProvider,
|
|
118
|
-
Trans,
|
|
119
|
-
Translation,
|
|
120
|
-
cookieName,
|
|
121
|
-
defaultLanguage,
|
|
122
|
-
defaultNamespace,
|
|
123
|
-
defaultNamespace2,
|
|
124
|
-
getAllLanguageSlugs,
|
|
125
|
-
getLanguage,
|
|
126
|
-
i18nextInstance,
|
|
127
|
-
languages,
|
|
128
|
-
namespaces,
|
|
129
|
-
useTranslation,
|
|
130
|
-
withTranslation
|
|
131
|
-
};
|