@gunshi/plugin-i18n 0.29.3 → 0.29.5
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/index.js +9 -27
- package/package.json +13 -13
package/lib/index.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import { plugin } from "@gunshi/plugin";
|
|
2
|
-
|
|
3
|
-
//#region ../shared/src/constants.ts
|
|
4
|
-
/**
|
|
5
|
-
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
6
|
-
* @license MIT
|
|
7
|
-
*/
|
|
8
|
-
const BUILT_IN_PREFIX = "_";
|
|
9
|
-
const PLUGIN_PREFIX = "g";
|
|
10
|
-
const ARG_PREFIX = "arg";
|
|
11
|
-
const BUILT_IN_KEY_SEPARATOR = ":";
|
|
12
|
-
const BUILD_IN_PREFIX_AND_KEY_SEPARATOR = `${BUILT_IN_PREFIX}${BUILT_IN_KEY_SEPARATOR}`;
|
|
13
|
-
const ARG_PREFIX_AND_KEY_SEPARATOR = `${ARG_PREFIX}${BUILT_IN_KEY_SEPARATOR}`;
|
|
2
|
+
const ARG_PREFIX_AND_KEY_SEPARATOR = `arg:`;
|
|
14
3
|
const COMMON_ARGS = {
|
|
15
4
|
help: {
|
|
16
5
|
type: "boolean",
|
|
@@ -23,7 +12,6 @@ const COMMON_ARGS = {
|
|
|
23
12
|
description: "Display this version"
|
|
24
13
|
}
|
|
25
14
|
};
|
|
26
|
-
|
|
27
15
|
//#endregion
|
|
28
16
|
//#region ../resources/locales/en-US.json
|
|
29
17
|
var en_US_default = {
|
|
@@ -41,7 +29,6 @@ var en_US_default = {
|
|
|
41
29
|
help: "Display this help message",
|
|
42
30
|
version: "Display this version"
|
|
43
31
|
};
|
|
44
|
-
|
|
45
32
|
//#endregion
|
|
46
33
|
//#region ../shared/src/utils.ts
|
|
47
34
|
/**
|
|
@@ -55,7 +42,7 @@ var en_US_default = {
|
|
|
55
42
|
* @returns Prefixed built-in key.
|
|
56
43
|
*/
|
|
57
44
|
function resolveBuiltInKey(key) {
|
|
58
|
-
return
|
|
45
|
+
return `_:${key}`;
|
|
59
46
|
}
|
|
60
47
|
/**
|
|
61
48
|
* Resolve a namespaced key for argument resources.
|
|
@@ -70,7 +57,7 @@ function resolveBuiltInKey(key) {
|
|
|
70
57
|
* @returns Prefixed argument key.
|
|
71
58
|
*/
|
|
72
59
|
function resolveArgKey(key, name) {
|
|
73
|
-
return `${name ? `${name}
|
|
60
|
+
return `${name ? `${name}:` : ""}arg:${key}`;
|
|
74
61
|
}
|
|
75
62
|
/**
|
|
76
63
|
* Resolve a namespaced key for non-built-in resources.
|
|
@@ -84,7 +71,7 @@ function resolveArgKey(key, name) {
|
|
|
84
71
|
* @returns Prefixed non-built-in key.
|
|
85
72
|
*/
|
|
86
73
|
function resolveKey(key, name) {
|
|
87
|
-
return `${name ? `${name}
|
|
74
|
+
return `${name ? `${name}:` : ""}${key}`;
|
|
88
75
|
}
|
|
89
76
|
/**
|
|
90
77
|
* Resolve command examples.
|
|
@@ -107,9 +94,8 @@ async function resolveExamples(ctx, examples) {
|
|
|
107
94
|
* @returns A namespaced key for the plugin.
|
|
108
95
|
*/
|
|
109
96
|
function namespacedId(id) {
|
|
110
|
-
return
|
|
97
|
+
return `g:${id}`;
|
|
111
98
|
}
|
|
112
|
-
|
|
113
99
|
//#endregion
|
|
114
100
|
//#region src/translation.ts
|
|
115
101
|
/**
|
|
@@ -183,14 +169,12 @@ var DefaultTranslation = class {
|
|
|
183
169
|
});
|
|
184
170
|
}
|
|
185
171
|
};
|
|
186
|
-
|
|
187
172
|
//#endregion
|
|
188
173
|
//#region src/types.ts
|
|
189
174
|
/**
|
|
190
175
|
* The unique identifier for the i18n plugin.
|
|
191
176
|
*/
|
|
192
177
|
const pluginId = namespacedId("i18n");
|
|
193
|
-
|
|
194
178
|
//#endregion
|
|
195
179
|
//#region src/helpers.ts
|
|
196
180
|
/**
|
|
@@ -284,7 +268,6 @@ function withI18nResource(command, resource) {
|
|
|
284
268
|
resource
|
|
285
269
|
};
|
|
286
270
|
}
|
|
287
|
-
|
|
288
271
|
//#endregion
|
|
289
272
|
//#region src/index.ts
|
|
290
273
|
/**
|
|
@@ -324,7 +307,7 @@ function withI18nResource(command, resource) {
|
|
|
324
307
|
* The default locale string, which format is BCP 47 language tag.
|
|
325
308
|
*/
|
|
326
309
|
const DEFAULT_LOCALE = "en-US";
|
|
327
|
-
const BUILT_IN_PREFIX_CODE =
|
|
310
|
+
const BUILT_IN_PREFIX_CODE = "_".codePointAt(0);
|
|
328
311
|
/**
|
|
329
312
|
* i18n plugin
|
|
330
313
|
*
|
|
@@ -373,7 +356,7 @@ function i18n(options = {}) {
|
|
|
373
356
|
}
|
|
374
357
|
function translate(key, values = Object.create(null)) {
|
|
375
358
|
const strKey = key;
|
|
376
|
-
if (strKey.codePointAt(0) === BUILT_IN_PREFIX_CODE) return (localeBuiltinResources.get(localeStr) || localeBuiltinResources.get(
|
|
359
|
+
if (strKey.codePointAt(0) === BUILT_IN_PREFIX_CODE) return (localeBuiltinResources.get(localeStr) || localeBuiltinResources.get("en-US"))[strKey] || strKey;
|
|
377
360
|
else return adapter.translate(localeStr, strKey, values) || "";
|
|
378
361
|
}
|
|
379
362
|
function setResource(locale, resource) {
|
|
@@ -403,7 +386,7 @@ function i18n(options = {}) {
|
|
|
403
386
|
for (const globalOption of getGlobalOptions()) if (globalOptionResources.has(globalOption)) {
|
|
404
387
|
const optionResource = globalOptionResources.get(globalOption);
|
|
405
388
|
const globalOptionKey = resolveArgKey(globalOption, ctx.name);
|
|
406
|
-
resource[globalOptionKey] = optionResource[localeStr] || optionResource[
|
|
389
|
+
resource[globalOptionKey] = optionResource[localeStr] || optionResource["en-US"] || Object.values(optionResource)[0] || "";
|
|
407
390
|
}
|
|
408
391
|
adapter.setResource(localeStr, Object.assign(Object.create(null), adapter.getResource(localeStr), resource));
|
|
409
392
|
return loaded;
|
|
@@ -460,6 +443,5 @@ async function normalizeResource(resource, ctx) {
|
|
|
460
443
|
else ret[resolveKey(key, ctx.name)] = value;
|
|
461
444
|
return ret;
|
|
462
445
|
}
|
|
463
|
-
|
|
464
446
|
//#endregion
|
|
465
|
-
export { DEFAULT_LOCALE, DefaultTranslation, createTranslationAdapter, i18n as default, defineI18n, defineI18nWithTypes, pluginId, resolveArgKey, resolveBuiltInKey, resolveKey, withI18nResource };
|
|
447
|
+
export { DEFAULT_LOCALE, DefaultTranslation, createTranslationAdapter, i18n as default, defineI18n, defineI18nWithTypes, pluginId, resolveArgKey, resolveBuiltInKey, resolveKey, withI18nResource };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/plugin-i18n",
|
|
3
3
|
"description": "internationalization plugin for gunshi",
|
|
4
|
-
"version": "0.29.
|
|
4
|
+
"version": "0.29.5",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@gunshi/plugin": "0.29.
|
|
56
|
+
"@gunshi/plugin": "0.29.5"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@gunshi/plugin-global": "0.29.
|
|
59
|
+
"@gunshi/plugin-global": "0.29.5"
|
|
60
60
|
},
|
|
61
61
|
"peerDependenciesMeta": {
|
|
62
62
|
"@gunshi/plugin-global": {
|
|
@@ -65,20 +65,20 @@
|
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@intlify/core": "next",
|
|
68
|
-
"deno": "^2.7.
|
|
69
|
-
"jsr": "^0.
|
|
68
|
+
"deno": "^2.7.11",
|
|
69
|
+
"jsr": "^0.14.3",
|
|
70
70
|
"jsr-exports-lint": "^0.4.2",
|
|
71
71
|
"messageformat": "4.0.0",
|
|
72
72
|
"publint": "^0.3.18",
|
|
73
73
|
"tsdown": "0.15.12",
|
|
74
|
-
"typedoc": "^0.28.
|
|
75
|
-
"typedoc-plugin-markdown": "^4.
|
|
76
|
-
"@gunshi/plugin-global": "0.29.
|
|
77
|
-
"@gunshi/
|
|
78
|
-
"@gunshi/
|
|
79
|
-
"@gunshi/resources": "0.29.
|
|
80
|
-
"
|
|
81
|
-
"gunshi": "0.29.
|
|
74
|
+
"typedoc": "^0.28.18",
|
|
75
|
+
"typedoc-plugin-markdown": "^4.11.0",
|
|
76
|
+
"@gunshi/plugin-global": "0.29.5",
|
|
77
|
+
"@gunshi/plugin-renderer": "0.29.5",
|
|
78
|
+
"@gunshi/bone": "0.29.5",
|
|
79
|
+
"@gunshi/resources": "0.29.5",
|
|
80
|
+
"gunshi": "0.29.5",
|
|
81
|
+
"@gunshi/shared": "0.29.5"
|
|
82
82
|
},
|
|
83
83
|
"scripts": {
|
|
84
84
|
"build": "tsdown",
|