@runnerpro/backend 1.0.13 → 1.0.15

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/lib/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LANGUAGES = exports.translate = exports.fetchIA = exports.err = exports.sendMail = exports.batchQuery = exports.query = exports.sleep = exports.sendNotification = void 0;
3
+ exports.useTranslation = exports.LANGUAGES = exports.translate = exports.fetchIA = exports.err = exports.sendMail = exports.batchQuery = exports.query = exports.sleep = exports.sendNotification = void 0;
4
4
  const sendNotification_1 = require("./sendNotification");
5
5
  Object.defineProperty(exports, "sendNotification", { enumerable: true, get: function () { return sendNotification_1.sendNotification; } });
6
6
  const sleep_1 = require("./sleep");
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "fetchIA", { enumerable: true, get: function () {
17
17
  const translation_1 = require("./translation");
18
18
  Object.defineProperty(exports, "translate", { enumerable: true, get: function () { return translation_1.translate; } });
19
19
  Object.defineProperty(exports, "LANGUAGES", { enumerable: true, get: function () { return translation_1.LANGUAGES; } });
20
+ Object.defineProperty(exports, "useTranslation", { enumerable: true, get: function () { return translation_1.useTranslation; } });
@@ -9,10 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.translate = exports.LANGUAGES = void 0;
12
+ exports.useTranslation = exports.translate = exports.LANGUAGES = void 0;
13
13
  const { TranslationServiceClient } = require('@google-cloud/translate');
14
14
  const { LANGUAGES } = require('@runnerpro/common');
15
15
  exports.LANGUAGES = LANGUAGES;
16
+ const fs = require('fs');
16
17
  const translate = (text, { fromLanguage, toLanguage, }) => __awaiter(void 0, void 0, void 0, function* () {
17
18
  const projectId = process.env.GCP_PROYECT_ID;
18
19
  const location = 'global';
@@ -28,3 +29,19 @@ const translate = (text, { fromLanguage, toLanguage, }) => __awaiter(void 0, voi
28
29
  return response.translations[0].translatedText;
29
30
  });
30
31
  exports.translate = translate;
32
+ const useTranslation = (language, path) => {
33
+ return {
34
+ t: (text, interpolation) => {
35
+ const filePath = './src/locales' + path + '/' + language + '.json';
36
+ const fileContent = JSON.parse(fs.readFileSync(filePath, 'utf8'));
37
+ let translatedText = fileContent[text];
38
+ if (interpolation) {
39
+ Object.keys(interpolation).forEach((key) => {
40
+ translatedText = translatedText.replace(`{{ ${key} }}`, interpolation[key]);
41
+ });
42
+ }
43
+ return translatedText;
44
+ },
45
+ };
46
+ };
47
+ exports.useTranslation = useTranslation;
@@ -4,6 +4,6 @@ import { query, batchQuery } from './db';
4
4
  import { sendMail } from './sendMail';
5
5
  import { err } from './err';
6
6
  import { fetchIA } from './fetch/fetchIA';
7
- import { translate, LANGUAGES } from './translation';
8
- export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, translate, LANGUAGES, };
7
+ import { translate, LANGUAGES, useTranslation } from './translation';
8
+ export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, translate, LANGUAGES, useTranslation, };
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,UAAU,EACV,QAAQ,EACR,GAAG,EACH,OAAO,EACP,SAAS,EACT,SAAS,GACV,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,UAAU,EACV,QAAQ,EACR,GAAG,EACH,OAAO,EACP,SAAS,EACT,SAAS,EACT,cAAc,GACf,CAAC"}
@@ -4,5 +4,8 @@ declare const translate: (text: string, { fromLanguage, toLanguage, }: {
4
4
  fromLanguage: LANGUAGES_TYPE;
5
5
  toLanguage: LANGUAGES_TYPE;
6
6
  }) => Promise<string>;
7
- export { LANGUAGES, translate };
7
+ declare const useTranslation: (language: string, path: string) => {
8
+ t: (text: string, interpolation: any) => any;
9
+ };
10
+ export { LANGUAGES, translate, useTranslation };
8
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/translation/index.ts"],"names":[],"mappings":"AACA,QAAA,MAAQ,SAAS,KAAiC,CAAC;AAEnD,KAAK,cAAc,GAAG,MAAM,OAAO,SAAS,CAAC;AAE7C,QAAA,MAAM,SAAS,SACP,MAAM;kBAIO,cAAc;gBAAc,cAAc;MAC5D,QAAQ,MAAM,CAgBhB,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/translation/index.ts"],"names":[],"mappings":"AACA,QAAA,MAAQ,SAAS,KAAiC,CAAC;AAGnD,KAAK,cAAc,GAAG,MAAM,OAAO,SAAS,CAAC;AAE7C,QAAA,MAAM,SAAS,SACP,MAAM;kBAIO,cAAc;gBAAc,cAAc;MAC5D,QAAQ,MAAM,CAgBhB,CAAC;AAEF,QAAA,MAAM,cAAc,aAAc,MAAM,QAAQ,MAAM;cAExC,MAAM,iBAAiB,GAAG;CAevC,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"