@markuplint/i18n 4.0.0-dev.28 → 4.0.0-rc.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/$schema.json +2 -0
- package/LICENSE +1 -1
- package/{lib/cjs → cjs}/translator.js +13 -4
- package/esm/index.mjs +1 -0
- package/{lib/translator.js → esm/translator.mjs} +13 -4
- package/esm.mjs +42 -0
- package/locales/ja.json +2 -0
- package/package.json +12 -7
- package/lib/index.js +0 -1
- /package/{lib/cjs → cjs}/index.d.ts +0 -0
- /package/{lib/cjs → cjs}/index.js +0 -0
- /package/{lib/cjs → cjs}/translator.d.ts +0 -0
- /package/{lib/cjs → cjs}/types.d.ts +0 -0
- /package/{lib/cjs → cjs}/types.js +0 -0
- /package/{lib → esm}/index.d.ts +0 -0
- /package/{lib → esm}/translator.d.ts +0 -0
- /package/{lib → esm}/types.d.ts +0 -0
- /package/{lib/types.js → esm/types.mjs} +0 -0
package/$schema.json
CHANGED
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"c:obsolete": { "type": "string" },
|
|
51
51
|
"character": { "type": "string" },
|
|
52
52
|
"characters": { "type": "string" },
|
|
53
|
+
"child element": { "type": "string" },
|
|
53
54
|
"class name": { "type": "string" },
|
|
54
55
|
"code block": { "type": "string" },
|
|
55
56
|
"colon": { "type": "string" },
|
|
@@ -212,6 +213,7 @@
|
|
|
212
213
|
"{0} or more chars": { "type": "string" },
|
|
213
214
|
"{0} or more digits": { "type": "string" },
|
|
214
215
|
"{0} part of {1}": { "type": "string" },
|
|
216
|
+
"{0} requires {1}": { "type": "string" },
|
|
215
217
|
"{0} should {1}": { "type": "string" },
|
|
216
218
|
"{0} should associate with {1}": { "type": "string" },
|
|
217
219
|
"{0} should be {1}": { "type": "string" },
|
package/LICENSE
CHANGED
|
@@ -19,13 +19,20 @@ function translator(localeSet) {
|
|
|
19
19
|
if (keywords.length === 0) {
|
|
20
20
|
return translateKeyword(messageTmpl, '', localeSet);
|
|
21
21
|
}
|
|
22
|
-
const noTranslateIndex = new Set([
|
|
22
|
+
const noTranslateIndex = new Set([
|
|
23
|
+
...messageTmpl.matchAll(
|
|
24
|
+
// eslint-disable-next-line regexp/strict
|
|
25
|
+
/(?<={)\d+(?=\*})/g),
|
|
26
|
+
].map(m => m[0]));
|
|
23
27
|
const key = removeNoTranslateMark(messageTmpl).toLowerCase();
|
|
24
|
-
const
|
|
28
|
+
const sentences = Object.entries(localeSet?.sentences ?? {});
|
|
29
|
+
const sentence = sentences.find(([sentenceKey]) => sentenceKey.toLowerCase() === key)?.[1];
|
|
25
30
|
messageTmpl = sentence ?? key;
|
|
26
31
|
messageTmpl =
|
|
27
32
|
removeNoTranslateMark(input.toLowerCase()) === messageTmpl ? removeNoTranslateMark(input) : messageTmpl;
|
|
28
|
-
message = messageTmpl.replaceAll(
|
|
33
|
+
message = messageTmpl.replaceAll(
|
|
34
|
+
// eslint-disable-next-line regexp/strict
|
|
35
|
+
/{(\d+)(?::(c))?}/g, ($0, number, flag) => {
|
|
29
36
|
const num = Number.parseInt(number);
|
|
30
37
|
if (Number.isNaN(num)) {
|
|
31
38
|
return $0;
|
|
@@ -106,5 +113,7 @@ function toLocaleString(value, locale) {
|
|
|
106
113
|
return value.toString(10);
|
|
107
114
|
}
|
|
108
115
|
function removeNoTranslateMark(message) {
|
|
109
|
-
return message.replaceAll(
|
|
116
|
+
return message.replaceAll(
|
|
117
|
+
// eslint-disable-next-line regexp/strict
|
|
118
|
+
/(?<={\d+)\*(?=})/g, '');
|
|
110
119
|
}
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { translator } from './translator.mjs';
|
|
@@ -16,13 +16,20 @@ export function translator(localeSet) {
|
|
|
16
16
|
if (keywords.length === 0) {
|
|
17
17
|
return translateKeyword(messageTmpl, '', localeSet);
|
|
18
18
|
}
|
|
19
|
-
const noTranslateIndex = new Set([
|
|
19
|
+
const noTranslateIndex = new Set([
|
|
20
|
+
...messageTmpl.matchAll(
|
|
21
|
+
// eslint-disable-next-line regexp/strict
|
|
22
|
+
/(?<={)\d+(?=\*})/g),
|
|
23
|
+
].map(m => m[0]));
|
|
20
24
|
const key = removeNoTranslateMark(messageTmpl).toLowerCase();
|
|
21
|
-
const
|
|
25
|
+
const sentences = Object.entries(localeSet?.sentences ?? {});
|
|
26
|
+
const sentence = sentences.find(([sentenceKey]) => sentenceKey.toLowerCase() === key)?.[1];
|
|
22
27
|
messageTmpl = sentence ?? key;
|
|
23
28
|
messageTmpl =
|
|
24
29
|
removeNoTranslateMark(input.toLowerCase()) === messageTmpl ? removeNoTranslateMark(input) : messageTmpl;
|
|
25
|
-
message = messageTmpl.replaceAll(
|
|
30
|
+
message = messageTmpl.replaceAll(
|
|
31
|
+
// eslint-disable-next-line regexp/strict
|
|
32
|
+
/{(\d+)(?::(c))?}/g, ($0, number, flag) => {
|
|
26
33
|
const num = Number.parseInt(number);
|
|
27
34
|
if (Number.isNaN(num)) {
|
|
28
35
|
return $0;
|
|
@@ -101,5 +108,7 @@ function toLocaleString(value, locale) {
|
|
|
101
108
|
return value.toString(10);
|
|
102
109
|
}
|
|
103
110
|
function removeNoTranslateMark(message) {
|
|
104
|
-
return message.replaceAll(
|
|
111
|
+
return message.replaceAll(
|
|
112
|
+
// eslint-disable-next-line regexp/strict
|
|
113
|
+
/(?<={\d+)\*(?=})/g, '');
|
|
105
114
|
}
|
package/esm.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {string} filePath
|
|
7
|
+
* @param {string} newExtension
|
|
8
|
+
*/
|
|
9
|
+
function renameFileExtension(filePath, newExtension) {
|
|
10
|
+
const dir = path.dirname(filePath);
|
|
11
|
+
const fileName = path.basename(filePath, path.extname(filePath)) + newExtension;
|
|
12
|
+
const newFilePath = path.join(dir, fileName);
|
|
13
|
+
fs.renameSync(filePath, newFilePath);
|
|
14
|
+
return newFilePath;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function replaceInFile(filePath, searchValue, replaceValue) {
|
|
18
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
19
|
+
const result = data.replace(searchValue, replaceValue);
|
|
20
|
+
fs.writeFileSync(filePath, result, 'utf8');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param {string} dir
|
|
26
|
+
*/
|
|
27
|
+
function processDirectory(dir) {
|
|
28
|
+
const files = fs.readdirSync(dir, { withFileTypes: true });
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
const fullPath = path.join(dir, file.name);
|
|
31
|
+
if (file.isDirectory()) {
|
|
32
|
+
processDirectory(fullPath);
|
|
33
|
+
} else {
|
|
34
|
+
if (file.name.endsWith('.js')) {
|
|
35
|
+
const newFilePath = renameFileExtension(fullPath, '.mjs');
|
|
36
|
+
replaceInFile(newFilePath, /\.js/g, '.mjs');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
processDirectory('./esm');
|
package/locales/ja.json
CHANGED
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"c:obsolete": "は廃止されています",
|
|
39
39
|
"character": "文字",
|
|
40
40
|
"characters": "文字",
|
|
41
|
+
"child element": "子要素",
|
|
41
42
|
"class name": "クラス名",
|
|
42
43
|
"code block": "コードブロック",
|
|
43
44
|
"colon": "コロン",
|
|
@@ -196,6 +197,7 @@
|
|
|
196
197
|
"{0} or more chars": "{0}文字以上",
|
|
197
198
|
"{0} or more digits": "{0}桁以上",
|
|
198
199
|
"{0} part of {1}": "{1}の{0}の部分",
|
|
200
|
+
"{0} requires {1}": "{0}に{1}が必要です",
|
|
199
201
|
"{0} should {1}": "{0}は{1}したほうがよいです",
|
|
200
202
|
"{0} should associate with {1}": "{0}は{1}と関連付けたほうがよいです",
|
|
201
203
|
"{0} should be {1}": "{0}は{1}にしたほうがよいです",
|
package/package.json
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/i18n",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc.0",
|
|
4
4
|
"description": "Internationalization for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"private": false,
|
|
9
|
-
"
|
|
9
|
+
"main": "./cjs/index.js",
|
|
10
|
+
"types": "./cjs/index.d.ts",
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
12
|
-
"import":
|
|
13
|
-
|
|
13
|
+
"import": {
|
|
14
|
+
"default": "./esm/index.mjs",
|
|
15
|
+
"types": "./esm/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"require": "./cjs/index.js"
|
|
14
18
|
},
|
|
15
19
|
"./locales/en.json": {
|
|
16
20
|
"import": "./locales/en.json",
|
|
@@ -21,7 +25,6 @@
|
|
|
21
25
|
"require": "./locales/ja.json"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
|
-
"types": "./lib/index.d.ts",
|
|
25
28
|
"publishConfig": {
|
|
26
29
|
"access": "public"
|
|
27
30
|
},
|
|
@@ -29,8 +32,10 @@
|
|
|
29
32
|
"entryPoint": "./src/index.ts"
|
|
30
33
|
},
|
|
31
34
|
"scripts": {
|
|
32
|
-
"build": "
|
|
35
|
+
"build": "yarn build:esm; yarn build:cjs; node ./esm.mjs",
|
|
36
|
+
"build:esm": "tsc",
|
|
37
|
+
"build:cjs": "tsc --module commonjs --outDir cjs",
|
|
33
38
|
"clean": "tsc --build --clean"
|
|
34
39
|
},
|
|
35
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "3fdeb45cb69ed52b3a215a7520cea1181601443f"
|
|
36
41
|
}
|
package/lib/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { translator } from './translator.js';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{lib → esm}/index.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
/package/{lib → esm}/types.d.ts
RENAMED
|
File without changes
|
|
File without changes
|