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 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 message = ((_a = this.translations[locale]) == null ? void 0 : _a[key]) || ((_b = this.translations[this.defaultLocale]) == null ? void 0 : _b[key]) || key;
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
@@ -13,7 +13,7 @@ declare class TranslationLoader {
13
13
  * @param template
14
14
  * @param params
15
15
  */
16
- static formatMessage(template: string, params: Record<any, any>): string;
16
+ private static formatMessage;
17
17
  /**
18
18
  *
19
19
  * @param key
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ declare class TranslationLoader {
13
13
  * @param template
14
14
  * @param params
15
15
  */
16
- static formatMessage(template: string, params: Record<any, any>): string;
16
+ private static formatMessage;
17
17
  /**
18
18
  *
19
19
  * @param key
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 message = ((_a = this.translations[locale]) == null ? void 0 : _a[key]) || ((_b = this.translations[this.defaultLocale]) == null ? void 0 : _b[key]) || key;
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
  };
@@ -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.2",
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",