File tree Expand file tree Collapse file tree 6 files changed +25
-25
lines changed
Expand file tree Collapse file tree 6 files changed +25
-25
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,9 @@ const plugin = [
2929 opts: {
3030 name: ' MonacoEditorI18nPlugin' ,
3131 fn : () => {
32- return new MonacoEditorI18nPlugin ();
32+ return new MonacoEditorI18nPlugin ({
33+ locale: " dt-zh-hans" ,
34+ });
3335 },
3436 },
3537 }
@@ -43,19 +45,15 @@ const MonacoEditorI18nPlugin = require('monaco-editor-i18n-plugin');
4345
4446module .exports = {
4547 ... ,
46- plugins: [new MonacoEditorI18nPlugin ()],
48+ plugins: [
49+ new MonacoEditorI18nPlugin ({
50+ locale: " dt-zh-hans" ,
51+ })
52+ ],
4753 ... ,
4854};
4955```
5056
51- 或
52-
53- ``` js
54- new MonacoEditorI18nPlugin ({
55- locale: " dt-zh-hans" ,
56- });
57- ```
58-
5957### 简体中文
6058
6159使用到的 ` 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 ) 。
Original file line number Diff line number Diff line change @@ -29,7 +29,9 @@ const plugin = [
2929 opts: {
3030 name: ' MonacoEditorI18nPlugin' ,
3131 fn : () => {
32- return new MonacoEditorI18nPlugin ();
32+ return new MonacoEditorI18nPlugin ({
33+ locale: " dt-zh-hans" ,
34+ });
3335 },
3436 },
3537 }
@@ -43,19 +45,15 @@ const MonacoEditorI18nPlugin = require('monaco-editor-i18n-plugin');
4345
4446module .exports = {
4547 ... ,
46- plugins: [new MonacoEditorI18nPlugin ()],
48+ plugins: [
49+ new MonacoEditorI18nPlugin ({
50+ locale: " dt-zh-hans" ,
51+ })
52+ ],
4753 ... ,
4854};
4955```
5056
51- or
52-
53- ``` js
54- new MonacoEditorI18nPlugin ({
55- locale: " dt-zh-hans" ,
56- });
57- ```
58-
5957### Simplified Chinese
6058
6159The 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 ) 。
Original file line number Diff line number Diff line change 11{
22 "name" : " monaco-editor-i18n-plugin" ,
3- "version" : " 0.0.2 " ,
3+ "version" : " 0.0.4 " ,
44 "description" : " A i18n plugin for the Monaco editor" ,
55 "main" : " out/index.js" ,
66 "typings" : " ./out/index.d.ts" ,
77 "author" : " DTStack" ,
88 "license" : " MIT" ,
99 "scripts" : {
10- "build" : " rimraf out && tsc -p tsconfig.json && cp -r src/locale out/"
10+ "build" : " rimraf out && tsc -p tsconfig.json && cp -r src/locale out/" ,
11+ "prepublishOnly" : " npm run build"
1112 },
1213 "bugs" : {
1314 "url" : " https://github.com/DTStack/monaco-editor-i18n-plugin/issues"
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ export declare namespace MonacoEditorI18nPlugin {
1313 /**
1414 * default is dt-zh-hans
1515 */
16- locale ? : "dt- zh-hans" | "zh-hans" ;
16+ locale : "en-US" | " zh-hans" | "dt- zh-hans" ;
1717
1818 /**
1919 * custom locale file path
Original file line number Diff line number Diff line change @@ -13,14 +13,17 @@ const replaceNls: PitchLoaderDefinitionFunction<MonacoEditorI18nPlugin.IMonacoEd
1313 let _content = fs . readFileSync ( nls , { encoding : "utf8" } ) ;
1414
1515 if ( _content . includes ( "monaco-editor-i18n-plugin" ) ) {
16- // use locale or customLocalePath
16+ // use options' locale/ customLocalePath
1717 const { locale, customLocalePath } = this . getOptions ( ) || { } ;
1818
1919 let filePath = "monaco-editor-i18n-plugin/out/locale/dt-zh-hans.json" ;
2020 if ( customLocalePath ) {
2121 filePath = customLocalePath ;
2222 } else if ( locale === "zh-hans" ) {
2323 filePath = "monaco-editor-i18n-plugin/out/locale/zh-hans.json" ;
24+ } else if ( locale === "en-US" ) {
25+ _content = _content . replace ( / r e q u i r e \( " [ ^ " ] * " \) ; / g, `{};` ) ;
26+ return _content ;
2427 } else {
2528 // locale default value is dt-zh-hans
2629 filePath = "monaco-editor-i18n-plugin/out/locale/dt-zh-hans.json" ;
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ function _format(message, args) {
2020// replace monaco-editor/esm/vs/nls.js localize
2121function localize ( path , data , defaultMessage ) {
2222 const key = typeof data === "object" ? data . key : data ;
23- const _data = localeData ? localeData . contents : { } ;
23+ const _data = localeData ? .contents || { } ;
2424 let message = ( _data [ path ] || { } ) [ key ] ;
2525 if ( ! message ) {
2626 message = defaultMessage ;
You can’t perform that action at this time.
0 commit comments