Skip to content

nls support for package.json and common-js #3156

@dbaeumer

Description

@dbaeumer

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()();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions