简体   繁体   English

如何本地化VSCode扩展

[英]How to localise VSCode extension

I wrote a VS Code extension to support printing. 我写了一个VS Code扩展来支持打印。 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. 但是我在VS Code API文档中找不到任何本地化内容。 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? 是否有关于VS Code扩展本地化的支持或至少有约定?


Thanks to Gama11 for pointing me at good resources. 感谢Gama11为我提供了很多资源。

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). 如果我成功了,那么当我完成后,我将用指向我的项目的链接替换此段,该项目应演示三种语言(EN,FR,RU)。

Yes, this is possible, and there is actually a I18n sample extension for this: 是的,这是可能的,为此实际上有一个I18n示例扩展名:

It's best if you read the readme, but the basic idea is the following: 最好阅读自述文件,但基本思想如下:

  • use the vscode-nls-dev NPM package 使用vscode-nls-dev NPM软件包
  • use NLS identifiers such as "%extension.sayHello.title%" as placeholders for command titles and such in package.json 使用NLS标识符(例如"%extension.sayHello.title%"作为命令标题的占位符,并在package.json
  • similarly, in JS code NLS identifiers can be translated with a localize() method imported from vscode-nls 同样,在JS代码中,可以使用从vscode-nls导入的localize()方法转换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 有一个顶层i8n目录,其中包含<file-name>.i18n.json文件中支持的语言的那些标识符的翻译

Alternatively, you could also take a look at how the C++ extension does it: 另外,您还可以看一下C ++扩展的工作方式:

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). 他们似乎采取了稍微不同的方法:没有i8n目录,而是直接在文件( package.nls.it.jsonpackage.nls.zh-cn.jsonpackage.nls.json与默认文件旁边) / 英语)。 I'm not sure if it translates anything outside of package.json / in JS code though. 我不确定它是否在JS代码中转换package.json /之外的任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM