Assignments
Details
We now have nls support for package.json and common-js. To test do the following:
Package.json for Extensions
- create a package.nls.json file as a sibling to your package.json file
- in
package.json, replace strings that should be localized with a key surrounded by %%. For example
"commands": [
{
"command": "typescript.reloadProjects",
"title": "%typescript.reloadProjects.title%",
"category": "TypeScript"
}
],
- In the package.nls.json add a key value pair that maps the key to a human readable value for our default language (which is English).
{
"typescript.reloadProjects.title": "Reload Project",
}
Ensure that when you start the extension the correct string is presented in the user interface. Also ensure that pseudo translation works. To do so start vscode with --locale=pseudo. The strings from the package.nls.json should be enclosed in [] and vowels should be doubled.
CommonJS Extensions
Install vscode-nls as a dependency of your extension. In the extension main add the following code:
import * as nls from 'vscode-nls';
let localize = nls.config({ locale: 'pseudo' })();
And in the activate function add
console.log(localize('key', 'Extension activated'));
This should show the following in the console:
[Plugin Host] [Exteensiioon aactiivaateed]
In other files in the extension you don't need to configure the nls module again. You can simple do:
import * as nls from 'vscode-nls';
let localize = nls.loadMessageBundle();
If you want to leave the code in since you tested it with your extension code then simply remove the locale property and initialize as follows:
import * as nls from 'vscode-nls';
let localize = nls.config()();
Assignments
Details
We now have nls support for package.json and common-js. To test do the following:
Package.json for Extensions
package.json, replace strings that should be localized with a key surrounded by %%. For example{ "typescript.reloadProjects.title": "Reload Project", }Ensure that when you start the extension the correct string is presented in the user interface. Also ensure that pseudo translation works. To do so start vscode with --locale=pseudo. The strings from the package.nls.json should be enclosed in [] and vowels should be doubled.
CommonJS Extensions
Install
vscode-nlsas a dependency of your extension. In the extension main add the following code:And in the activate function add
This should show the following in the console:
In other files in the extension you don't need to configure the nls module again. You can simple do:
If you want to leave the code in since you tested it with your extension code then simply remove the locale property and initialize as follows: