Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks done
dbaeumer opened this issue Feb 19, 2016 · 5 comments
Closed
3 tasks done

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

dbaeumer opened this issue Feb 19, 2016 · 5 comments

Comments

@dbaeumer
Copy link
Member

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()();
@joaomoreno
Copy link
Member

More detailed testing steps would be appreciated. Also, I have no idea how to setup and test a Portuguese translation...

@weinand
Copy link
Contributor

weinand commented Feb 24, 2016

@joaomoreno we do not have any translations other than the pseudo translation. If we had, you could test Portuguese by launching code with "--locale=pt_PT" or "--locale=pt_BR".

@joaomoreno
Copy link
Member

Isn't each extension supposed to ship its own translations files? If so, how can I set up a Portuguese file?

@weinand
Copy link
Contributor

weinand commented Feb 24, 2016

@joaomoreno the process (i.e. tools) that produces these files is not yet ready (https://github.com/Microsoft/vscode-nls-dev). The default package.nls.json I've created manually. I assume that you can make a Portuguese clone of it but we would have to reverse engineer the name of that file from the source in vscode-nls-dev.
For the other nls files it is even more complex to manually doing it because the keys that you pass to localize() are converted into sequential numbers...

@joaomoreno
Copy link
Member

Got it

@Tyriar Tyriar added the verified Verification succeeded label Feb 24, 2016
@Tyriar Tyriar closed this as completed Feb 24, 2016
@Tyriar Tyriar removed the verified Verification succeeded label Feb 24, 2016
vazexqi pushed a commit to forcedotcom/salesforcedx-vscode that referenced this issue Jul 5, 2017
vazexqi pushed a commit to forcedotcom/salesforcedx-vscode that referenced this issue Jul 5, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants