generaltranslation 2.0.60 → 2.0.62

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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LanguageObject } from './codes/codes';
2
- import { Request } from './translation/_translateBundle';
3
- import { Update } from './translation/_updateProjectDictionary';
2
+ import { StringWithVariables } from './translation/strings/_translate';
3
+ import { Content, Update, Request } from './types/types';
4
4
  /**
5
5
  * Type representing the constructor parameters for the GT class.
6
6
  */
@@ -29,36 +29,36 @@ declare class GT {
29
29
  */
30
30
  constructor({ apiKey, defaultLanguage, projectID, baseURL }?: GTConstructorParams);
31
31
  /**
32
- * Translates a string into a target language.
32
+ * Translates a string or an array of strings/variables into a target language.
33
33
  * If `metadata.store` is provided, the translation is cached for use in a public project.
34
34
  *
35
- * @param {string} content - The string to be translated.
35
+ * @param {Content} content - The string or array of strings/variables to be translated.
36
36
  * @param {string} targetLanguage - The target language code (e.g., 'en', 'fr') for the translation.
37
37
  * @param {{ context?: string, store?: boolean, [key: string]: any }} [metadata] - Additional metadata for the translation request.
38
38
  * @param {string} [metadata.context] - Contextual information to assist with the translation.
39
39
  * @param {boolean} [metadata.store] - Whether to cache the translation for use in a public project.
40
40
  *
41
- * @returns {Promise<{ translation: string, error?: Error | unknown }>} - A promise that resolves to the translated content, or an error if the translation fails.
41
+ * @returns {Promise<{ translation: string, error?: Error | unknown }>} A promise that resolves to the translated content, or an error if the translation fails.
42
42
  */
43
- translate(content: string, targetLanguage: string, metadata?: {
43
+ translate(content: Content, targetLanguage: string, metadata?: {
44
44
  context?: string;
45
45
  store?: boolean;
46
46
  [key: string]: any;
47
47
  }): Promise<{
48
- translation: string;
48
+ translation: StringWithVariables | [];
49
49
  error?: Error | unknown;
50
50
  }>;
51
51
  /**
52
52
  * Translates the content of React children elements.
53
53
  *
54
54
  * @param {Object} params - The parameters for the translation.
55
- * @param {any} params.content - The React children content to be translated.
55
+ * @param {any} params.children - The React children content to be translated.
56
56
  * @param {string} params.targetLanguage - The target language for the translation.
57
57
  * @param {Object} params.metadata - Additional metadata for the translation process.
58
58
  *
59
59
  * @returns {Promise<any>} - A promise that resolves to the translated content.
60
60
  */
61
- translateReact(content: any, targetLanguage: string, metadata?: {
61
+ translateReact(children: any, targetLanguage: string, metadata?: {
62
62
  context?: string;
63
63
  store?: boolean;
64
64
  [key: string]: any;
package/dist/index.js CHANGED
@@ -63,10 +63,10 @@ exports.formatCurrency = formatCurrency;
63
63
  // ----- IMPORTS ----- //
64
64
  var codes_1 = require("./codes/codes");
65
65
  var getLanguageDirection_1 = __importDefault(require("./codes/getLanguageDirection"));
66
- var _translateBundle_1 = __importDefault(require("./translation/_translateBundle"));
67
- var _translate_1 = __importDefault(require("./translation/_translate"));
68
- var _translateReact_1 = __importDefault(require("./translation/_translateReact"));
69
- var _updateProjectDictionary_1 = __importDefault(require("./translation/_updateProjectDictionary"));
66
+ var _translateBundle_1 = __importDefault(require("./translation/dictionaries/_translateBundle"));
67
+ var _translate_1 = __importDefault(require("./translation/strings/_translate"));
68
+ var _translateReact_1 = __importDefault(require("./translation/react/_translateReact"));
69
+ var _updateProjectDictionary_1 = __importDefault(require("./translation/dictionaries/_updateProjectDictionary"));
70
70
  var _format_1 = require("./format/_format");
71
71
  // ----- CORE CLASS ----- //
72
72
  var getDefaultFromEnv = function (VARIABLE) {
@@ -96,16 +96,16 @@ var GT = /** @class */ (function () {
96
96
  this.baseURL = baseURL;
97
97
  }
98
98
  /**
99
- * Translates a string into a target language.
99
+ * Translates a string or an array of strings/variables into a target language.
100
100
  * If `metadata.store` is provided, the translation is cached for use in a public project.
101
101
  *
102
- * @param {string} content - The string to be translated.
102
+ * @param {Content} content - The string or array of strings/variables to be translated.
103
103
  * @param {string} targetLanguage - The target language code (e.g., 'en', 'fr') for the translation.
104
104
  * @param {{ context?: string, store?: boolean, [key: string]: any }} [metadata] - Additional metadata for the translation request.
105
105
  * @param {string} [metadata.context] - Contextual information to assist with the translation.
106
106
  * @param {boolean} [metadata.store] - Whether to cache the translation for use in a public project.
107
107
  *
108
- * @returns {Promise<{ translation: string, error?: Error | unknown }>} - A promise that resolves to the translated content, or an error if the translation fails.
108
+ * @returns {Promise<{ translation: string, error?: Error | unknown }>} A promise that resolves to the translated content, or an error if the translation fails.
109
109
  */
110
110
  GT.prototype.translate = function (content, targetLanguage, metadata) {
111
111
  return __awaiter(this, void 0, void 0, function () {
@@ -121,17 +121,17 @@ var GT = /** @class */ (function () {
121
121
  * Translates the content of React children elements.
122
122
  *
123
123
  * @param {Object} params - The parameters for the translation.
124
- * @param {any} params.content - The React children content to be translated.
124
+ * @param {any} params.children - The React children content to be translated.
125
125
  * @param {string} params.targetLanguage - The target language for the translation.
126
126
  * @param {Object} params.metadata - Additional metadata for the translation process.
127
127
  *
128
128
  * @returns {Promise<any>} - A promise that resolves to the translated content.
129
129
  */
130
- GT.prototype.translateReact = function (content, targetLanguage, metadata) {
130
+ GT.prototype.translateReact = function (children, targetLanguage, metadata) {
131
131
  return __awaiter(this, void 0, void 0, function () {
132
132
  return __generator(this, function (_a) {
133
133
  switch (_a.label) {
134
- case 0: return [4 /*yield*/, (0, _translateReact_1.default)(this, content, targetLanguage, __assign({ projectID: this.projectID, defaultLanguage: this.defaultLanguage }, metadata))];
134
+ case 0: return [4 /*yield*/, (0, _translateReact_1.default)(this, children, targetLanguage, __assign({ projectID: this.projectID, defaultLanguage: this.defaultLanguage }, metadata))];
135
135
  case 1: return [2 /*return*/, _a.sent()];
136
136
  }
137
137
  });
@@ -37,6 +37,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.default = _updateProjectDictionary;
40
+ /**
41
+ * @internal
42
+ */
40
43
  function _updateProjectDictionary(gt, updates, languages, projectID, replace) {
41
44
  return __awaiter(this, void 0, void 0, function () {
42
45
  var response, _a, _b, _c, result, error_1;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export type StringWithVariables = string | {
2
+ variable?: string;
3
+ key: string;
4
+ } | Array<string | {
5
+ variable?: string;
6
+ key: string;
7
+ }>;
@@ -0,0 +1,33 @@
1
+ export type Variable = {
2
+ variable?: string;
3
+ key: string;
4
+ };
5
+ export type Content = string | Array<string | Variable>;
6
+ export type Update = {
7
+ type: 'react';
8
+ data: {
9
+ children: any;
10
+ metadata: Record<string, any>;
11
+ };
12
+ } | {
13
+ type: 'string';
14
+ data: {
15
+ content: Content;
16
+ metadata: Record<string, any>;
17
+ };
18
+ };
19
+ export type Request = {
20
+ type: 'string';
21
+ data: {
22
+ content: Content;
23
+ targetLanguage: string;
24
+ metadata: Record<string, any>;
25
+ };
26
+ } | {
27
+ type: 'react';
28
+ data: {
29
+ children: any;
30
+ targetLanguage: string;
31
+ metadata: Record<string, any>;
32
+ };
33
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "2.0.60",
3
+ "version": "2.0.62",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,15 +0,0 @@
1
- export type Request = {
2
- type: 'string';
3
- data: {
4
- content: string;
5
- targetLanguage: string;
6
- metadata: Record<string, any>;
7
- };
8
- } | {
9
- type: 'react';
10
- data: {
11
- content: string;
12
- targetLanguage: string;
13
- metadata: Record<string, any>;
14
- };
15
- };
@@ -1,17 +0,0 @@
1
- export type Update = {
2
- type: 'react';
3
- data: {
4
- children: object | string;
5
- metadata: Record<string, any>;
6
- };
7
- } | {
8
- type: 'string';
9
- data: {
10
- content: string;
11
- metadata: Record<string, any>;
12
- };
13
- };
14
- export default function _updateProjectDictionary(gt: {
15
- baseURL: string;
16
- apiKey: string;
17
- }, updates: Update[], languages: string[], projectID: string, replace: boolean): Promise<string[]>;