@markuplint/i18n 4.0.0-alpha.2 → 4.0.0-dev.28
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/$schema.json +4 -3
- package/lib/cjs/translator.js +19 -16
- package/lib/translator.js +19 -16
- package/locales/ja.json +2 -1
- package/package.json +2 -2
package/$schema.json
CHANGED
|
@@ -75,12 +75,12 @@
|
|
|
75
75
|
"double-quote": { "type": "string" },
|
|
76
76
|
"duplicated": { "type": "string" },
|
|
77
77
|
"element": { "type": "string" },
|
|
78
|
-
"empty": { "type": "string" },
|
|
79
78
|
"empty string": { "type": "string" },
|
|
79
|
+
"empty": { "type": "string" },
|
|
80
80
|
"end tag": { "type": "string" },
|
|
81
|
+
"escape in character reference": { "type": "string" },
|
|
81
82
|
"extension": { "type": "string" },
|
|
82
83
|
"feature-identifier": { "type": "string" },
|
|
83
|
-
"escape in character reference": { "type": "string" },
|
|
84
84
|
"floating-point number": { "type": "string" },
|
|
85
85
|
"format": { "type": "string" },
|
|
86
86
|
"fractional part": { "type": "string" },
|
|
@@ -144,9 +144,10 @@
|
|
|
144
144
|
"time": { "type": "string" },
|
|
145
145
|
"token": { "type": "string" },
|
|
146
146
|
"top level": { "type": "string" },
|
|
147
|
-
"type": { "type": "string" },
|
|
148
147
|
"transparent model": { "type": "string" },
|
|
148
|
+
"type": { "type": "string" },
|
|
149
149
|
"unit": { "type": "string" },
|
|
150
|
+
"unknown": { "type": "string" },
|
|
150
151
|
"uppercase": { "type": "string" },
|
|
151
152
|
"url who schema is an http(s) schema": { "type": "string" },
|
|
152
153
|
"use": { "type": "string" },
|
package/lib/cjs/translator.js
CHANGED
|
@@ -19,20 +19,20 @@ function translator(localeSet) {
|
|
|
19
19
|
if (keywords.length === 0) {
|
|
20
20
|
return translateKeyword(messageTmpl, '', localeSet);
|
|
21
21
|
}
|
|
22
|
-
const noTranslateIndex =
|
|
22
|
+
const noTranslateIndex = new Set([...messageTmpl.matchAll(/(?<={)\d+(?=\*})/g)].map(m => m[0]));
|
|
23
23
|
const key = removeNoTranslateMark(messageTmpl).toLowerCase();
|
|
24
24
|
const sentence = localeSet?.sentences?.[key];
|
|
25
25
|
messageTmpl = sentence ?? key;
|
|
26
26
|
messageTmpl =
|
|
27
27
|
removeNoTranslateMark(input.toLowerCase()) === messageTmpl ? removeNoTranslateMark(input) : messageTmpl;
|
|
28
|
-
message = messageTmpl.
|
|
29
|
-
const num = parseInt(number);
|
|
30
|
-
if (isNaN(num)) {
|
|
28
|
+
message = messageTmpl.replaceAll(/{(\d+)(?::(c))?}/g, ($0, number, flag) => {
|
|
29
|
+
const num = Number.parseInt(number);
|
|
30
|
+
if (Number.isNaN(num)) {
|
|
31
31
|
return $0;
|
|
32
32
|
}
|
|
33
|
-
const keyword = keywords[num]
|
|
33
|
+
const keyword = keywords[num] == null ? '' : toString(keywords[num], localeSet?.locale);
|
|
34
34
|
// No translate
|
|
35
|
-
if (noTranslateIndex.
|
|
35
|
+
if (noTranslateIndex.has(number)) {
|
|
36
36
|
return keyword;
|
|
37
37
|
}
|
|
38
38
|
return translateKeyword(keyword, flag, localeSet);
|
|
@@ -53,7 +53,7 @@ function taggedTemplateTranslator(localeSet) {
|
|
|
53
53
|
if (index === strings.raw.length - 1)
|
|
54
54
|
return place;
|
|
55
55
|
const value = keys[i];
|
|
56
|
-
const cFlag =
|
|
56
|
+
const cFlag = (typeof value === 'string' ? value : '').startsWith('c:') ? ':c' : '';
|
|
57
57
|
return `${place}{${i++}${cFlag}}`;
|
|
58
58
|
})
|
|
59
59
|
.join('');
|
|
@@ -64,10 +64,10 @@ exports.taggedTemplateTranslator = taggedTemplateTranslator;
|
|
|
64
64
|
function translateKeyword(keyword, flag, localeSet) {
|
|
65
65
|
// No translate
|
|
66
66
|
if (/^%[^%]+%$/.test(keyword)) {
|
|
67
|
-
return keyword.
|
|
67
|
+
return keyword.replaceAll(/^%|%$/g, '');
|
|
68
68
|
}
|
|
69
69
|
// "%" prefix and suffix escaped
|
|
70
|
-
keyword = keyword.
|
|
70
|
+
keyword = keyword.replaceAll(/^%%|%%$/g, '%');
|
|
71
71
|
const key = flag ? `${flag}:${keyword}` : keyword;
|
|
72
72
|
const replacedWord =
|
|
73
73
|
// finding with flag
|
|
@@ -78,24 +78,27 @@ function translateKeyword(keyword, flag, localeSet) {
|
|
|
78
78
|
}
|
|
79
79
|
function toString(value, locale = 'en') {
|
|
80
80
|
switch (typeof value) {
|
|
81
|
-
case 'string':
|
|
81
|
+
case 'string': {
|
|
82
82
|
return value;
|
|
83
|
-
|
|
83
|
+
}
|
|
84
|
+
case 'number': {
|
|
84
85
|
return toLocaleString(value, locale);
|
|
85
|
-
|
|
86
|
+
}
|
|
87
|
+
case 'boolean': {
|
|
86
88
|
return `${value}`;
|
|
89
|
+
}
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
function toLocaleString(value, locale) {
|
|
90
93
|
try {
|
|
91
94
|
return value.toLocaleString(locale);
|
|
92
95
|
}
|
|
93
|
-
catch (
|
|
94
|
-
if (
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error instanceof RangeError) {
|
|
95
98
|
try {
|
|
96
99
|
return value.toLocaleString('en');
|
|
97
100
|
}
|
|
98
|
-
catch
|
|
101
|
+
catch {
|
|
99
102
|
// void
|
|
100
103
|
}
|
|
101
104
|
}
|
|
@@ -103,5 +106,5 @@ function toLocaleString(value, locale) {
|
|
|
103
106
|
return value.toString(10);
|
|
104
107
|
}
|
|
105
108
|
function removeNoTranslateMark(message) {
|
|
106
|
-
return message.
|
|
109
|
+
return message.replaceAll(/(?<={\d+)\*(?=})/g, '');
|
|
107
110
|
}
|
package/lib/translator.js
CHANGED
|
@@ -16,20 +16,20 @@ export function translator(localeSet) {
|
|
|
16
16
|
if (keywords.length === 0) {
|
|
17
17
|
return translateKeyword(messageTmpl, '', localeSet);
|
|
18
18
|
}
|
|
19
|
-
const noTranslateIndex =
|
|
19
|
+
const noTranslateIndex = new Set([...messageTmpl.matchAll(/(?<={)\d+(?=\*})/g)].map(m => m[0]));
|
|
20
20
|
const key = removeNoTranslateMark(messageTmpl).toLowerCase();
|
|
21
21
|
const sentence = localeSet?.sentences?.[key];
|
|
22
22
|
messageTmpl = sentence ?? key;
|
|
23
23
|
messageTmpl =
|
|
24
24
|
removeNoTranslateMark(input.toLowerCase()) === messageTmpl ? removeNoTranslateMark(input) : messageTmpl;
|
|
25
|
-
message = messageTmpl.
|
|
26
|
-
const num = parseInt(number);
|
|
27
|
-
if (isNaN(num)) {
|
|
25
|
+
message = messageTmpl.replaceAll(/{(\d+)(?::(c))?}/g, ($0, number, flag) => {
|
|
26
|
+
const num = Number.parseInt(number);
|
|
27
|
+
if (Number.isNaN(num)) {
|
|
28
28
|
return $0;
|
|
29
29
|
}
|
|
30
|
-
const keyword = keywords[num]
|
|
30
|
+
const keyword = keywords[num] == null ? '' : toString(keywords[num], localeSet?.locale);
|
|
31
31
|
// No translate
|
|
32
|
-
if (noTranslateIndex.
|
|
32
|
+
if (noTranslateIndex.has(number)) {
|
|
33
33
|
return keyword;
|
|
34
34
|
}
|
|
35
35
|
return translateKeyword(keyword, flag, localeSet);
|
|
@@ -49,7 +49,7 @@ export function taggedTemplateTranslator(localeSet) {
|
|
|
49
49
|
if (index === strings.raw.length - 1)
|
|
50
50
|
return place;
|
|
51
51
|
const value = keys[i];
|
|
52
|
-
const cFlag =
|
|
52
|
+
const cFlag = (typeof value === 'string' ? value : '').startsWith('c:') ? ':c' : '';
|
|
53
53
|
return `${place}{${i++}${cFlag}}`;
|
|
54
54
|
})
|
|
55
55
|
.join('');
|
|
@@ -59,10 +59,10 @@ export function taggedTemplateTranslator(localeSet) {
|
|
|
59
59
|
function translateKeyword(keyword, flag, localeSet) {
|
|
60
60
|
// No translate
|
|
61
61
|
if (/^%[^%]+%$/.test(keyword)) {
|
|
62
|
-
return keyword.
|
|
62
|
+
return keyword.replaceAll(/^%|%$/g, '');
|
|
63
63
|
}
|
|
64
64
|
// "%" prefix and suffix escaped
|
|
65
|
-
keyword = keyword.
|
|
65
|
+
keyword = keyword.replaceAll(/^%%|%%$/g, '%');
|
|
66
66
|
const key = flag ? `${flag}:${keyword}` : keyword;
|
|
67
67
|
const replacedWord =
|
|
68
68
|
// finding with flag
|
|
@@ -73,24 +73,27 @@ function translateKeyword(keyword, flag, localeSet) {
|
|
|
73
73
|
}
|
|
74
74
|
function toString(value, locale = 'en') {
|
|
75
75
|
switch (typeof value) {
|
|
76
|
-
case 'string':
|
|
76
|
+
case 'string': {
|
|
77
77
|
return value;
|
|
78
|
-
|
|
78
|
+
}
|
|
79
|
+
case 'number': {
|
|
79
80
|
return toLocaleString(value, locale);
|
|
80
|
-
|
|
81
|
+
}
|
|
82
|
+
case 'boolean': {
|
|
81
83
|
return `${value}`;
|
|
84
|
+
}
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
function toLocaleString(value, locale) {
|
|
85
88
|
try {
|
|
86
89
|
return value.toLocaleString(locale);
|
|
87
90
|
}
|
|
88
|
-
catch (
|
|
89
|
-
if (
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error instanceof RangeError) {
|
|
90
93
|
try {
|
|
91
94
|
return value.toLocaleString('en');
|
|
92
95
|
}
|
|
93
|
-
catch
|
|
96
|
+
catch {
|
|
94
97
|
// void
|
|
95
98
|
}
|
|
96
99
|
}
|
|
@@ -98,5 +101,5 @@ function toLocaleString(value, locale) {
|
|
|
98
101
|
return value.toString(10);
|
|
99
102
|
}
|
|
100
103
|
function removeNoTranslateMark(message) {
|
|
101
|
-
return message.
|
|
104
|
+
return message.replaceAll(/(?<={\d+)\*(?=})/g, '');
|
|
102
105
|
}
|
package/locales/ja.json
CHANGED
|
@@ -132,9 +132,10 @@
|
|
|
132
132
|
"time": "時間",
|
|
133
133
|
"token": "トークン",
|
|
134
134
|
"top level": "トップレベル",
|
|
135
|
-
"type": "型",
|
|
136
135
|
"transparent model": "トランスペアレントモデル",
|
|
136
|
+
"type": "型",
|
|
137
137
|
"unit": "単位",
|
|
138
|
+
"unknown": "不明",
|
|
138
139
|
"uppercase": "大文字",
|
|
139
140
|
"url who schema is an http(s) schema": "HTTP(S)スキーマのURL",
|
|
140
141
|
"use": "使用",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/i18n",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-dev.28+0131de5e",
|
|
4
4
|
"description": "Internationalization for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"build": "tsc; tsc --module commonjs --outDir lib/cjs",
|
|
33
33
|
"clean": "tsc --build --clean"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "0131de5ea9dd6d3fd5472d7b414b66644c758881"
|
|
36
36
|
}
|