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 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(error.message, `Error loading translations for ${locale}`, "Translation error", error.stack, import_opticore_http_response.HttpStatusCode.INTERNAL_SERVER_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 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;
128
135
  return this.formatMessage(message, params);
129
136
  }
130
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
@@ -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(error.message, `Error loading translations for ${locale}`, "Translation error", error.stack, HttpStatusCode.INTERNAL_SERVER_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 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;
91
98
  return this.formatMessage(message, params);
92
99
  }
93
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.1",
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.11"
32
+ "opticore-logger": "^1.0.13",
33
+ "tsx": "^4.19.3"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@types/node": "^22.13.5",