@markuplint/i18n 4.0.0-alpha.4 → 4.0.0-alpha.6
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/LICENSE +1 -1
- package/{lib → cjs}/translator.js +11 -3
- package/esm/index.mjs +1 -0
- package/{lib/cjs/translator.js → esm/translator.mjs} +13 -10
- package/esm/types.mjs +1 -0
- package/esm.mjs +42 -0
- package/package.json +10 -11
- package/lib/index.js +0 -5
- package/lib/types.js +0 -2
- /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/LICENSE
CHANGED
|
@@ -19,13 +19,19 @@ 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
28
|
const sentence = localeSet?.sentences?.[key];
|
|
25
29
|
messageTmpl = sentence ?? key;
|
|
26
30
|
messageTmpl =
|
|
27
31
|
removeNoTranslateMark(input.toLowerCase()) === messageTmpl ? removeNoTranslateMark(input) : messageTmpl;
|
|
28
|
-
message = messageTmpl.replaceAll(
|
|
32
|
+
message = messageTmpl.replaceAll(
|
|
33
|
+
// eslint-disable-next-line regexp/strict
|
|
34
|
+
/{(\d+)(?::(c))?}/g, ($0, number, flag) => {
|
|
29
35
|
const num = Number.parseInt(number);
|
|
30
36
|
if (Number.isNaN(num)) {
|
|
31
37
|
return $0;
|
|
@@ -106,5 +112,7 @@ function toLocaleString(value, locale) {
|
|
|
106
112
|
return value.toString(10);
|
|
107
113
|
}
|
|
108
114
|
function removeNoTranslateMark(message) {
|
|
109
|
-
return message.replaceAll(
|
|
115
|
+
return message.replaceAll(
|
|
116
|
+
// eslint-disable-next-line regexp/strict
|
|
117
|
+
/(?<={\d+)\*(?=})/g, '');
|
|
110
118
|
}
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { translator } from './translator.mjs';
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.taggedTemplateTranslator = exports.translator = void 0;
|
|
4
1
|
const defaultListFormat = {
|
|
5
2
|
quoteStart: '"',
|
|
6
3
|
quoteEnd: '"',
|
|
7
4
|
separator: ', ',
|
|
8
5
|
};
|
|
9
|
-
function translator(localeSet) {
|
|
6
|
+
export function translator(localeSet) {
|
|
10
7
|
return (messageTmpl, ...keywords) => {
|
|
11
8
|
let message = messageTmpl;
|
|
12
9
|
if (typeof messageTmpl !== 'string') {
|
|
@@ -19,13 +16,19 @@ function translator(localeSet) {
|
|
|
19
16
|
if (keywords.length === 0) {
|
|
20
17
|
return translateKeyword(messageTmpl, '', localeSet);
|
|
21
18
|
}
|
|
22
|
-
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]));
|
|
23
24
|
const key = removeNoTranslateMark(messageTmpl).toLowerCase();
|
|
24
25
|
const sentence = localeSet?.sentences?.[key];
|
|
25
26
|
messageTmpl = sentence ?? key;
|
|
26
27
|
messageTmpl =
|
|
27
28
|
removeNoTranslateMark(input.toLowerCase()) === messageTmpl ? removeNoTranslateMark(input) : messageTmpl;
|
|
28
|
-
message = messageTmpl.replaceAll(
|
|
29
|
+
message = messageTmpl.replaceAll(
|
|
30
|
+
// eslint-disable-next-line regexp/strict
|
|
31
|
+
/{(\d+)(?::(c))?}/g, ($0, number, flag) => {
|
|
29
32
|
const num = Number.parseInt(number);
|
|
30
33
|
if (Number.isNaN(num)) {
|
|
31
34
|
return $0;
|
|
@@ -40,11 +43,10 @@ function translator(localeSet) {
|
|
|
40
43
|
return message;
|
|
41
44
|
};
|
|
42
45
|
}
|
|
43
|
-
exports.translator = translator;
|
|
44
46
|
/**
|
|
45
47
|
* @experimental
|
|
46
48
|
*/
|
|
47
|
-
function taggedTemplateTranslator(localeSet) {
|
|
49
|
+
export function taggedTemplateTranslator(localeSet) {
|
|
48
50
|
const t = translator(localeSet);
|
|
49
51
|
return (strings, ...keys) => {
|
|
50
52
|
let i = 0;
|
|
@@ -60,7 +62,6 @@ function taggedTemplateTranslator(localeSet) {
|
|
|
60
62
|
return t(template, ...keys);
|
|
61
63
|
};
|
|
62
64
|
}
|
|
63
|
-
exports.taggedTemplateTranslator = taggedTemplateTranslator;
|
|
64
65
|
function translateKeyword(keyword, flag, localeSet) {
|
|
65
66
|
// No translate
|
|
66
67
|
if (/^%[^%]+%$/.test(keyword)) {
|
|
@@ -106,5 +107,7 @@ function toLocaleString(value, locale) {
|
|
|
106
107
|
return value.toString(10);
|
|
107
108
|
}
|
|
108
109
|
function removeNoTranslateMark(message) {
|
|
109
|
-
return message.replaceAll(
|
|
110
|
+
return message.replaceAll(
|
|
111
|
+
// eslint-disable-next-line regexp/strict
|
|
112
|
+
/(?<={\d+)\*(?=})/g, '');
|
|
110
113
|
}
|
package/esm/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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/package.json
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/i18n",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.6",
|
|
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
|
-
"main": "./
|
|
10
|
-
"types": "./
|
|
9
|
+
"main": "./cjs/index.js",
|
|
10
|
+
"types": "./cjs/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"import": {
|
|
14
|
-
"default": "./
|
|
15
|
-
"types": "./
|
|
14
|
+
"default": "./esm/index.mjs",
|
|
15
|
+
"types": "./esm/index.d.ts"
|
|
16
16
|
},
|
|
17
|
-
"require":
|
|
18
|
-
"default": "./lib/cjs/index.js",
|
|
19
|
-
"types": "./lib/cjs/index.d.ts"
|
|
20
|
-
}
|
|
17
|
+
"require": "./cjs/index.js"
|
|
21
18
|
},
|
|
22
19
|
"./locales/en.json": {
|
|
23
20
|
"import": "./locales/en.json",
|
|
@@ -35,8 +32,10 @@
|
|
|
35
32
|
"entryPoint": "./src/index.ts"
|
|
36
33
|
},
|
|
37
34
|
"scripts": {
|
|
38
|
-
"build": "
|
|
35
|
+
"build": "yarn build:esm; yarn build:cjs; node ./esm.mjs",
|
|
36
|
+
"build:esm": "tsc",
|
|
37
|
+
"build:cjs": "tsc --module commonjs --outDir cjs",
|
|
39
38
|
"clean": "tsc --build --clean"
|
|
40
39
|
},
|
|
41
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "06e1242d274c72cf08a10a572b06ac35d1b924a4"
|
|
42
41
|
}
|
package/lib/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translator = void 0;
|
|
4
|
-
var translator_js_1 = require("./translator.js");
|
|
5
|
-
Object.defineProperty(exports, "translator", { enumerable: true, get: function () { return translator_js_1.translator; } });
|
package/lib/types.js
DELETED
|
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
|