Skip to content

Commit 657c1a3

Browse files
committed
feat: locale support zh-hans
1 parent aa7f5d3 commit 657c1a3

File tree

6 files changed

+10146
-17
lines changed

6 files changed

+10146
-17
lines changed

README-zh_CN.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
## 使用
1414

15-
### 简体中文
15+
### 简体中文(精简版)
1616

17-
默认的语言是简体中文,使用到的 `src/locale/dt-zh-hans.json` 是基于 [vscode-loc](https://github.com/microsoft/vscode-loc/blob/release/1.63.3/i18n/vscode-language-pack-zh-hans/translations/main.i18n.json) 精简的。
17+
使用到的 `src/locale/dt-zh-hans.json` 是基于 [vscode-loc/i18n/zh-hans](https://github.com/microsoft/vscode-loc/blob/release/1.63.3/i18n/vscode-language-pack-zh-hans/translations/main.i18n.json) 精简的。
1818

1919
- `ko.config.js` [ko - Project toolkit for React Applications](https://github.com/DTStack/ko)
2020

@@ -48,14 +48,31 @@ module.exports = {
4848
};
4949
```
5050

51+
52+
53+
```js
54+
new MonacoEditorI18nPlugin({
55+
locale: "dt-zh-hans",
56+
});
57+
```
58+
59+
### 简体中文
60+
61+
使用到的 `src/locale/zh-hans.json` 来源为 [vscode-loc/i18n/zh-hans](https://github.com/microsoft/vscode-loc/blob/release/1.63.3/i18n/vscode-language-pack-zh-hans/translations/main.i18n.json)
62+
63+
```js
64+
new MonacoEditorI18nPlugin({
65+
locale: "zh-hans",
66+
});
67+
```
68+
5169
### 自定义语言
5270

5371
如果你想使用其他语言或者精简后的 `src/locale/dt-zh-hans.json` 文件不能满足要求,你可以在 [vscode-loc/i18n](https://github.com/microsoft/vscode-loc/tree/release/1.63.3/i18n) 找到其他语言的 JSON 文件。
5472

5573
```js
5674
new MonacoEditorI18nPlugin({
57-
locale: "zh-hant", // 繁体中文
58-
customLocalePath: path.join(__dirname, "./zh-hant.json"),
75+
customLocalePath: path.join(__dirname, "./zh-hant.json"), // 繁体中文
5976
});
6077
```
6178

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ The purpose of this plugin is to set the language when using `monaco-editor`. Th
1212

1313
## Usage
1414

15-
### zh-hans
15+
### dt-zh-hans
1616

17-
The default language is Simplified Chinese. The used `src/locale/dt-zh-hans.json` is based on [vscode-loc](https://github.com/microsoft/vscode-loc/blob/release/1.63.3/i18n/vscode-language-pack-zh-hans/translations/main.i18n.json) lite.
17+
The used `src/locale/dt-zh-hans.json` is lite based on [vscode-loc/i18n/zh-hans](https://github.com/microsoft/vscode-loc/blob/release/1.63.3/i18n/vscode-language-pack-zh-hans/translations/main.i18n.json).
1818

1919
- `ko.config.js` [ko - Project toolkit for React Applications](https://github.com/DTStack/ko)
2020

@@ -48,14 +48,31 @@ module.exports = {
4848
};
4949
```
5050

51+
or
52+
53+
```js
54+
new MonacoEditorI18nPlugin({
55+
locale: "dt-zh-hans",
56+
});
57+
```
58+
59+
### Simplified Chinese
60+
61+
The used `src/locale/zh-hans.json` is from [vscode-loc/i18n/zh-hans](https://github.com/microsoft/vscode-loc/blob/release/1.63.3/i18n/vscode-language-pack-zh-hans/translations/main.i18n.json)
62+
63+
```js
64+
new MonacoEditorI18nPlugin({
65+
locale: "zh-hans",
66+
});
67+
```
68+
5169
### custom languages
5270

5371
If you want to use another language or if the `src/locale/dt-zh-hans.json` doesn't meet your requirements, you can get another's JSON file from [vscode-loc/i18n](https://github.com/microsoft/vscode-loc/tree/release/1.63.3/i18n).
5472

5573
```js
5674
new MonacoEditorI18nPlugin({
57-
locale: "zh-hant", // Traditional Chinese
58-
customLocalePath: path.join(__dirname, "./zh-hant.json"),
75+
customLocalePath: path.join(__dirname, "./zh-hant.json"), // Traditional Chinese
5976
});
6077
```
6178

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "monaco-editor-i18n-plugin",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "A i18n plugin for the Monaco editor",
55
"main": "out/index.js",
66
"typings": "./out/index.d.ts",

src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const replaceLocalizeLoader = require.resolve("./loaders/replaceLocalize");
1111
export declare namespace MonacoEditorI18nPlugin {
1212
interface IMonacoEditorI18nPluginOpts {
1313
/**
14-
* default is zh-cn
14+
* default is dt-zh-hans
1515
*/
16-
locale: "zh-cn";
16+
locale?: "dt-zh-hans" | "zh-hans";
1717

1818
/**
1919
* custom locale file path
@@ -56,8 +56,7 @@ function addCompilerRules(compiler: webpack.Compiler, rules: webpack.RuleSetRule
5656

5757
class MonacoEditorI18nPlugin {
5858
options: MonacoEditorI18nPlugin.IMonacoEditorI18nPluginOpts = {
59-
locale: "zh-cn",
60-
customLocalePath: "",
59+
locale: "dt-zh-hans",
6160
};
6261

6362
constructor(options: MonacoEditorI18nPlugin.IMonacoEditorI18nPluginOpts) {

src/loaders/replaceNls.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@ const replaceNls: PitchLoaderDefinitionFunction<MonacoEditorI18nPlugin.IMonacoEd
1212

1313
let _content = fs.readFileSync(nls, { encoding: "utf8" });
1414

15-
// use user custom locale file path
16-
const { customLocalePath } = this.getOptions() || {};
17-
if (customLocalePath && _content.includes("monaco-editor-i18n-plugin")) {
18-
_content = _content.replace(/require\("[^"]*"\);/g, `require("${customLocalePath}");`);
15+
if (_content.includes("monaco-editor-i18n-plugin")) {
16+
// use locale or customLocalePath
17+
const { locale, customLocalePath } = this.getOptions() || {};
18+
19+
let filePath = "monaco-editor-i18n-plugin/out/locale/dt-zh-hans.json";
20+
if (customLocalePath) {
21+
filePath = customLocalePath;
22+
} else if (locale === "zh-hans") {
23+
filePath = "monaco-editor-i18n-plugin/out/locale/zh-hans.json";
24+
} else {
25+
// locale default value is dt-zh-hans
26+
filePath = "monaco-editor-i18n-plugin/out/locale/dt-zh-hans.json";
27+
}
28+
_content = _content.replace(/require\("[^"]*"\);/g, `require("${filePath}");`);
1929
}
2030

2131
return _content;

0 commit comments

Comments
 (0)