How to localise VSCode extension
Asked Answered
A

2

11

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.

Aleece answered 3/6, 2019 at 2:0 Comment(3)
I believe this is not possibel. VScode itself also doesn't come localized.Apolitical
Of course VSCode is localized. code.visualstudio.com/docs/getstarted/localesLoach
I learned something new. Thanks for pointing me (us) in the right direction.Apolitical
L
11

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:

  • 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 i18n 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:

They seem to take a slightly different approach: no i18n 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.

Loach answered 3/6, 2019 at 9:17 Comment(4)
This is at least part of what I seek. I have two commands, and this will definitely help with those. I haven't had time for a thorough look, but perhaps you can say: will this also allow translations of setting names and descriptions?Aleece
I'm not sure about setting names, but I think setting descriptions should be possible.Loach
I've had another quick look and on the face of it both settings and descriptions can be localised, so I'm taking this as an answer.Aleece
The link of i18n-sample code has been modified to the following url github.com/microsoft/vscode-extension-samples/tree/main/…Desideratum
I
2

The official l10n (localization) sample extension should help a lot, as the old i18n (internationalization) sample has been deprecated.

Clone it here: https://github.com/microsoft/vscode-extension-samples/tree/main/l10n-sample

Inflammable answered 11/11, 2022 at 3:15 Comment(2)
It's not only the sample that's changed. The reason for the change is a new API supporting localisation of strings within the extension, which was promoted to a release version quite recently. The sample has been updated in support of this. A CLI toolchain is also being considered to support the ongoing process of string extraction, replacement with tokens and managing translation to multiple target languages, although this is not publicly available yet.Aleece
@PeterWone Thanks for the info! Where did you get the message and where to track more?Inflammable

© 2022 - 2024 — McMap. All rights reserved.