如何本地化VSCode扩展 [英] How to localise VSCode extension

查看:139
本文介绍了如何本地化VSCode扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个VS Code扩展来支持打印.由于最近所有问题都与涉及外国字符集的问题有关,因此我似乎应该支持英语以外的其他语言.

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.

但是我在VS Code API文档中找不到任何本地化内容.有一个关于语言的部分,但是关于计算机语言的解析和语法着色等.

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.

关于VS Code扩展的本地化是否有任何支持或至少有约定?

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

感谢Gama11为我提供了很多资源.

Thanks to Gama11 for pointing me at good resources.

官方示例非常基础.这使它们成为一个很好的起点,但是更完整的示例将有所帮助.如果我成功了,那么当我完成操作后,我将用一个指向我的项目的链接替换此段,该项目应演示三种语言(EN,FR,RU).

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).

推荐答案

是的,这是可能的,并且实际上有一个I18n示例扩展名:

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

最好阅读自述文件,但基本思想如下:

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

  • 使用 vscode-nls-dev NPM程序包
  • 使用NLS标识符(例如%extension.sayHello.title%" )作为命令标题的占位符,并在 package.json
  • 中使用
  • 类似地,在JS代码中,可以使用从 vscode-nls
  • 导入的 localize()方法来转换NLS标识符
  • 具有顶级 i8n 目录,其中包含< file-name> .i18n.json 文件
  • 中支持的语言的标识符的翻译.>
  • 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

或者,您也可以看看C ++扩展是如何做到的:

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

他们似乎采取了稍微不同的方法:没有 i8n 目录,而是直接将翻译直接放在文件( package.nls.it.json package.nls.zh-cn.json package.nls.json (默认为/英文).我不确定它是否会转换JS代码中 package.json /之外的任何内容.

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.

这篇关于如何本地化VSCode扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆