{"id":28560165,"url":"https://github.com/dtstack/monaco-editor-i18n-plugin","last_synced_at":"2025-06-10T09:07:44.324Z","repository":{"id":259407434,"uuid":"877136836","full_name":"DTStack/monaco-editor-i18n-plugin","owner":"DTStack","description":"A i18n plugin for the Monaco editor","archived":false,"fork":false,"pushed_at":"2025-03-12T07:04:32.000Z","size":222,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-13T18:50:12.710Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DTStack.png","metadata":{"files":{"readme":"README-zh_CN.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-23T06:38:42.000Z","updated_at":"2025-03-22T00:07:22.000Z","dependencies_parsed_at":"2024-10-27T09:15:22.042Z","dependency_job_id":null,"html_url":"https://github.com/DTStack/monaco-editor-i18n-plugin","commit_stats":null,"previous_names":["dtstack/monaco-editor-i18n-plugin"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DTStack%2Fmonaco-editor-i18n-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DTStack%2Fmonaco-editor-i18n-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DTStack%2Fmonaco-editor-i18n-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DTStack%2Fmonaco-editor-i18n-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DTStack","download_url":"https://codeload.github.com/DTStack/monaco-editor-i18n-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DTStack%2Fmonaco-editor-i18n-plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259043767,"owners_count":22797163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-10T09:07:41.949Z","updated_at":"2025-06-10T09:07:44.315Z","avatar_url":"https://github.com/DTStack.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# monaco-editor-i18n-plugin\n\n\u003ca href=\"https://www.npmjs.com/package/monaco-editor-i18n-plugin\"\u003e\u003cimg alt=\"NPM Status\" src=\"https://img.shields.io/npm/v/monaco-editor-i18n-plugin.svg?style=flat\"\u003e\u003c/a\u003e\n\n[English](./README.md) | 简体中文\n\n这个插件的作用是在使用 `monaco-editor` 时可以设置界面语言，主要实现思路是通过覆写 `monaco-editor/esm/vs/nls.js` 文件来实现界面语言切换的效果。\n\n\n## 版本差异\n\n- 0.x 版本：当你的产品只有一种界面语言时（不需要支持国际化，如仅支持中文），请使用 [0.x](https://github.com/DTStack/monaco-editor-i18n-plugin/tree/0.x-stable) 的版本。\n- 最新版本：当你的产品需要支持国际化时（产品页面支持切换界面语言），请使用最新版本。\n\n\n## 安装\n\n`npm install monaco-editor-i18n-plugin -D`\n\n\n## 语言\n\n### 简体中文（精简版）\n\n使用到的 `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) 精简的。\n\n### 简体中文（完整版）\n\n使用到的 `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)。\n\n### 自定义语言\n\n如果你想使用其他语言或者精简后的 `src/locale/dt-zh-hans.json` 文件不能满足要求，你可以在 [vscode-loc/i18n](https://github.com/microsoft/vscode-loc/tree/release/1.63.3/i18n) 找到其他语言的 JSON 文件，修改后放入你的工程文件夹下，以便使用自定义路径。\n\n\n## 使用示例\n\n### 配置项\n\n-   `ko.config.js` [ko - Project toolkit for React Applications](https://github.com/DTStack/ko)\n\n```js\nconst MonacoEditorI18nPlugin = require('monaco-editor-i18n-plugin');\n\nconst plugin = [\n    ...,\n    {\n        key: 'WebpackPlugin',\n        action: 'add',\n        opts: {\n            name: 'MonacoEditorI18nPlugin',\n            fn: () =\u003e {\n                return new MonacoEditorI18nPlugin({\n                    windowKey: '__DT_LOCALE__',\n                    localStorageKey: 'dt-locale',\n                });\n            },\n        },\n    }\n]\n```\n\n-   `webpack.config.js`\n\n```js\nconst MonacoEditorI18nPlugin = require('monaco-editor-i18n-plugin');\n\nmodule.exports = {\n    ...,\n    plugins: [\n        new MonacoEditorI18nPlugin({\n            windowKey: '__DT_LOCALE__',\n            localStorageKey: 'dt-locale',\n        })\n    ],\n    ...,\n};\n```\n\n### 使用说明\n\n需要在工程代码中将使用到的界面语言内容挂载到 `window` 对象上，key 默认值为 `__DT_LOCALE__`。`en-US` 为 `monaco-editor` 的默认语言，值为空对象即可。后续读取界面语言内容将从 `window` 对象中读取。挂载示例如下：\n\n```js\nimport dtZhHans from 'monaco-editor-i18n-plugin/out/locale/dt-zh-hans.json';\nimport zhHant from './zh-hant.json';\n\n// 将界面语言内容挂载到 window 对象上\nwindow.__DT_LOCALE__ = {\n    'zh-hant': zhHant?.contents || {},\n    'dt-zh-hans': dtZhHans?.contents || {},\n    'en-US': {},\n};\n```\n\n切换界面语言时需要同步将语言名称存到 localStorage 中。切换示例如下：\n\n```js\nfunction setLocale(value: string) {\n    window.localStorage.setItem('dt-locale', value);\n}\n\nsetLocale('dt-zh-hans');\n```\n\n\u003e **注意**\n\u003e\n\u003e - 如果 `monaco-editor` 的界面语言没有随产品页面变化，请注意 `window.__DT_LOCALE__` 的挂载时机应尽可能的早。\n\n\n## 注意事项\n\n- 目前验证的 `monaco-editor` 版本为 `0.30.1` 和 `0.31.1`。\n- 对应的 `vscode-loc` 版本为 `1.63.3`。\n- 如果自定义语言不生效，可能是上述两个包的版本没有对应，`vscode-loc` 后续版本的 JSON 文件结构是有变化的，请自行验证。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtstack%2Fmonaco-editor-i18n-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdtstack%2Fmonaco-editor-i18n-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtstack%2Fmonaco-editor-i18n-plugin/lists"}