opticore-translator 1.0.2 → 1.0.3
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.cjs +2 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/example/index.ts +10 -0
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -130,7 +130,8 @@ var TranslationLoader = class {
|
|
|
130
130
|
*/
|
|
131
131
|
static t(key, locale = this.defaultLocale, params = {}) {
|
|
132
132
|
var _a, _b;
|
|
133
|
-
const
|
|
133
|
+
const localeKey = `message.translation.${locale}`;
|
|
134
|
+
const message = ((_a = this.translations[localeKey]) == null ? void 0 : _a[key]) || ((_b = this.translations[`message.translation.${this.defaultLocale}`]) == null ? void 0 : _b[key]) || key;
|
|
134
135
|
return this.formatMessage(message, params);
|
|
135
136
|
}
|
|
136
137
|
};
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -93,7 +93,8 @@ var TranslationLoader = class {
|
|
|
93
93
|
*/
|
|
94
94
|
static t(key, locale = this.defaultLocale, params = {}) {
|
|
95
95
|
var _a, _b;
|
|
96
|
-
const
|
|
96
|
+
const localeKey = `message.translation.${locale}`;
|
|
97
|
+
const message = ((_a = this.translations[localeKey]) == null ? void 0 : _a[key]) || ((_b = this.translations[`message.translation.${this.defaultLocale}`]) == null ? void 0 : _b[key]) || key;
|
|
97
98
|
return this.formatMessage(message, params);
|
|
98
99
|
}
|
|
99
100
|
};
|
package/example/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {TranslationLoader} from "../src";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
((): void => {
|
|
5
|
+
TranslationLoader.loadTranslations(path.join('src', 'utils', 'translations'), 'en');
|
|
6
|
+
//const msg: string = TranslationLoader.t("mongoServerError", "en");
|
|
7
|
+
|
|
8
|
+
console.log("path is :", path.join(process.cwd(), 'src', 'utils', 'translations'));
|
|
9
|
+
console.log("mongoServerError is :", TranslationLoader.t("mongoServerError", "en", { dbHost: '127.0.0.1' }));
|
|
10
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opticore-translator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "opticore translator to translate according language",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"chalk": "^5.4.1",
|
|
30
30
|
"opticore-env-access": "^1.0.2",
|
|
31
31
|
"opticore-http-response": "^1.0.3",
|
|
32
|
-
"opticore-logger": "^1.0.13"
|
|
32
|
+
"opticore-logger": "^1.0.13",
|
|
33
|
+
"tsx": "^4.19.3"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/node": "^22.13.5",
|