generaltranslation 2.0.0 → 2.0.2

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.
@@ -0,0 +1,34 @@
1
+ interface LanguageObject {
2
+ language: string;
3
+ script: string;
4
+ region: string;
5
+ }
6
+ /**
7
+ * Returns a language object from an array of codes or a single code.
8
+ * Returns null if there's no matching language.
9
+ * @param {string|string[]} codes - The code or array of codes.
10
+ * @returns {(LanguageObject|null) | (LanguageObject|null)[]} The language object(s).
11
+ */
12
+ declare function _getLanguageObject(codes: string): LanguageObject | null;
13
+ declare function _getLanguageObject(codes: string[]): (LanguageObject | null)[];
14
+ /**
15
+ * Returns the language name(s) from an array of codes or a single code.
16
+ * @param {string|string[]} codes - The code or array of codes.
17
+ * @returns {string|string[]} The language name(s).
18
+ */
19
+ declare const _getLanguageName: (codes: string | string[]) => string | string[];
20
+ /**
21
+ * Returns the language code(s) from an array of language names or a single name.
22
+ * @param {string|string[]} languages - The language name or array of language names.
23
+ * @returns {string|string[]} The language code(s).
24
+ */
25
+ declare const _getLanguageCode: (languages: string | string[]) => string | string[];
26
+ /**
27
+ * Determines if all provided language codes represent the same language.
28
+ * Can take either an array of codes or a plain set of parameters.
29
+ * @param codes - The language codes, either as separate arguments or as an array.
30
+ * @returns {boolean} True if all codes represent the same language, false otherwise.
31
+ */
32
+ declare function _isSameLanguage(...codes: string[]): boolean;
33
+ declare function _isSameLanguage(codes: string[]): boolean;
34
+ export { _getLanguageObject, _getLanguageName, _getLanguageCode, _isSameLanguage };
@@ -0,0 +1,51 @@
1
+ import { _getLanguageObject, _isSameLanguage } from './codes/codes';
2
+ /**
3
+ * Interface representing the constructor parameters for the GT class.
4
+ */
5
+ type GTConstructorParams = {
6
+ apiKey?: string;
7
+ defaultLanguage?: string;
8
+ projectID?: string;
9
+ baseURL?: string;
10
+ };
11
+ /**
12
+ * GT is the core driver for the General Translation library.
13
+ */
14
+ declare class GT {
15
+ apiKey: string;
16
+ defaultLanguage: string;
17
+ projectID: string;
18
+ baseURL: string;
19
+ /**
20
+ * Constructs an instance of the GT class.
21
+ *
22
+ * @param {GTConstructorParams} [params] - The parameters for initializing the GT instance.
23
+ * @param {string} [params.apiKey=''] - The API key for accessing the translation service.
24
+ * @param {string} [params.defaultLanguage='en'] - The default language for translations.
25
+ * @param {string} [params.projectID=''] - The project ID for the translation service.
26
+ * @param {string} [params.baseURL='https://prod.gtx.dev'] - The base URL for the translation service.
27
+ */
28
+ constructor({ apiKey, defaultLanguage, projectID, baseURL }?: GTConstructorParams);
29
+ /**
30
+ * Translates the content of React children elements.
31
+ *
32
+ * @param {Object} params - The parameters for the translation.
33
+ * @param {any} params.content - The React children content to be translated.
34
+ * @param {string} params.targetLanguage - The target language for the translation.
35
+ * @param {Object} params.metadata - Additional metadata for the translation process.
36
+ *
37
+ * @returns {Promise<any>} - A promise that resolves to the translated content.
38
+ */
39
+ translateReactChildren({ content, targetLanguage, ...metadata }: {
40
+ content: any;
41
+ targetLanguage: string;
42
+ metadata: {
43
+ [key: string]: any;
44
+ };
45
+ }): Promise<any>;
46
+ }
47
+ export default GT;
48
+ export declare const getLanguageObject: typeof _getLanguageObject;
49
+ export declare const getLanguageCode: (languages: string | string[]) => string | string[];
50
+ export declare const getLanguageName: (codes: string | string[]) => string | string[];
51
+ export declare const isSameLanguage: typeof _isSameLanguage;
package/dist/index.js CHANGED
@@ -10,6 +10,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  step((generator = generator.apply(thisArg, _arguments || [])).next());
11
11
  });
12
12
  };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
13
24
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
26
  };
@@ -59,7 +70,8 @@ class GT {
59
70
  * @returns {Promise<any>} - A promise that resolves to the translated content.
60
71
  */
61
72
  translateReactChildren(_a) {
62
- return __awaiter(this, arguments, void 0, function* ({ content, targetLanguage, metadata = {} }) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ var { content, targetLanguage } = _a, metadata = __rest(_a, ["content", "targetLanguage"]);
63
75
  return yield _translateReactChildren_1.default.call(this, content, targetLanguage, metadata);
64
76
  });
65
77
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Translates the given content into the target language using a specified API.
3
+ *
4
+ * @param {Object} this - An object containing baseURL and apiKey for the API.
5
+ * @param {any} content - The content to be translated. This can be of any type.
6
+ * @param {string} targetLanguage - The target language code (e.g., 'en', 'fr') for the translation.
7
+ * @param {Object} metadata - Additional metadata to be sent with the translation request.
8
+ *
9
+ * @returns {Promise<Object | null>} - A promise that resolves to the translated content as an object, or null if an error occurs.
10
+ *
11
+ * @throws {Error} - Throws an error if the response from the API is not ok (status code not in the range 200-299).
12
+ *
13
+ **/
14
+ export default function _translateReactChildren(this: {
15
+ baseURL: string;
16
+ apiKey: string;
17
+ }, content: any, targetLanguage: string, metadata: {
18
+ [key: string]: any;
19
+ }): Promise<Object | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git+https://github.com/General-Translation/js-toolkit.git"
12
+ "url": "git+https://github.com/General-Translation/generaltranslation.git"
13
13
  },
14
14
  "keywords": [
15
15
  "LLM",
@@ -21,9 +21,9 @@
21
21
  "author": "General Translation, Inc.",
22
22
  "license": "ISC",
23
23
  "bugs": {
24
- "url": "https://github.com/General-Translation/js-toolkit/issues"
24
+ "url": "https://github.com/General-Translation/generaltranslation/issues"
25
25
  },
26
- "homepage": "https://github.com/General-Translation/js-toolkit#readme",
26
+ "homepage": "https://github.com/General-Translation/generaltranslation#readme",
27
27
  "devDependencies": {
28
28
  "@types/node": "^20.14.9",
29
29
  "typescript": "^5.5.2"