问题
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 inpackage.json
- similarly, in JS code NLS identifiers can be translated with a
localize()
method imported fromvscode-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