opticore-translator 1.0.1 → 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 +9 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -2
- package/example/index.ts +10 -0
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -92,7 +92,13 @@ var TranslationLoader = class {
|
|
|
92
92
|
this.translations[locale] = JSON.parse(import_fs.default.readFileSync(filePath, "utf-8"));
|
|
93
93
|
this.logger.success("Translation Loaded", `Translations loaded for locale: ${locale}`);
|
|
94
94
|
} catch (error) {
|
|
95
|
-
this.logger.error(
|
|
95
|
+
this.logger.error(
|
|
96
|
+
error.message,
|
|
97
|
+
`Error loading translations for ${locale}`,
|
|
98
|
+
"Translation error",
|
|
99
|
+
error.stack,
|
|
100
|
+
import_opticore_http_response.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
101
|
+
);
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
104
|
});
|
|
@@ -124,7 +130,8 @@ var TranslationLoader = class {
|
|
|
124
130
|
*/
|
|
125
131
|
static t(key, locale = this.defaultLocale, params = {}) {
|
|
126
132
|
var _a, _b;
|
|
127
|
-
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;
|
|
128
135
|
return this.formatMessage(message, params);
|
|
129
136
|
}
|
|
130
137
|
};
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -55,7 +55,13 @@ var TranslationLoader = class {
|
|
|
55
55
|
this.translations[locale] = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
56
56
|
this.logger.success("Translation Loaded", `Translations loaded for locale: ${locale}`);
|
|
57
57
|
} catch (error) {
|
|
58
|
-
this.logger.error(
|
|
58
|
+
this.logger.error(
|
|
59
|
+
error.message,
|
|
60
|
+
`Error loading translations for ${locale}`,
|
|
61
|
+
"Translation error",
|
|
62
|
+
error.stack,
|
|
63
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
64
|
+
);
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
});
|
|
@@ -87,7 +93,8 @@ var TranslationLoader = class {
|
|
|
87
93
|
*/
|
|
88
94
|
static t(key, locale = this.defaultLocale, params = {}) {
|
|
89
95
|
var _a, _b;
|
|
90
|
-
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;
|
|
91
98
|
return this.formatMessage(message, params);
|
|
92
99
|
}
|
|
93
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.
|
|
32
|
+
"opticore-logger": "^1.0.13",
|
|
33
|
+
"tsx": "^4.19.3"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/node": "^22.13.5",
|