Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyi committed Oct 23, 2024
0 parents commit f60e45a
Show file tree
Hide file tree
Showing 13 changed files with 1,568 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Build
run: |
npm install
tsc -p tsconfig.json
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
out

.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) DTStack Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
66 changes: 66 additions & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# monaco-editor-i18n-plugin

<a href="https://www.npmjs.com/package/monaco-editor-i18n-plugin"><img alt="NPM Status" src="https://img.shields.io/npm/v/monaco-editor-i18n-plugin.svg?style=flat"></a>

[English](./README.md) | 简体中文

这个插件的作用是在使用 `monaco-editor` 时可以设置语言,主要实现思路是通过覆写 `monaco-editor/esm/vs/nls.js` 文件来实现语言切换的效果。

## 安装

`npm install monaco-editor-i18n-plugin -D`

## 使用

### 简体中文

默认的语言是简体中文,使用到的 `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) 精简的。

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

```js
const MonacoEditorI18nPlugin = require('monaco-editor-i18n-plugin');

const plugin = [
...,
{
key: 'WebpackPlugin',
action: 'add',
opts: {
name: 'MonacoEditorI18nPlugin',
fn: () => {
return new MonacoEditorI18nPlugin();
},
},
}
]
```

- `webpack.config.js`

```js
const MonacoEditorI18nPlugin = require('monaco-editor-i18n-plugin');

module.exports = {
...,
plugins: [new MonacoEditorI18nPlugin()],
...,
};
```

### 自定义语言

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

```js
new MonacoEditorI18nPlugin({
locale: "zh-hant", // 繁体中文
customLocalePath: path.join(__dirname, "./zh-hant.json"),
});
```

## 注意事项

- 目前验证的 `monaco-editor` 版本为 `0.30.1``0.31.1`
- `vscode-loc` 的版本为 `1.63.3`
- 如果自定义语言不生效,可能是上述两个包的版本没有对应,`vscode-loc` 后续版本的 JSON 文件结构是有变化的,请自行验证。
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# monaco-editor-i18n-plugin

<a href="https://www.npmjs.com/package/monaco-editor-i18n-plugin"><img alt="NPM Status" src="https://img.shields.io/npm/v/monaco-editor-i18n-plugin.svg?style=flat"></a>

English | [简体中文](./README-zh_CN.md)

这个插件的作用是在使用 `monaco-editor` 时可以设置语言,主要实现思路是通过覆写 `monaco-editor/esm/vs/nls.js` 文件来实现语言切换的效果。

## Install

`npm install monaco-editor-i18n-plugin -D`

## Usage

### zh-hans

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.

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

```js
const MonacoEditorI18nPlugin = require('monaco-editor-i18n-plugin');

const plugin = [
...,
{
key: 'WebpackPlugin',
action: 'add',
opts: {
name: 'MonacoEditorI18nPlugin',
fn: () => {
return new MonacoEditorI18nPlugin();
},
},
}
]
```

- `webpack.config.js`

```js
const MonacoEditorI18nPlugin = require('monaco-editor-i18n-plugin');

module.exports = {
...,
plugins: [new MonacoEditorI18nPlugin()],
...,
};
```

### custom languages

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 language's JSON file from [vscode-loc/i18n](https://github.com/microsoft/vscode-loc/tree/release/1.63.3/i18n).

```js
new MonacoEditorI18nPlugin({
locale: "zh-hant", // Traditional Chinese
customLocalePath: path.join(__dirname, "./zh-hant.json"),
});
```

## Notice

- The currently verified versions of `monaco-editor` are `0.30.1` and `0.31.1`.
- The version of `vscode-loc` is `1.63.3`.
- If custom language doesn't work, it may be due to a mismatch between the versions of the two packages. The JSON file structure in later versions of `vscode-loc` has changed, so please verify it by yourself.
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "monaco-editor-i18n-plugin",
"version": "0.0.0-beta.7",
"description": "A i18n plugin for the Monaco editor",
"main": "out/index.js",
"typings": "./out/index.d.ts",
"author": "DTStack",
"license": "MIT",
"scripts": {
"build": "rimraf out && tsc -p tsconfig.json && cp -r src/locale out/"
},
"bugs": {
"url": "https://github.com/DTStack/monaco-editor-i18n-plugin/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/DTStack/monaco-editor-i18n-plugin"
},
"homepage": "https://github.com/DTStack/monaco-editor-i18n-plugin#readme",
"devDependencies": {
"@types/node": "^22.7.9",
"rimraf": "^5.0.10",
"typescript": "^5.4.5",
"webpack": "^5.68.0"
},
"peerDependencies": {
"monaco-editor": "0.30.1 || 0.31.1",
"webpack": "^5"
},
"keywords": [
"monaco",
"monaco editor",
"vscode",
"nls",
"i18n",
"webpack"
]
}
Loading

0 comments on commit f60e45a

Please sign in to comment.