How to localise VSCode extension

谁说我不能喝 提交于 2021-01-01 03:44:18

问题


I wrote a VS Code extension to support printing. Since all the recent issues have been concerned with issues relating to foreign character sets, it seems like I should support languages other than English.

But I can't find anything in on localisation in the VS Code API documentation. There's a section on languages but that's about parsing and syntax colouring etc for computer languages.

Is there any support or at least convention regarding localisation of VS Code extensions?


Thanks to Gama11 for pointing me at good resources.

The official examples are very basic. This makes them a good place to start, but a more complete example would help. If I'm successful then when I'm done I'll replace this para with a link to my project, which should demonstrate three languages (EN, FR, RU).


回答1:


Yes, this is possible, and there is actually a I18n sample extension for this:

  • https://github.com/microsoft/vscode-extension-samples/tree/master/i18n-sample

It's best if you read the readme, but the basic idea is the following:

  • use the vscode-nls-dev NPM package
  • use NLS identifiers such as "%extension.sayHello.title%" as placeholders for command titles and such in package.json
  • similarly, in JS code NLS identifiers can be translated with a localize() method imported from vscode-nls
  • have a toplevel i8n directory that contains the translations for those identifiers for the languages that are supported in <file-name>.i18n.json files

Alternatively, you could also take a look at how the C++ extension does it:

  • https://github.com/microsoft/vscode-cpptools/tree/master/Extension

They seem to take a slightly different approach: no i8n directory, but instead have the translations directly next to the file (package.nls.it.json, package.nls.zh-cn.json and package.nls.json with the default / English). I'm not sure if it translates anything outside of package.json / in JS code though.



来源:https://stackoverflow.com/questions/56420338/how-to-localise-vscode-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!