root 3bf41bf355 update | hai 1 ano | |
---|---|---|
.. | ||
lib | hai 1 ano | |
License.txt | hai 1 ano | |
README.md | hai 1 ano | |
browser.d.ts | hai 1 ano | |
browser.js | hai 1 ano | |
node.d.ts | hai 1 ano | |
node.js | hai 1 ano | |
package.json | hai 1 ano |
CommonJS module to support externalization and localization. The module only depends on Node.js however its primary use case is for VSCode extensions.
import * as nls from 'vscode-nls';
let localize = nls.config({ locale: 'de-DE' })();
console.log(localize('keyOne', "Hello World"));
console.log(localize('keyTwo', "Current Date {0}", Date.now()));
The config
call configures the nls module and should only be called once in the applications entry point. You pass in the locale you want to use and whether the resolved locale should be cached for all further calls. The config call returns a function which is used to load a message bundle. During development time the argument should stay empty. There is another tool that helps extracting the message from your sources and it creates the message bundles autmatically for you. The tool is available here.
In secondary modules loaded from the 'main' module no configuration is necessary. However you still need to load the nls module and load the message bundle. This looks like this:
import * as nls from 'vscode-nls';
let localize = nls.loadMessageBundle();
console.log(localize('keyOne', "Hello World"));
During development time the strings in the code are presented to the user. If the locale is set to 'pseudo' the messages are modified in the following form:
vscode-nls\node
. To use the browser specific part import vscode-nls\browser
.The browser specific part currently does only support a default language inline in code. There is no support yet to load a different language bundle during runtime. However the split allows to web pack the vscode-nls
module.
VSCODE_NLS_CONFIG
setting.localize
function to string | number | boolean | null | undefined
nls.bundle(.${locale})?.json
file.