@nimpl/i18n 2.0.0-canary.2 → 2.0.0-canary.4
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/clientConfig.d.ts +0 -0
- package/dist/clientConfig.js +2 -0
- package/dist/configuration/getConfig.js +39 -12
- package/dist/i18n.js +29 -0
- package/dist/lib/loadI18nData.js +2 -2
- package/i18n.d.ts +2 -0
- package/package.json +8 -1
|
File without changes
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -10,22 +33,26 @@ const CONFIG_PATH = path_1.default.join(process.cwd(), "nimpl-i18n.js");
|
|
|
10
33
|
// Crutch bypass of conversion by the assembler to require
|
|
11
34
|
const dynamicImport = new Function("p", "return import(p)");
|
|
12
35
|
const getConfig = async () => {
|
|
36
|
+
let clientConfig;
|
|
13
37
|
if (fs_1.default.existsSync(CONFIG_PATH)) {
|
|
14
38
|
const config = await dynamicImport((0, url_1.pathToFileURL)(CONFIG_PATH).href);
|
|
15
|
-
|
|
16
|
-
if (!load) {
|
|
17
|
-
throw new Error(`Can't find "load" method in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
|
|
18
|
-
}
|
|
19
|
-
if (!languages) {
|
|
20
|
-
throw new Error(`Can't find "languages" list in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
|
|
21
|
-
}
|
|
22
|
-
if (!getLanguage) {
|
|
23
|
-
throw new Error(`Can't find "getLanguage" method in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
|
|
24
|
-
}
|
|
25
|
-
return config.default;
|
|
39
|
+
clientConfig = config.default;
|
|
26
40
|
}
|
|
27
41
|
else {
|
|
28
|
-
|
|
42
|
+
// @ts-expect-error will be imported from the alias configuration in webpack
|
|
43
|
+
const config = await Promise.resolve().then(() => __importStar(require("@nimpl/i18n/clientConfig")));
|
|
44
|
+
clientConfig = config.default;
|
|
45
|
+
}
|
|
46
|
+
const { load, getLanguage, languages } = clientConfig;
|
|
47
|
+
if (!load) {
|
|
48
|
+
throw new Error(`Can't find "load" method in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
|
|
49
|
+
}
|
|
50
|
+
if (!languages) {
|
|
51
|
+
throw new Error(`Can't find "languages" list in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
|
|
52
|
+
}
|
|
53
|
+
if (!getLanguage) {
|
|
54
|
+
throw new Error(`Can't find "getLanguage" method in configuration file - https://github.com/vordgi/nimpl-i18n#configuration`);
|
|
29
55
|
}
|
|
56
|
+
return clientConfig;
|
|
30
57
|
};
|
|
31
58
|
exports.default = getConfig;
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const CONFIG_PATH = path_1.default.join(process.cwd(), "nimpl-i18n.js");
|
|
9
|
+
const i18n = () => {
|
|
10
|
+
return (nextConfig = {}) => {
|
|
11
|
+
return {
|
|
12
|
+
...nextConfig,
|
|
13
|
+
webpack: (config, options) => {
|
|
14
|
+
if (!(0, fs_1.existsSync)(CONFIG_PATH))
|
|
15
|
+
throw new Error("Please create and configure nimpl-i18n.js");
|
|
16
|
+
config.resolve ||= {};
|
|
17
|
+
config.resolve.alias = {
|
|
18
|
+
...config.resolve.alias,
|
|
19
|
+
"@nimpl/i18n/clientConfig": CONFIG_PATH,
|
|
20
|
+
};
|
|
21
|
+
if (typeof nextConfig.webpack === "function") {
|
|
22
|
+
return nextConfig.webpack(config, options);
|
|
23
|
+
}
|
|
24
|
+
return config;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.default = i18n;
|
package/dist/lib/loadI18nData.js
CHANGED
|
@@ -12,7 +12,7 @@ const loadI18nData = async () => {
|
|
|
12
12
|
if (!language || !config.languages.includes(language)) {
|
|
13
13
|
throw new Error(`Can\' load data for language "${language}", valid languages are: ${config.languages.join(", ")}`);
|
|
14
14
|
}
|
|
15
|
-
const
|
|
16
|
-
return { dictionary
|
|
15
|
+
const dictionary = await config.load(language);
|
|
16
|
+
return { dictionary, language };
|
|
17
17
|
};
|
|
18
18
|
exports.default = loadI18nData;
|
package/i18n.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimpl/i18n",
|
|
3
|
-
"version": "2.0.0-canary.
|
|
3
|
+
"version": "2.0.0-canary.4",
|
|
4
4
|
"description": "i18n library for working with translations in server and client components",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./ClientTranslation": {
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
"./getTranslation": {
|
|
10
10
|
"default": "./dist/getTranslation.js"
|
|
11
11
|
},
|
|
12
|
+
"./i18n": {
|
|
13
|
+
"default": "./dist/i18n.js"
|
|
14
|
+
},
|
|
12
15
|
"./I18nTransmitter": {
|
|
13
16
|
"default": "./dist/I18nTransmitter.js"
|
|
14
17
|
},
|
|
@@ -20,6 +23,9 @@
|
|
|
20
23
|
},
|
|
21
24
|
"./useTranslation": {
|
|
22
25
|
"default": "./dist/useTranslation.js"
|
|
26
|
+
},
|
|
27
|
+
"./clientConfig": {
|
|
28
|
+
"default": "./dist/clientConfig.js"
|
|
23
29
|
}
|
|
24
30
|
},
|
|
25
31
|
"files": [
|
|
@@ -54,6 +60,7 @@
|
|
|
54
60
|
"@types/node": "16.11.12",
|
|
55
61
|
"@types/object-path": "0.11.4",
|
|
56
62
|
"@types/react": "18.2.43",
|
|
63
|
+
"@types/webpack": "5.28.5",
|
|
57
64
|
"react": "18.2.0",
|
|
58
65
|
"typescript": "5.3.2"
|
|
59
66
|
},
|