intl-template 1.0.0-alpha.4 → 1.0.0
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/intl.js +123 -207
- package/package.json +4 -8
- package/src/intl.js +8 -56
- package/src/intl.test.js +1 -22
- package/dist/intl.d.ts +0 -57
- package/dist/intl.js.map +0 -1
- package/tsconfig.json +0 -19
package/dist/intl.js
CHANGED
|
@@ -1,216 +1,132 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
+
var __toCommonJS = (from) => {
|
|
7
|
+
var entry = __moduleCache.get(from), desc;
|
|
8
|
+
if (entry)
|
|
9
|
+
return entry;
|
|
10
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
}));
|
|
16
|
+
__moduleCache.set(from, entry);
|
|
17
|
+
return entry;
|
|
20
18
|
};
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
29
27
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
|
|
29
|
+
// src/intl.js
|
|
30
|
+
var exports_intl = {};
|
|
31
|
+
__export(exports_intl, {
|
|
32
|
+
parseTemplate: () => parseTemplate,
|
|
33
|
+
l10n: () => l10n,
|
|
34
|
+
default: () => intl_default,
|
|
35
|
+
Translation: () => Translation,
|
|
36
|
+
Runes: () => Runes
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(exports_intl);
|
|
39
|
+
|
|
40
|
+
class Runes extends Array {
|
|
41
|
+
toString() {
|
|
42
|
+
return this.join("");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function parseTemplate(templateString) {
|
|
46
|
+
const order = [];
|
|
47
|
+
const template = [];
|
|
48
|
+
const parts = templateString.split(/({\d*})/);
|
|
49
|
+
parts.forEach((part) => {
|
|
50
|
+
if (part.match(/^{\d*}$/)) {
|
|
51
|
+
if (part === "{}") {
|
|
52
|
+
order.push(order.length);
|
|
53
|
+
} else {
|
|
54
|
+
order.push(parseInt(part.slice(1, -1), 10));
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
template.push(part);
|
|
35
58
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
return Runes;
|
|
40
|
-
}(Array));
|
|
41
|
-
export { Runes };
|
|
42
|
-
/**
|
|
43
|
-
* Parses a template string and extracts the template parts and order of slots.
|
|
44
|
-
* @param {string} templateString - The template string to parse.
|
|
45
|
-
* @returns {{ template: string[], order: number[] }}
|
|
46
|
-
*/
|
|
47
|
-
export function parseTemplate(templateString) {
|
|
48
|
-
var order = [];
|
|
49
|
-
var template = [];
|
|
50
|
-
var parts = templateString.split(/({\d*})/);
|
|
51
|
-
parts.forEach(function (part) {
|
|
52
|
-
if (part.match(/^{\d*}$/)) {
|
|
53
|
-
if (part === '{}') {
|
|
54
|
-
order.push(order.length);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
// slot with order, e.g. `{2}abc{1}def{0}`
|
|
58
|
-
order.push(parseInt(part.slice(1, -1), 10));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
template.push(part);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
return { template: template, order: order };
|
|
59
|
+
});
|
|
60
|
+
return { template, order };
|
|
66
61
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
},
|
|
89
|
-
set: function (templates, locale, regionTemplates) {
|
|
90
|
-
templates[locale] = Object.entries(regionTemplates).reduce(function (region, _a) {
|
|
91
|
-
var key = _a[0], value = _a[1];
|
|
92
|
-
region[key] = parseTemplate(value);
|
|
93
|
-
return region;
|
|
94
|
-
}, {});
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
}));
|
|
98
|
-
/**
|
|
99
|
-
* Translates a string based on the provided locale and strings.
|
|
100
|
-
*
|
|
101
|
-
* @param {string} locale - The locale to use for translation.
|
|
102
|
-
* @param {TemplateStringsArray | string} strings - The string or array of strings to be translated.
|
|
103
|
-
* @param {...any} parts - The dynamic parts to be inserted into the translated string.
|
|
104
|
-
* @returns {Runes} - The translated string with dynamic parts inserted.
|
|
105
|
-
* @throws {Error} - If the length of the template parts does not match the length of the template.
|
|
106
|
-
*/
|
|
107
|
-
this.translate = function (locale, strings) {
|
|
108
|
-
var _a, _b, _c;
|
|
109
|
-
var parts = [];
|
|
110
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
111
|
-
parts[_i - 2] = arguments[_i];
|
|
112
|
-
}
|
|
113
|
-
if (typeof strings === "string") {
|
|
114
|
-
strings = strings.split("{}");
|
|
115
|
-
}
|
|
116
|
-
var key = strings.join("{}");
|
|
117
|
-
var translation = (_a = __classPrivateFieldGet(_this, _Translation_templates, "f")) === null || _a === void 0 ? void 0 : _a[locale];
|
|
118
|
-
if (!translation) {
|
|
119
|
-
translation = __classPrivateFieldGet(_this, _Translation_templates, "f")[_this.defaultLocale];
|
|
120
|
-
}
|
|
121
|
-
var _d = (translation === null || translation === void 0 ? void 0 : translation[key]) || {}, template = _d.template, order = _d.order;
|
|
122
|
-
if (!template) {
|
|
123
|
-
if (((_c = (_b = import.meta) === null || _b === void 0 ? void 0 : _b.env) === null || _c === void 0 ? void 0 : _c.MODE) === "development") {
|
|
124
|
-
console.warn("not match translate key, ".concat(key), { translation: translation, locale: locale, strings: strings, parts: parts });
|
|
125
|
-
}
|
|
126
|
-
template = strings.slice();
|
|
127
|
-
order = parts.map(function (_, i) { return i; });
|
|
128
|
-
}
|
|
129
|
-
if (parts.length !== template.length - 1) {
|
|
130
|
-
throw new Error("translate template parts length does not match. locale: ".concat(locale, ", key: ").concat(key));
|
|
131
|
-
}
|
|
132
|
-
var runes = template.reduce(function (runes, template, idx) {
|
|
133
|
-
runes.push(template);
|
|
134
|
-
var orderIdx = order[idx];
|
|
135
|
-
if (orderIdx >= 0) {
|
|
136
|
-
var part = parts[orderIdx];
|
|
137
|
-
if (typeof part === "function") {
|
|
138
|
-
runes.push(part(locale));
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
runes.push(part);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return runes;
|
|
145
|
-
}, new Runes());
|
|
146
|
-
return runes;
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* Use regex extract template and vars
|
|
150
|
-
* @param {*} locale
|
|
151
|
-
* @param {*} regexString
|
|
152
|
-
* @param {*} matchString
|
|
153
|
-
* @returns {Runes}
|
|
154
|
-
*/
|
|
155
|
-
this.translateByRegEx = function (locale, regexString, matchString) {
|
|
156
|
-
var _a = regexTemplate(regexString, matchString), parts = _a.parts, strings = _a.strings;
|
|
157
|
-
return _this.translate.apply(_this, __spreadArray([locale, strings], parts, false));
|
|
158
|
-
};
|
|
159
|
-
this.l10n = function (strings) {
|
|
160
|
-
var parts = [];
|
|
161
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
162
|
-
parts[_i - 1] = arguments[_i];
|
|
163
|
-
}
|
|
164
|
-
return translation.translate.apply(translation, __spreadArray([_this.defaultLocale, strings], parts, false));
|
|
165
|
-
};
|
|
166
|
-
this.l10nRegExp = function (regexString, matchString) {
|
|
167
|
-
return translation.translateByRegEx(_this.defaultLocale, regexString, matchString);
|
|
168
|
-
};
|
|
169
|
-
this.defaultLocale = locale;
|
|
62
|
+
|
|
63
|
+
class Translation {
|
|
64
|
+
mode = "react";
|
|
65
|
+
#templates = new Proxy({}, {
|
|
66
|
+
get(templates, locale) {
|
|
67
|
+
return new Proxy(templates[locale] || {}, {
|
|
68
|
+
set(region, key, value) {
|
|
69
|
+
if (typeof value !== "string") {
|
|
70
|
+
throw new Error("Template must be a string.");
|
|
71
|
+
}
|
|
72
|
+
region[key] = parseTemplate(value);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
set(templates, locale, regionTemplates) {
|
|
78
|
+
templates[locale] = Object.entries(regionTemplates).reduce((region, [key, value]) => {
|
|
79
|
+
region[key] = parseTemplate(value);
|
|
80
|
+
return region;
|
|
81
|
+
}, {});
|
|
82
|
+
return true;
|
|
170
83
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
var locale = _a[0], regionTemplates = _a[1];
|
|
179
|
-
__classPrivateFieldGet(_this, _Translation_templates, "f")[locale] = regionTemplates;
|
|
180
|
-
});
|
|
181
|
-
return true;
|
|
182
|
-
},
|
|
183
|
-
enumerable: false,
|
|
184
|
-
configurable: true
|
|
84
|
+
});
|
|
85
|
+
get templates() {
|
|
86
|
+
return this.#templates;
|
|
87
|
+
}
|
|
88
|
+
set templates(value) {
|
|
89
|
+
Object.entries(value).forEach(([locale, regionTemplates]) => {
|
|
90
|
+
this.#templates[locale] = regionTemplates;
|
|
185
91
|
});
|
|
186
|
-
return
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
var strings = [];
|
|
202
|
-
var matches = new RegExp(regexString).exec(matchString);
|
|
203
|
-
if (!matches) {
|
|
204
|
-
return { parts: [], strings: strings };
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
translate = (locale, strings, ...parts) => {
|
|
95
|
+
if (typeof strings === "string") {
|
|
96
|
+
strings = strings.split("{}");
|
|
97
|
+
}
|
|
98
|
+
const key = strings.join("{}");
|
|
99
|
+
const translation = this.#templates?.[locale];
|
|
100
|
+
let { template, order } = translation?.[key] || {};
|
|
101
|
+
if (!template) {
|
|
102
|
+
if (import.meta?.env?.MODE === "development") {
|
|
103
|
+
console.warn(`not match translate key, ${key}`, { translation, locale, strings, parts });
|
|
104
|
+
}
|
|
105
|
+
template = strings.slice();
|
|
106
|
+
order = parts.map((_, i) => i);
|
|
205
107
|
}
|
|
206
|
-
parts
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
108
|
+
if (parts.length !== template.length - 1) {
|
|
109
|
+
throw new Error(`translate template parts length does not match. locale: ${locale}, key: ${key}`);
|
|
110
|
+
}
|
|
111
|
+
const runes = template.reduce((runes2, template2, idx) => {
|
|
112
|
+
runes2.push(template2);
|
|
113
|
+
const orderIdx = order[idx];
|
|
114
|
+
if (orderIdx >= 0) {
|
|
115
|
+
const part = parts[orderIdx];
|
|
116
|
+
if (typeof part === "function") {
|
|
117
|
+
runes2.push(part(locale));
|
|
118
|
+
} else {
|
|
119
|
+
runes2.push(part);
|
|
212
120
|
}
|
|
213
|
-
|
|
214
|
-
|
|
121
|
+
}
|
|
122
|
+
return runes2;
|
|
123
|
+
}, new Runes);
|
|
124
|
+
if (this.mode !== "react") {
|
|
125
|
+
return runes.toString();
|
|
126
|
+
}
|
|
127
|
+
return runes;
|
|
128
|
+
};
|
|
215
129
|
}
|
|
216
|
-
|
|
130
|
+
var translation = new Translation;
|
|
131
|
+
var intl_default = translation;
|
|
132
|
+
var l10n = translation.translate.bind(null, globalThis?.navigator?.language);
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-template",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "l10n tagged template literals",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/intl.js",
|
|
7
7
|
"module": "src/intl.js",
|
|
8
8
|
"repository": "github:performonkey/intl-template",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "
|
|
11
|
-
"test": "node --test"
|
|
10
|
+
"build": "bun build src/intl.js --outdir=dist --format=cjs"
|
|
12
11
|
},
|
|
13
12
|
"keywords": [
|
|
14
13
|
"i18n",
|
|
@@ -16,8 +15,5 @@
|
|
|
16
15
|
"tagged template literals"
|
|
17
16
|
],
|
|
18
17
|
"author": "p10y",
|
|
19
|
-
"license": "ISC"
|
|
20
|
-
|
|
21
|
-
"typescript": "^5.0.0"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
18
|
+
"license": "ISC"
|
|
19
|
+
}
|
package/src/intl.js
CHANGED
|
@@ -33,9 +33,8 @@ export function parseTemplate(templateString) {
|
|
|
33
33
|
* Represents a Translation object that handles string translation based on locale and templates.
|
|
34
34
|
*/
|
|
35
35
|
export class Translation {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
36
|
+
/** @type {"" | "react"} */
|
|
37
|
+
mode = "react"
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
40
|
* Templates object that stores the translation templates for each locale.
|
|
@@ -93,10 +92,7 @@ export class Translation {
|
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
const key = strings.join("{}")
|
|
96
|
-
|
|
97
|
-
if (!translation) {
|
|
98
|
-
translation = this.#templates[this.defaultLocale]
|
|
99
|
-
}
|
|
95
|
+
const translation = this.#templates?.[locale]
|
|
100
96
|
let { template, order } = translation?.[key] || {}
|
|
101
97
|
if (!template) {
|
|
102
98
|
if (import.meta?.env?.MODE === "development") {
|
|
@@ -126,27 +122,11 @@ export class Translation {
|
|
|
126
122
|
return runes
|
|
127
123
|
}, new Runes())
|
|
128
124
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Use regex extract template and vars
|
|
134
|
-
* @param {*} locale
|
|
135
|
-
* @param {*} regexString
|
|
136
|
-
* @param {*} matchString
|
|
137
|
-
* @returns {Runes}
|
|
138
|
-
*/
|
|
139
|
-
translateByRegEx = (locale, regexString, matchString) => {
|
|
140
|
-
const { parts, strings } = regexTemplate(regexString, matchString)
|
|
141
|
-
return this.translate(locale, strings, ...parts);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
l10n = (strings, ...parts) => {
|
|
145
|
-
return translation.translate(this.defaultLocale, strings, ...parts)
|
|
146
|
-
}
|
|
125
|
+
if (this.mode !== "react") {
|
|
126
|
+
return runes.toString()
|
|
127
|
+
}
|
|
147
128
|
|
|
148
|
-
|
|
149
|
-
return translation.translateByRegEx(this.defaultLocale, regexString, matchString)
|
|
129
|
+
return runes
|
|
150
130
|
}
|
|
151
131
|
}
|
|
152
132
|
|
|
@@ -154,32 +134,4 @@ const translation = new Translation()
|
|
|
154
134
|
|
|
155
135
|
export default translation
|
|
156
136
|
|
|
157
|
-
export const l10n = translation.
|
|
158
|
-
|
|
159
|
-
export const l10nRegExp = translation.l10nRegExp
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* @param {string} regexString
|
|
163
|
-
* @param {string} matchString
|
|
164
|
-
* @returns {{ strings: Array<string>, parts: Array<string> }}
|
|
165
|
-
*/
|
|
166
|
-
export function regexTemplate(regexString, matchString) {
|
|
167
|
-
let parts = [];
|
|
168
|
-
const strings = [];
|
|
169
|
-
|
|
170
|
-
const matches = new RegExp(regexString).exec(matchString)
|
|
171
|
-
if (!matches) {
|
|
172
|
-
return { parts: [], strings }
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
parts = matches.slice(1)
|
|
176
|
-
regexString
|
|
177
|
-
.split(/(\([^)]+\))/) // split by regex group
|
|
178
|
-
.forEach(part => {
|
|
179
|
-
if (!part.startsWith("(") || !part.endsWith(")")) {
|
|
180
|
-
strings.push(part)
|
|
181
|
-
}
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
return { strings, parts };
|
|
185
|
-
}
|
|
137
|
+
export const l10n = translation.translate.bind(null, globalThis?.navigator?.language);
|
package/src/intl.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert"
|
|
2
2
|
import test from "node:test"
|
|
3
|
-
import { Translation, Runes
|
|
3
|
+
import { Translation, Runes } from "./intl.js"
|
|
4
4
|
|
|
5
5
|
test("template", async (t) => {
|
|
6
6
|
await t.test("multiple locale template parse", () => {
|
|
@@ -124,27 +124,6 @@ test("translation.translate", async (t) => {
|
|
|
124
124
|
})
|
|
125
125
|
})
|
|
126
126
|
|
|
127
|
-
test("translation.regexTranslate", async (t) => {
|
|
128
|
-
await t.test("regexTranslate", () => {
|
|
129
|
-
const translation = new Translation("zh-CN")
|
|
130
|
-
translation.templates["zh-CN"] = {
|
|
131
|
-
"abc {} def {}": "甲乙丙 {1} {0} 丁戊卯",
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
assert.equal(
|
|
135
|
-
translation.regexTranslate("zh-CN", "abc (\\d+) def (\\d+)", "abc 123 def 345").toString(),
|
|
136
|
-
"甲乙丙 345 123 丁戊卯"
|
|
137
|
-
)
|
|
138
|
-
})
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
test("regexTemplate", async (t) => {
|
|
142
|
-
assert.deepEqual(
|
|
143
|
-
regexTemplate("(\\d+) def (\\d+)", "123 def 345"),
|
|
144
|
-
{ strings: ["", " def ", ""], parts: ['123', '345'] }
|
|
145
|
-
)
|
|
146
|
-
})
|
|
147
|
-
|
|
148
127
|
test("Runes", async (t) => {
|
|
149
128
|
assert.equal(
|
|
150
129
|
new Runes('a', ' b ', 1, 2).toString(),
|
package/dist/intl.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parses a template string and extracts the template parts and order of slots.
|
|
3
|
-
* @param {string} templateString - The template string to parse.
|
|
4
|
-
* @returns {{ template: string[], order: number[] }}
|
|
5
|
-
*/
|
|
6
|
-
export function parseTemplate(templateString: string): {
|
|
7
|
-
template: string[];
|
|
8
|
-
order: number[];
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* @param {string} regexString
|
|
12
|
-
* @param {string} matchString
|
|
13
|
-
* @returns {{ strings: Array<string>, parts: Array<string> }}
|
|
14
|
-
*/
|
|
15
|
-
export function regexTemplate(regexString: string, matchString: string): {
|
|
16
|
-
strings: Array<string>;
|
|
17
|
-
parts: Array<string>;
|
|
18
|
-
};
|
|
19
|
-
export class Runes extends Array<any> {
|
|
20
|
-
constructor(arrayLength?: number | undefined);
|
|
21
|
-
constructor(arrayLength: number);
|
|
22
|
-
constructor(...items: any[]);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Represents a Translation object that handles string translation based on locale and templates.
|
|
26
|
-
*/
|
|
27
|
-
export class Translation {
|
|
28
|
-
constructor(locale: any);
|
|
29
|
-
defaultLocale: any;
|
|
30
|
-
set templates(value: ProxyConstructor);
|
|
31
|
-
get templates(): ProxyConstructor;
|
|
32
|
-
/**
|
|
33
|
-
* Translates a string based on the provided locale and strings.
|
|
34
|
-
*
|
|
35
|
-
* @param {string} locale - The locale to use for translation.
|
|
36
|
-
* @param {TemplateStringsArray | string} strings - The string or array of strings to be translated.
|
|
37
|
-
* @param {...any} parts - The dynamic parts to be inserted into the translated string.
|
|
38
|
-
* @returns {Runes} - The translated string with dynamic parts inserted.
|
|
39
|
-
* @throws {Error} - If the length of the template parts does not match the length of the template.
|
|
40
|
-
*/
|
|
41
|
-
translate: (locale: string, strings: TemplateStringsArray | string, ...parts: any[]) => Runes;
|
|
42
|
-
/**
|
|
43
|
-
* Use regex extract template and vars
|
|
44
|
-
* @param {*} locale
|
|
45
|
-
* @param {*} regexString
|
|
46
|
-
* @param {*} matchString
|
|
47
|
-
* @returns {Runes}
|
|
48
|
-
*/
|
|
49
|
-
translateByRegEx: (locale: any, regexString: any, matchString: any) => Runes;
|
|
50
|
-
l10n: (strings: any, ...parts: any[]) => Runes;
|
|
51
|
-
l10nRegExp: (regexString: any, matchString: any) => Runes;
|
|
52
|
-
#private;
|
|
53
|
-
}
|
|
54
|
-
export default translation;
|
|
55
|
-
export function l10n(strings: any, ...parts: any[]): Runes;
|
|
56
|
-
export function l10nRegExp(regexString: any, matchString: any): Runes;
|
|
57
|
-
declare const translation: Translation;
|
package/dist/intl.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"intl.js","sourceR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
-
"outDir": "./dist",
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"strict": true,
|
|
16
|
-
"skipLibCheck": true
|
|
17
|
-
},
|
|
18
|
-
"exclude": ["dist", "src/*.test.js", "jest.config.js"]
|
|
19
|
-
}
|