generaltranslation 2.0.69 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.md +105 -0
- package/dist/codes/_determineLanguage.js +3 -9
- package/dist/codes/_isSameLanguage.js +1 -4
- package/dist/codes/codes.js +22 -19
- package/dist/formatting/format.js +11 -21
- package/dist/formatting/string_content.js +9 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.js +43 -60
- package/dist/internal.d.ts +7 -0
- package/dist/internal.js +11 -0
- package/dist/settings/libraryDefaultLanguage.js +1 -3
- package/dist/translation/dictionaries/_translateBundle.js +1 -4
- package/dist/translation/dictionaries/_updateProjectDictionary.js +1 -4
- package/dist/translation/react/_translateReact.js +1 -4
- package/dist/translation/strings/_translate.js +1 -4
- package/dist/types/types.js +1 -2
- package/package.json +41 -9
package/LICENSE.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
2
|
+
|
3
|
+
## Abbreviation
|
4
|
+
|
5
|
+
FSL-1.1-ALv2
|
6
|
+
|
7
|
+
## Notice
|
8
|
+
|
9
|
+
Copyright 2024 General Translation, Inc.
|
10
|
+
|
11
|
+
## Terms and Conditions
|
12
|
+
|
13
|
+
### Licensor ("We")
|
14
|
+
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
16
|
+
|
17
|
+
### The Software
|
18
|
+
|
19
|
+
The "Software" is each version of the software that we make available under
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
21
|
+
Conditions with the Software.
|
22
|
+
|
23
|
+
### License Grant
|
24
|
+
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
29
|
+
|
30
|
+
### Permitted Purpose
|
31
|
+
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
33
|
+
means making the Software available to others in a commercial product or
|
34
|
+
service that:
|
35
|
+
|
36
|
+
1. substitutes for the Software;
|
37
|
+
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
39
|
+
that exists as of the date we make the Software available; or
|
40
|
+
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
42
|
+
|
43
|
+
Permitted Purposes specifically include using the Software:
|
44
|
+
|
45
|
+
1. for your internal use and access;
|
46
|
+
|
47
|
+
2. for non-commercial education;
|
48
|
+
|
49
|
+
3. for non-commercial research; and
|
50
|
+
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
53
|
+
|
54
|
+
### Patents
|
55
|
+
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
60
|
+
immediately.
|
61
|
+
|
62
|
+
### Redistribution
|
63
|
+
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
65
|
+
the Software.
|
66
|
+
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
69
|
+
remove any copyright notices provided in or with the Software.
|
70
|
+
|
71
|
+
### Disclaimer
|
72
|
+
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
76
|
+
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
80
|
+
|
81
|
+
### Trademarks
|
82
|
+
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
85
|
+
trademarks, trade names, service marks or product names.
|
86
|
+
|
87
|
+
## Grant of Future License
|
88
|
+
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
93
|
+
will apply:
|
94
|
+
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
96
|
+
this file except in compliance with the License.
|
97
|
+
|
98
|
+
You may obtain a copy of the License at
|
99
|
+
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
101
|
+
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
105
|
+
specific language governing permissions and limitations under the License.
|
@@ -1,16 +1,10 @@
|
|
1
|
-
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.default = _determineLanguage;
|
7
|
-
var _isSameLanguage_1 = __importDefault(require("./_isSameLanguage"));
|
1
|
+
import isSameLanguage from './_isSameLanguage';
|
8
2
|
/**
|
9
3
|
* Given a list of language and a list of approved language, sorted in preference order
|
10
4
|
* Determines which language of the given languages is the best match in the approvedLanguages, prioritizing exact matches and falling back to dialects of the same language
|
11
5
|
* @internal
|
12
6
|
*/
|
13
|
-
function _determineLanguage(languages, approvedLanguages) {
|
7
|
+
export default function _determineLanguage(languages, approvedLanguages) {
|
14
8
|
if (typeof languages === 'string')
|
15
9
|
languages = [languages];
|
16
10
|
if (!approvedLanguages)
|
@@ -19,7 +13,7 @@ function _determineLanguage(languages, approvedLanguages) {
|
|
19
13
|
var exactMatch = approvedLanguages.find(function (approvedLanguage) { return approvedLanguage === language; });
|
20
14
|
if (exactMatch)
|
21
15
|
return { value: exactMatch };
|
22
|
-
var sameLanguage = approvedLanguages.find(function (approvedLanguage) { return (
|
16
|
+
var sameLanguage = approvedLanguages.find(function (approvedLanguage) { return isSameLanguage(approvedLanguage, language); });
|
23
17
|
if (sameLanguage)
|
24
18
|
return { value: sameLanguage };
|
25
19
|
};
|
@@ -1,10 +1,7 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.default = _isSameLanguage;
|
4
1
|
/**
|
5
2
|
* @internal
|
6
3
|
*/
|
7
|
-
function _isSameLanguage() {
|
4
|
+
export default function _isSameLanguage() {
|
8
5
|
var codes = [];
|
9
6
|
for (var _i = 0; _i < arguments.length; _i++) {
|
10
7
|
codes[_i] = arguments[_i];
|
package/dist/codes/codes.js
CHANGED
@@ -1,35 +1,39 @@
|
|
1
|
-
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports._standardizeLanguageCode = exports._isValidLanguageCode = void 0;
|
7
|
-
exports._getLanguageName = _getLanguageName;
|
8
|
-
exports._getLanguageDirection = _getLanguageDirection;
|
9
|
-
var libraryDefaultLanguage_1 = __importDefault(require("../settings/libraryDefaultLanguage"));
|
1
|
+
import libraryDefaultLanguage from "../settings/libraryDefaultLanguage";
|
10
2
|
/**
|
11
3
|
* Checks if a given BCP 47 language code is valid.
|
12
4
|
* @param {string} code - The BCP 47 language code to validate.
|
13
5
|
* @returns {boolean} True if the BCP 47 code is valid, false otherwise.
|
14
6
|
* @internal
|
15
7
|
*/
|
16
|
-
var _isValidLanguageCode = function (code) {
|
8
|
+
export var _isValidLanguageCode = function (code) {
|
17
9
|
try {
|
18
|
-
var
|
19
|
-
|
10
|
+
var _a = new Intl.Locale(code), language = _a.language, region = _a.region, script = _a.script;
|
11
|
+
var displayLanguageNames = new Intl.DisplayNames([libraryDefaultLanguage], { type: 'language' });
|
12
|
+
if (displayLanguageNames.of(language) === language)
|
13
|
+
return false;
|
14
|
+
if (region) {
|
15
|
+
var displayRegionNames = new Intl.DisplayNames([libraryDefaultLanguage], { type: 'region' });
|
16
|
+
if (displayRegionNames.of(region) === region)
|
17
|
+
return false;
|
18
|
+
}
|
19
|
+
if (script) {
|
20
|
+
var displayScriptNames = new Intl.DisplayNames([libraryDefaultLanguage], { type: 'script' });
|
21
|
+
if (displayScriptNames.of(script) === script)
|
22
|
+
return false;
|
23
|
+
}
|
24
|
+
return true;
|
20
25
|
}
|
21
|
-
catch (
|
26
|
+
catch (_b) {
|
22
27
|
return false;
|
23
28
|
}
|
24
29
|
};
|
25
|
-
exports._isValidLanguageCode = _isValidLanguageCode;
|
26
30
|
/**
|
27
31
|
* Standardizes a BCP 47 language code to ensure correct formatting.
|
28
32
|
* @param {string} code - The BCP 47 language code to standardize.
|
29
33
|
* @returns {string} The standardized BCP 47 language code, or an empty string if invalid.
|
30
34
|
* @internal
|
31
35
|
*/
|
32
|
-
var _standardizeLanguageCode = function (code) {
|
36
|
+
export var _standardizeLanguageCode = function (code) {
|
33
37
|
try {
|
34
38
|
return new Intl.Locale(code).toString();
|
35
39
|
}
|
@@ -38,7 +42,6 @@ var _standardizeLanguageCode = function (code) {
|
|
38
42
|
return '';
|
39
43
|
}
|
40
44
|
};
|
41
|
-
exports._standardizeLanguageCode = _standardizeLanguageCode;
|
42
45
|
/**
|
43
46
|
* Retrieves the display name(s) of language code(s) using Intl.DisplayNames.
|
44
47
|
*
|
@@ -47,8 +50,8 @@ exports._standardizeLanguageCode = _standardizeLanguageCode;
|
|
47
50
|
* @returns {string | string[]} The display name(s) corresponding to the code(s), or empty string(s) if invalid.
|
48
51
|
* @internal
|
49
52
|
*/
|
50
|
-
function _getLanguageName(code, defaultLanguage) {
|
51
|
-
if (defaultLanguage === void 0) { defaultLanguage =
|
53
|
+
export function _getLanguageName(code, defaultLanguage) {
|
54
|
+
if (defaultLanguage === void 0) { defaultLanguage = libraryDefaultLanguage; }
|
52
55
|
try {
|
53
56
|
var displayNames_1 = new Intl.DisplayNames([defaultLanguage], { type: 'language' });
|
54
57
|
if (typeof code === 'string') {
|
@@ -81,7 +84,7 @@ function _getLanguageName(code, defaultLanguage) {
|
|
81
84
|
* @returns {string} - 'rtl' if the language is right-to-left, otherwise 'ltr'.
|
82
85
|
* @internal
|
83
86
|
*/
|
84
|
-
function _getLanguageDirection(code) {
|
87
|
+
export function _getLanguageDirection(code) {
|
85
88
|
var _a;
|
86
89
|
try {
|
87
90
|
var locale = new Intl.Locale(code);
|
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __assign = (this && this.__assign) || function () {
|
3
2
|
__assign = Object.assign || function(t) {
|
4
3
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
@@ -10,16 +9,7 @@ var __assign = (this && this.__assign) || function () {
|
|
10
9
|
};
|
11
10
|
return __assign.apply(this, arguments);
|
12
11
|
};
|
13
|
-
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports._formatNum = _formatNum;
|
18
|
-
exports._formatDateTime = _formatDateTime;
|
19
|
-
exports._formatCurrency = _formatCurrency;
|
20
|
-
exports._formatList = _formatList;
|
21
|
-
exports._formatRelativeTime = _formatRelativeTime;
|
22
|
-
var libraryDefaultLanguage_1 = __importDefault(require("../settings/libraryDefaultLanguage"));
|
12
|
+
import libraryDefaultLanguage from '../settings/libraryDefaultLanguage';
|
23
13
|
/**
|
24
14
|
* Formats a number according to the specified languages and options.
|
25
15
|
*
|
@@ -31,8 +21,8 @@ var libraryDefaultLanguage_1 = __importDefault(require("../settings/libraryDefau
|
|
31
21
|
* @returns {string} The formatted number.
|
32
22
|
* @internal
|
33
23
|
*/
|
34
|
-
function _formatNum(_a) {
|
35
|
-
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? [
|
24
|
+
export function _formatNum(_a) {
|
25
|
+
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? [libraryDefaultLanguage] : _b, _c = _a.options, options = _c === void 0 ? {} : _c;
|
36
26
|
return new Intl.NumberFormat(languages, __assign({ numberingSystem: 'latn' }, options)).format(value);
|
37
27
|
}
|
38
28
|
/**
|
@@ -46,8 +36,8 @@ function _formatNum(_a) {
|
|
46
36
|
* @returns {string} The formatted date.
|
47
37
|
* @internal
|
48
38
|
*/
|
49
|
-
function _formatDateTime(_a) {
|
50
|
-
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? [
|
39
|
+
export function _formatDateTime(_a) {
|
40
|
+
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? [libraryDefaultLanguage] : _b, _c = _a.options, options = _c === void 0 ? {} : _c;
|
51
41
|
return new Intl.DateTimeFormat(languages, __assign({ calendar: "gregory", numberingSystem: "latn" }, options)).format(value);
|
52
42
|
}
|
53
43
|
/**
|
@@ -62,8 +52,8 @@ function _formatDateTime(_a) {
|
|
62
52
|
* @returns {string} The formatted currency value.
|
63
53
|
* @internal
|
64
54
|
*/
|
65
|
-
function _formatCurrency(_a) {
|
66
|
-
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? [
|
55
|
+
export function _formatCurrency(_a) {
|
56
|
+
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? [libraryDefaultLanguage] : _b, _c = _a.currency, currency = _c === void 0 ? 'USD' : _c, _d = _a.options, options = _d === void 0 ? {} : _d;
|
67
57
|
return new Intl.NumberFormat(languages, __assign({ style: 'currency', currency: currency, numberingSystem: 'latn' }, options)).format(value);
|
68
58
|
}
|
69
59
|
/**
|
@@ -77,8 +67,8 @@ function _formatCurrency(_a) {
|
|
77
67
|
* @returns {string} The formatted list.
|
78
68
|
* @internal
|
79
69
|
*/
|
80
|
-
function _formatList(_a) {
|
81
|
-
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? [
|
70
|
+
export function _formatList(_a) {
|
71
|
+
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? [libraryDefaultLanguage] : _b, _c = _a.options, options = _c === void 0 ? {} : _c;
|
82
72
|
return new Intl.ListFormat(languages, __assign({ type: 'conjunction', style: 'long' }, options)).format(value);
|
83
73
|
}
|
84
74
|
/**
|
@@ -93,7 +83,7 @@ function _formatList(_a) {
|
|
93
83
|
* @returns {string} The formatted relative time string.
|
94
84
|
* @internal
|
95
85
|
*/
|
96
|
-
function _formatRelativeTime(_a) {
|
97
|
-
var value = _a.value, unit = _a.unit, _b = _a.languages, languages = _b === void 0 ? [
|
86
|
+
export function _formatRelativeTime(_a) {
|
87
|
+
var value = _a.value, unit = _a.unit, _b = _a.languages, languages = _b === void 0 ? [libraryDefaultLanguage] : _b, _c = _a.options, options = _c === void 0 ? {} : _c;
|
98
88
|
return new Intl.RelativeTimeFormat(languages, __assign({ style: "long", numeric: 'auto' }, options)).format(value, unit);
|
99
89
|
}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __assign = (this && this.__assign) || function () {
|
3
2
|
__assign = Object.assign || function(t) {
|
4
3
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
@@ -10,14 +9,8 @@ var __assign = (this && this.__assign) || function () {
|
|
10
9
|
};
|
11
10
|
return __assign.apply(this, arguments);
|
12
11
|
};
|
13
|
-
|
14
|
-
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports._splitStringToContent = _splitStringToContent;
|
18
|
-
exports._renderContentToString = _renderContentToString;
|
19
|
-
var libraryDefaultLanguage_1 = __importDefault(require("../settings/libraryDefaultLanguage"));
|
20
|
-
var format_1 = require("./format");
|
12
|
+
import libraryDefaultLanguage from '../settings/libraryDefaultLanguage';
|
13
|
+
import { _formatCurrency, _formatDateTime, _formatNum, _formatList } from './format';
|
21
14
|
// Variable types mapping
|
22
15
|
var variableTypeMap = {
|
23
16
|
var: "variable",
|
@@ -31,7 +24,7 @@ var variableTypeMap = {
|
|
31
24
|
/**
|
32
25
|
* @internal
|
33
26
|
*/
|
34
|
-
function _splitStringToContent(string) {
|
27
|
+
export function _splitStringToContent(string) {
|
35
28
|
if (typeof string !== 'string')
|
36
29
|
throw new Error("splitStringToContent: ".concat(string, " is not a string!"));
|
37
30
|
var result = [];
|
@@ -73,8 +66,8 @@ function _splitStringToContent(string) {
|
|
73
66
|
/**
|
74
67
|
* @internal
|
75
68
|
*/
|
76
|
-
function _renderContentToString(content, languages, variables, variableOptions) {
|
77
|
-
if (languages === void 0) { languages =
|
69
|
+
export function _renderContentToString(content, languages, variables, variableOptions) {
|
70
|
+
if (languages === void 0) { languages = libraryDefaultLanguage; }
|
78
71
|
if (variables === void 0) { variables = {}; }
|
79
72
|
if (variableOptions === void 0) { variableOptions = {}; }
|
80
73
|
if (typeof content === 'string')
|
@@ -92,20 +85,20 @@ function _renderContentToString(content, languages, variables, variableOptions)
|
|
92
85
|
if (!item.variable)
|
93
86
|
return value;
|
94
87
|
else if (item.variable === "number") {
|
95
|
-
return
|
88
|
+
return _formatNum({
|
96
89
|
value: value,
|
97
90
|
languages: languages,
|
98
91
|
options: variableOptions[item.key]
|
99
92
|
});
|
100
93
|
}
|
101
94
|
else if (item.variable === "currency") {
|
102
|
-
return
|
95
|
+
return _formatCurrency(__assign(__assign({ value: value, languages: languages }, (variableOptions[item.key] && { options: variableOptions[item.key] })), (((_a = variableOptions[item.key]) === null || _a === void 0 ? void 0 : _a.currency) && { currency: variableOptions[item.key].currency })));
|
103
96
|
}
|
104
97
|
else if (item.variable === "datetime") {
|
105
|
-
return
|
98
|
+
return _formatDateTime(__assign({ value: value, languages: languages }, (variableOptions[item.key] && { options: variableOptions[item.key] })));
|
106
99
|
}
|
107
100
|
else if (item.variable === "list") {
|
108
|
-
return
|
101
|
+
return _formatList(__assign({ value: value, languages: languages }, (variableOptions[item.key] && { options: variableOptions[item.key] })));
|
109
102
|
}
|
110
103
|
return value;
|
111
104
|
}
|
package/dist/index.d.ts
CHANGED
@@ -77,7 +77,6 @@ declare class GT {
|
|
77
77
|
*/
|
78
78
|
updateProjectDictionary(updates: Update[], languages?: string[], replace?: boolean): Promise<string[]>;
|
79
79
|
}
|
80
|
-
export default GT;
|
81
80
|
/**
|
82
81
|
* Get the text direction for a given language code using the Intl.Locale API.
|
83
82
|
*
|
@@ -202,3 +201,4 @@ export declare function renderContentToString(content: Content, languages?: stri
|
|
202
201
|
* @returns {string | undefined} - The best matching language from the approvedLanguages list, or undefined if no match is found.
|
203
202
|
*/
|
204
203
|
export declare function determineLanguage(languages: string | string[], approvedLanguages: string[]): string | undefined;
|
204
|
+
export default GT;
|
package/dist/index.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
// `generaltranslation` language toolkit
|
3
2
|
// © 2024, General Translation, Inc.
|
4
3
|
var __assign = (this && this.__assign) || function () {
|
@@ -48,34 +47,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
48
47
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
49
48
|
}
|
50
49
|
};
|
51
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
52
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
53
|
-
};
|
54
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
55
|
-
exports.getLanguageDirection = getLanguageDirection;
|
56
|
-
exports.getLanguageName = getLanguageName;
|
57
|
-
exports.isValidLanguageCode = isValidLanguageCode;
|
58
|
-
exports.standardizeLanguageCode = standardizeLanguageCode;
|
59
|
-
exports.isSameLanguage = isSameLanguage;
|
60
|
-
exports.formatNum = formatNum;
|
61
|
-
exports.formatDateTime = formatDateTime;
|
62
|
-
exports.formatCurrency = formatCurrency;
|
63
|
-
exports.formatList = formatList;
|
64
|
-
exports.formatRelativeTime = formatRelativeTime;
|
65
|
-
exports.splitStringToContent = splitStringToContent;
|
66
|
-
exports.renderContentToString = renderContentToString;
|
67
|
-
exports.determineLanguage = determineLanguage;
|
68
50
|
// ----- IMPORTS ----- //
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
51
|
+
import _translateBundle from './translation/dictionaries/_translateBundle';
|
52
|
+
import _translate from './translation/strings/_translate';
|
53
|
+
import _translateReact from './translation/react/_translateReact';
|
54
|
+
import _updateProjectDictionary from './translation/dictionaries/_updateProjectDictionary';
|
55
|
+
import _determineLanguage from './codes/_determineLanguage';
|
56
|
+
import { _formatNum, _formatCurrency, _formatList, _formatRelativeTime, _formatDateTime } from './formatting/format';
|
57
|
+
import { _splitStringToContent, _renderContentToString } from './formatting/string_content';
|
58
|
+
import { _getLanguageName, _isValidLanguageCode, _getLanguageDirection, _standardizeLanguageCode } from './codes/codes';
|
59
|
+
import _isSameLanguage from './codes/_isSameLanguage';
|
60
|
+
import libraryDefaultLanguage from './settings/libraryDefaultLanguage';
|
79
61
|
// ----- CORE CLASS ----- //
|
80
62
|
var getDefaultFromEnv = function (VARIABLE) {
|
81
63
|
if (typeof process !== 'undefined' && process.env) {
|
@@ -97,7 +79,7 @@ var GT = /** @class */ (function () {
|
|
97
79
|
* @param {string} [params.baseURL='https://prod.gtx.dev'] - The base URL for the translation service.
|
98
80
|
*/
|
99
81
|
function GT(_a) {
|
100
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.apiKey, apiKey = _c === void 0 ? '' : _c, _d = _b.defaultLanguage, defaultLanguage = _d === void 0 ?
|
82
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.apiKey, apiKey = _c === void 0 ? '' : _c, _d = _b.defaultLanguage, defaultLanguage = _d === void 0 ? libraryDefaultLanguage : _d, _e = _b.projectID, projectID = _e === void 0 ? '' : _e, _f = _b.baseURL, baseURL = _f === void 0 ? 'https://prod.gtx.dev' : _f;
|
101
83
|
this.apiKey = apiKey || getDefaultFromEnv('GT_API_KEY');
|
102
84
|
this.projectID = projectID || getDefaultFromEnv('GT_PROJECT_ID');
|
103
85
|
this.defaultLanguage = defaultLanguage.toLowerCase();
|
@@ -119,7 +101,7 @@ var GT = /** @class */ (function () {
|
|
119
101
|
return __awaiter(this, void 0, void 0, function () {
|
120
102
|
return __generator(this, function (_a) {
|
121
103
|
switch (_a.label) {
|
122
|
-
case 0: return [4 /*yield*/, (
|
104
|
+
case 0: return [4 /*yield*/, _translate(this, content, language, __assign({ projectID: this.projectID, defaultLanguage: this.defaultLanguage }, metadata))];
|
123
105
|
case 1: return [2 /*return*/, _a.sent()];
|
124
106
|
}
|
125
107
|
});
|
@@ -139,7 +121,7 @@ var GT = /** @class */ (function () {
|
|
139
121
|
return __awaiter(this, void 0, void 0, function () {
|
140
122
|
return __generator(this, function (_a) {
|
141
123
|
switch (_a.label) {
|
142
|
-
case 0: return [4 /*yield*/, (
|
124
|
+
case 0: return [4 /*yield*/, _translateReact(this, children, language, __assign({ projectID: this.projectID, defaultLanguage: this.defaultLanguage }, metadata))];
|
143
125
|
case 1: return [2 /*return*/, _a.sent()];
|
144
126
|
}
|
145
127
|
});
|
@@ -153,7 +135,7 @@ var GT = /** @class */ (function () {
|
|
153
135
|
GT.prototype.translateBundle = function (requests) {
|
154
136
|
return __awaiter(this, void 0, void 0, function () {
|
155
137
|
return __generator(this, function (_a) {
|
156
|
-
return [2 /*return*/, (
|
138
|
+
return [2 /*return*/, _translateBundle(this, requests)];
|
157
139
|
});
|
158
140
|
});
|
159
141
|
};
|
@@ -170,22 +152,21 @@ var GT = /** @class */ (function () {
|
|
170
152
|
if (languages === void 0) { languages = []; }
|
171
153
|
if (replace === void 0) { replace = false; }
|
172
154
|
return __generator(this, function (_a) {
|
173
|
-
return [2 /*return*/, (
|
155
|
+
return [2 /*return*/, _updateProjectDictionary(this, updates, languages, replace)];
|
174
156
|
});
|
175
157
|
});
|
176
158
|
};
|
177
159
|
return GT;
|
178
160
|
}());
|
179
161
|
// ----- EXPORTS ----- //
|
180
|
-
exports.default = GT;
|
181
162
|
/**
|
182
163
|
* Get the text direction for a given language code using the Intl.Locale API.
|
183
164
|
*
|
184
165
|
* @param {string} code - The language code to check.
|
185
166
|
* @returns {string} - 'rtl' if the language is right-to-left, otherwise 'ltr'.
|
186
167
|
*/
|
187
|
-
function getLanguageDirection(code) {
|
188
|
-
return
|
168
|
+
export function getLanguageDirection(code) {
|
169
|
+
return _getLanguageDirection(code);
|
189
170
|
}
|
190
171
|
;
|
191
172
|
/**
|
@@ -195,8 +176,8 @@ function getLanguageDirection(code) {
|
|
195
176
|
* @param {string} [language = 'en'] - The language for display names.
|
196
177
|
* @returns {string | string[]} The display name(s) corresponding to the code(s), or empty string(s) if invalid.
|
197
178
|
*/
|
198
|
-
function getLanguageName(code, language) {
|
199
|
-
return
|
179
|
+
export function getLanguageName(code, language) {
|
180
|
+
return _getLanguageName(code, language);
|
200
181
|
}
|
201
182
|
;
|
202
183
|
/**
|
@@ -204,8 +185,8 @@ function getLanguageName(code, language) {
|
|
204
185
|
* @param {string} code - The BCP 47 language code to validate.
|
205
186
|
* @returns {boolean} True if the BCP 47 code is valid, false otherwise.
|
206
187
|
*/
|
207
|
-
function isValidLanguageCode(code) {
|
208
|
-
return
|
188
|
+
export function isValidLanguageCode(code) {
|
189
|
+
return _isValidLanguageCode(code);
|
209
190
|
}
|
210
191
|
;
|
211
192
|
/**
|
@@ -213,8 +194,8 @@ function isValidLanguageCode(code) {
|
|
213
194
|
* @param {string} code - The BCP 47 language code to standardize.
|
214
195
|
* @returns {string} The standardized BCP 47 language code.
|
215
196
|
*/
|
216
|
-
function standardizeLanguageCode(code) {
|
217
|
-
return
|
197
|
+
export function standardizeLanguageCode(code) {
|
198
|
+
return _standardizeLanguageCode(code);
|
218
199
|
}
|
219
200
|
;
|
220
201
|
/**
|
@@ -222,12 +203,12 @@ function standardizeLanguageCode(code) {
|
|
222
203
|
* @param {string[]} codes - The BCP 47 language codes to compare.
|
223
204
|
* @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
|
224
205
|
*/
|
225
|
-
function isSameLanguage() {
|
206
|
+
export function isSameLanguage() {
|
226
207
|
var codes = [];
|
227
208
|
for (var _i = 0; _i < arguments.length; _i++) {
|
228
209
|
codes[_i] = arguments[_i];
|
229
210
|
}
|
230
|
-
return
|
211
|
+
return _isSameLanguage.apply(void 0, codes);
|
231
212
|
}
|
232
213
|
;
|
233
214
|
/**
|
@@ -238,8 +219,8 @@ function isSameLanguage() {
|
|
238
219
|
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
|
239
220
|
* @returns {string} The formatted number.
|
240
221
|
*/
|
241
|
-
function formatNum(params) {
|
242
|
-
return
|
222
|
+
export function formatNum(params) {
|
223
|
+
return _formatNum(params);
|
243
224
|
}
|
244
225
|
;
|
245
226
|
/**
|
@@ -250,8 +231,8 @@ function formatNum(params) {
|
|
250
231
|
* @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
|
251
232
|
* @returns {string} The formatted date.
|
252
233
|
*/
|
253
|
-
function formatDateTime(params) {
|
254
|
-
return
|
234
|
+
export function formatDateTime(params) {
|
235
|
+
return _formatDateTime(params);
|
255
236
|
}
|
256
237
|
;
|
257
238
|
/**
|
@@ -263,8 +244,8 @@ function formatDateTime(params) {
|
|
263
244
|
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
|
264
245
|
* @returns {string} The formatted currency value.
|
265
246
|
*/
|
266
|
-
function formatCurrency(params) {
|
267
|
-
return
|
247
|
+
export function formatCurrency(params) {
|
248
|
+
return _formatCurrency(params);
|
268
249
|
}
|
269
250
|
;
|
270
251
|
/**
|
@@ -275,8 +256,8 @@ function formatCurrency(params) {
|
|
275
256
|
* @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
|
276
257
|
* @returns {string} The formatted list.
|
277
258
|
*/
|
278
|
-
function formatList(params) {
|
279
|
-
return
|
259
|
+
export function formatList(params) {
|
260
|
+
return _formatList(params);
|
280
261
|
}
|
281
262
|
;
|
282
263
|
/**
|
@@ -288,8 +269,8 @@ function formatList(params) {
|
|
288
269
|
* @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
|
289
270
|
* @returns {string} The formatted relative time string.
|
290
271
|
*/
|
291
|
-
function formatRelativeTime(params) {
|
292
|
-
return
|
272
|
+
export function formatRelativeTime(params) {
|
273
|
+
return _formatRelativeTime(params);
|
293
274
|
}
|
294
275
|
;
|
295
276
|
/**
|
@@ -297,8 +278,8 @@ function formatRelativeTime(params) {
|
|
297
278
|
* @param {string} string - The input string to split.
|
298
279
|
* @returns {Content} - An array containing strings and VariableObjects.
|
299
280
|
*/
|
300
|
-
function splitStringToContent(string) {
|
301
|
-
return
|
281
|
+
export function splitStringToContent(string) {
|
282
|
+
return _splitStringToContent(string);
|
302
283
|
}
|
303
284
|
;
|
304
285
|
/**
|
@@ -309,8 +290,8 @@ function splitStringToContent(string) {
|
|
309
290
|
* @param {Record<string, any>} [variableOptions={}] - An object containing options for formatting variables.
|
310
291
|
* @returns {string} - The rendered string with variables replaced by their formatted values.
|
311
292
|
*/
|
312
|
-
function renderContentToString(content, languages, variables, variableOptions) {
|
313
|
-
return
|
293
|
+
export function renderContentToString(content, languages, variables, variableOptions) {
|
294
|
+
return _renderContentToString(content, languages, variables, variableOptions);
|
314
295
|
}
|
315
296
|
;
|
316
297
|
/**
|
@@ -319,7 +300,9 @@ function renderContentToString(content, languages, variables, variableOptions) {
|
|
319
300
|
* @param {string[]} approvedLanguages - An array of approved languages, also sorted by preference.
|
320
301
|
* @returns {string | undefined} - The best matching language from the approvedLanguages list, or undefined if no match is found.
|
321
302
|
*/
|
322
|
-
function determineLanguage(languages, approvedLanguages) {
|
323
|
-
return (
|
303
|
+
export function determineLanguage(languages, approvedLanguages) {
|
304
|
+
return _determineLanguage(languages, approvedLanguages);
|
324
305
|
}
|
325
306
|
;
|
307
|
+
// DEFAULT EXPORT
|
308
|
+
export default GT;
|
package/dist/internal.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
// Functions provided to other GT libraries
|
2
|
+
import XXH from 'xxhashjs';
|
3
|
+
/**
|
4
|
+
* Calculates a unique hash for a given string using xxhash.
|
5
|
+
*
|
6
|
+
* @param {string} string - The string to be hashed.
|
7
|
+
* @returns {string} - The resulting hash as a hexadecimal string.
|
8
|
+
*/
|
9
|
+
export function hashString(string) {
|
10
|
+
return XXH.h64().update(string).digest().toString(16);
|
11
|
+
}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -35,12 +34,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
35
|
}
|
37
36
|
};
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
exports.default = _translateBundle;
|
40
37
|
/**
|
41
38
|
* @internal
|
42
39
|
*/
|
43
|
-
function _translateBundle(gt, requests) {
|
40
|
+
export default function _translateBundle(gt, requests) {
|
44
41
|
return __awaiter(this, void 0, void 0, function () {
|
45
42
|
var controller, signal, response, _a, _b, _c, resultArray;
|
46
43
|
var _d, _e, _f;
|
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -35,12 +34,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
35
|
}
|
37
36
|
};
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
exports.default = _updateProjectDictionary;
|
40
37
|
/**
|
41
38
|
* @internal
|
42
39
|
*/
|
43
|
-
function _updateProjectDictionary(gt, updates, languages, replace) {
|
40
|
+
export default function _updateProjectDictionary(gt, updates, languages, replace) {
|
44
41
|
return __awaiter(this, void 0, void 0, function () {
|
45
42
|
var response, _a, _b, _c, result;
|
46
43
|
return __generator(this, function (_d) {
|
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -35,12 +34,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
35
|
}
|
37
36
|
};
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
exports.default = _translateReact;
|
40
37
|
/**
|
41
38
|
* @internal
|
42
39
|
**/
|
43
|
-
function _translateReact(gt, content, targetLanguage, metadata) {
|
40
|
+
export default function _translateReact(gt, content, targetLanguage, metadata) {
|
44
41
|
return __awaiter(this, void 0, void 0, function () {
|
45
42
|
var controller, signal, response, _a, _b, _c;
|
46
43
|
return __generator(this, function (_d) {
|
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -35,12 +34,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
35
|
}
|
37
36
|
};
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
exports.default = _translate;
|
40
37
|
/**
|
41
38
|
* @internal
|
42
39
|
**/
|
43
|
-
function _translate(gt, content, targetLanguage, metadata) {
|
40
|
+
export default function _translate(gt, content, targetLanguage, metadata) {
|
44
41
|
return __awaiter(this, void 0, void 0, function () {
|
45
42
|
var controller, signal, response, _a, _b, _c, result;
|
46
43
|
return __generator(this, function (_d) {
|
package/dist/types/types.js
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
1
|
+
export {};
|
package/package.json
CHANGED
@@ -1,23 +1,18 @@
|
|
1
1
|
{
|
2
2
|
"name": "generaltranslation",
|
3
|
-
"version": "
|
3
|
+
"version": "3.0.1",
|
4
4
|
"description": "A language toolkit for AI developers",
|
5
|
-
"main": "dist/index.
|
5
|
+
"main": "dist/index.cjs.min.cjs",
|
6
|
+
"module": "dist/index.esm.min.mjs",
|
6
7
|
"types": "dist/index.d.ts",
|
7
8
|
"files": [
|
8
9
|
"dist"
|
9
10
|
],
|
10
11
|
"scripts": {
|
12
|
+
"build": "rm -r -f dist; rollup -c",
|
11
13
|
"transpile": "rm -r -f dist; tsc;",
|
12
14
|
"prepublishOnly": "npm run transpile"
|
13
15
|
},
|
14
|
-
"exports": {
|
15
|
-
".": {
|
16
|
-
"import": "./dist/index.js",
|
17
|
-
"require": "./dist/index.js",
|
18
|
-
"types": "./dist/index.d.ts"
|
19
|
-
}
|
20
|
-
},
|
21
16
|
"repository": {
|
22
17
|
"type": "git",
|
23
18
|
"url": "git+https://github.com/General-Translation/generaltranslation.git"
|
@@ -38,10 +33,47 @@
|
|
38
33
|
},
|
39
34
|
"homepage": "https://github.com/General-Translation/generaltranslation#readme",
|
40
35
|
"devDependencies": {
|
36
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
37
|
+
"@rollup/plugin-terser": "^0.4.4",
|
38
|
+
"@rollup/plugin-typescript": "^12.1.1",
|
41
39
|
"@types/node": "^20.14.9",
|
40
|
+
"@types/xxhashjs": "^0.2.4",
|
41
|
+
"rollup": "^4.24.0",
|
42
|
+
"rollup-plugin-dts": "^6.1.1",
|
43
|
+
"tslib": "^2.8.0",
|
42
44
|
"typescript": "^5.6.2"
|
43
45
|
},
|
44
46
|
"typescript": {
|
45
47
|
"definition": "dist/index.d.ts"
|
48
|
+
},
|
49
|
+
"dependencies": {
|
50
|
+
"xxhashjs": "^0.2.2"
|
51
|
+
},
|
52
|
+
"exports": {
|
53
|
+
".": {
|
54
|
+
"types": "./dist/index.d.ts",
|
55
|
+
"require": "./dist/index.cjs.min.cjs",
|
56
|
+
"import": "./dist/index.esm.min.mjs"
|
57
|
+
},
|
58
|
+
"./internal": {
|
59
|
+
"types": "./dist/internal.d.ts",
|
60
|
+
"require": "./dist/internal.cjs.min.cjs",
|
61
|
+
"import": "./dist/internal.esm.min.mjs"
|
62
|
+
}
|
63
|
+
},
|
64
|
+
"typesVersions": {
|
65
|
+
"*": {
|
66
|
+
"internal": [
|
67
|
+
"./dist/internal.d.ts"
|
68
|
+
]
|
69
|
+
}
|
70
|
+
},
|
71
|
+
"compilerOptions": {
|
72
|
+
"baseUrl": ".",
|
73
|
+
"paths": {
|
74
|
+
"generaltranslation/internal": [
|
75
|
+
"/dist/internal"
|
76
|
+
]
|
77
|
+
}
|
46
78
|
}
|
47
79
|
}
|