i18n-keyless-node 1.10.0
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/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/service.d.ts +3 -0
- package/dist/service.js +42 -0
- package/package.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { init, getTranslation } from "./service";
|
|
2
|
+
export { type I18nConfig, type Lang, type PrimaryLang, type Translations, type TranslationStore, type TranslationStoreState, type I18nKeylessRequestBody, type I18nKeylessResponse, type TranslationOptions, getAllTranslationsForAllLanguages, validateLanguage, queue, } from "i18n-keyless-core";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type I18nConfig, type Lang, type TranslationOptions } from "i18n-keyless-core";
|
|
2
|
+
export declare function init(newConfig: Omit<I18nConfig, "getAllTranslations">): Promise<Omit<I18nConfig, "getAllTranslations">>;
|
|
3
|
+
export declare function getTranslation(key: string, currentLanguage: Lang, options?: TranslationOptions): string;
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { queue, getTranslationCore, } from "i18n-keyless-core";
|
|
2
|
+
import { getAllTranslationsForAllLanguages } from "i18n-keyless-core/service";
|
|
3
|
+
const store = {
|
|
4
|
+
translations: {},
|
|
5
|
+
uniqueId: "",
|
|
6
|
+
lastRefresh: "",
|
|
7
|
+
config: null,
|
|
8
|
+
setTranslations: () => { },
|
|
9
|
+
setLanguage: () => { },
|
|
10
|
+
};
|
|
11
|
+
queue.on("empty", () => {
|
|
12
|
+
// when each word is translated, fetch the translations for the current language
|
|
13
|
+
getAllTranslationsForAllLanguages(store).then(store.setTranslations);
|
|
14
|
+
});
|
|
15
|
+
export async function init(newConfig) {
|
|
16
|
+
if (!newConfig.languages) {
|
|
17
|
+
throw new Error("i18n-keyless: languages is required");
|
|
18
|
+
}
|
|
19
|
+
if (!newConfig.languages.primary) {
|
|
20
|
+
throw new Error("i18n-keyless: primary is required");
|
|
21
|
+
}
|
|
22
|
+
if (!newConfig.languages.fallback) {
|
|
23
|
+
newConfig.languages.fallback = newConfig.languages.primary;
|
|
24
|
+
}
|
|
25
|
+
if (!newConfig.getAllTranslationsForAllLanguages || !newConfig.handleTranslate) {
|
|
26
|
+
if (!newConfig.API_KEY) {
|
|
27
|
+
if (!newConfig.API_URL) {
|
|
28
|
+
throw new Error("i18n-keyless: you didn't provide an API_KEY nor an API_URL nor a handleTranslate + getAllTranslationsForAllLanguages function. You need to provide one of them to make i18n-keyless work");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (newConfig.addMissingTranslations !== false) {
|
|
33
|
+
// default to true
|
|
34
|
+
newConfig.addMissingTranslations = true;
|
|
35
|
+
}
|
|
36
|
+
store.config = newConfig;
|
|
37
|
+
store.config.onInit?.(newConfig.languages.primary);
|
|
38
|
+
return newConfig;
|
|
39
|
+
}
|
|
40
|
+
export function getTranslation(key, currentLanguage, options) {
|
|
41
|
+
return getTranslationCore(key, { ...store, currentLanguage }, options);
|
|
42
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "i18n-keyless-node",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.10.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"prepublishOnly": "rm -rf ./dist && tsc --project tsconfig.json && npm pack",
|
|
14
|
+
"test": "echo 'no test for node'"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"i18n-keyless-core": "latest"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@eslint/js": "^9.9.0",
|
|
21
|
+
"@types/node": "^22.5.5",
|
|
22
|
+
"eslint": "^9.9.0",
|
|
23
|
+
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
|
|
24
|
+
"eslint-plugin-react-refresh": "^0.4.9"
|
|
25
|
+
}
|
|
26
|
+
}
|