microsoft / vscode-nls Goto Github PK
View Code? Open in Web Editor NEWnpm module to support externalization and localization of VSCode extensions.
License: Other
npm module to support externalization and localization of VSCode extensions.
License: Other
I am calling
const localize = nls.config({ messageFormat: nls.MessageFormat.file })();
in my extension.ts
and then, in other files, I am calling
let localize = nls.loadMessageBundle();
....
const message: string = localize(
"logoutMessage.text",
"Successfully logged out from Machine Translation Service."
);
window.showInformationMessage(message);
However, when actually building my extension, I am getting "Failed to load message bundle. See console for details." I am unable to find any output in the console. What might cause this message?
I try to translate my extension.
Found this package, then follow the example
try and try again. but it didn't work.
Is there an easier way to define i18n?
Missing Document:
Q: What it gulp doing?
A: no answer
Q: When should I run gulp task? Is it automatic?
A: no answer
Q: What should I write in package.nls.json
A: no answer
Q: What's the relationship between package.nls.json
and i18n/{lang}/package.i18n.json
A: no answer
Q: Why localize
receive tow argument (key: string, message: string, ...args: any[]): string;
?
...
Such as
// data.nls.json
{
"msg.hello": "Hello World"
}
Having keys
and messages
quickly gets messy when there are a lot of keys
I'm trying to use the library inside of a debug-adapter for Visual Studio, which doesn't set VSCODE_NLS_CONFIG.
From the experiments I've run it seems that localize the result of nls.loadMessageBundle(); is caching the locale when the function is called, and that if I change the locale with nls.config({ locale: 'de-DE' }) after a call to nls.loadMessageBundle() is made, the localize function is stuck on the initial locale, and not the one I configured with nls.config (A new call to nls.loadMessageBundle() returns localize with the new locale, but the already created localize functions all use the old locale).
Is there any way for me to make all the localize functions automatically change to the new locale when nls.config is called?
Today vscode-nls uses require to read JSON files, e.g. require(path.join(folder, 'nls.metadata.json'))
. Constructs like this prevent this module from being webpack-able and we should avoid them, e.g. by using readFile
and JSON.parse
For the details see: microsoft/vscode#86140
@Tyriar can you please check whether the directory the nls library wants to write that file exists ?
v5.1.0 had a regression when bundling using webpack:
WARNING in ./node_modules/vscode-nls/lib/browser/main.js 26:14-44
Module not found: Error: Can't resolve 'vscode-nls-web-data' in '/<project-path>/node_modules/vscode-nls/lib/browser'
regressed by #42
Please add some info to the README on the message bundle format and the naming conventions used for the message bundle files.
suggest to remove .travis.yml
in npm module
Case: Extension is providing a translation file (i.e. package.nls.ja.json
) but the values of the json
are empty strings.
Issue: Message shows the key, not the value.
Solution: Fallback to EN
translations instead of displaying the key.
@dbaeumer Are we interested in the proposed solution? Will you be accepting a PR for this?
Rename cache to cacheLanguageResolution. New default will be true
Rename load to loadMessageBundle()
I keep getting this error when I try to import the vscode-jsonlanguage service in my webpack for target web using a umd-compat-loader.
Error: Cannot find module 'fs'
at webpackMissingModule (main.js:8:1)
at Object.<anonymous> (main.js:8:1)
at ./node_modules/dependencyPackage/node_modules/vscode-json-languageservice/node_modules/vscode-nls/lib/main.js (main.js:499:1)
at __webpack_require__ (bootstrap:789:1)
at fn (bootstrap:100:1)
at ./node_modules/dependencyPackagenode_modules/vscode-json-languageservice/lib/esm/parser/jsonParser.js (jsonParser.js:1:1)
at __webpack_require__ (bootstrap:789:1)
at fn (bootstrap:100:1)
at ./node_modules/dependencyPackage/node_modules/vscode-json-languageservice/lib/esm/services/jsonCompletion.js (jsonCompletion.js:1:1)
at __webpack_require__ (bootstrap:789:1)
I understand that this error occurs because I'm trying to import this for target web. But I need to use it for my web application and I'm not able to get around this issue. Also, in my use case, I won't be using the filesystem at all for interacting with the data.
Is it possible to add support for web target builds? If not, please suggest a workaround that I can try.
I've already tried fs empty in webpack.config.js
node: {
fs: 'empty'
},
externals: {
"fs": "fs"
}
and also I've tried adding browsr.fs: false to my package.json file.
"browser": {
"fs": false
},
None of these workarounds solved the issue.
gulp transifex-push-test
<file original="out/src\errors"
When I pull from Transifex on a mac, I get files with backslashes in their names, because they are not interpreted as directory separators
For all the details see microsoft/vscode#4520
Currently vscode-nls library is provided for VSC extension localization. But according to current design 1> the localized strings for each languages under i18n are in separated files as a mirror of source code directory and file levels. 2> the English version string is passed to localize() function as second parameter. For microsoft/vscode#1, can you provide a way to make all the localized strings in a single file for better and clearer checking. For microsoft/vscode#2, with all the English version strings embedded in code, It would be hard to track all the Eng strings, how can I make it in a single file and reference from this file?
This is the official i18n method. The only material even remotely resembling documentation is a sample that won't even build.
I tried looking at the code. Considering that fundamentally all this does is dictionary base token replacement with the dictionary being selected by the locale, it is ridiculously convoluted and indirect. This probably makes it configurable and versatile, but that has absolutely no value if you don't tell people how to use the damn thing.
Write complete documentation. Now. Don't kid yourselves that it's open source and people should do it themselves. You have made your code far too indirect and complicated for that to happen.
From the readme.md
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()));
This is not documentation. It is the barest of sketches.
Inspection of the code reveals that an arbitrary number of parameters are accepted and from the above one can infer than these will be substituted in order for indexed tokens like {0}
similar to C# string.Format
. Can format specifiers be applied to control the rendering"? Will the rendering itself be localised for month and day names? Nobody knows because there's no documentation. I just noticed that this sample code explicitly specifies a locale. Super handy for testing. Pity nobody knows.
To what exactly does "keyOne" map? There's absolutely no indication.
Inspection of the code also reveals a conspicuous absence of comments. Even accepted PRs don't really say what they are. And things aren't what they seem. Depending on what happens earlier with the config method, localize might totally ignore the key field. It's so bad it makes me want to go add comments to my own code even though it hasn't been presented to millions as the endorsed solution.
Don't be lazy and give a quick sketch of the most common case. Explain ALL of the parameters, ALL the consequences of config choices and ALL the magic strings. If that seems like too much work then maybe your library should be simpler. Have a look at #18. The combination of complexity and dismal documentation is such a barrier to use that people found it less trouble to go write their own library.
If you have a clone of this repository locally, you'll need to run the following commands to catch-up with the rename
git branch -m master main
git fetch origin
git branch -u origin/main main
The error in C:\Program Files\Microsoft VS Code\resources\app\extensions\git\node_modules\vscode-nls\lib\main.js
Context:
file = "c:\Program Files\Microsoft VS Code\resources\app\extensions\git\out\main"
locale = "en"
candidate = ".nls.en.json"
_isPseude = false
The error has been threw by
if (fs.existsSync(file + candidate)) {
because there are no file main.nls.en.json
in c:\Program Files\Microsoft VS Code\resources\app\extensions\git\out\
Seems this is linked with comment from [vscode/src/main.js] in getNLSConfiguration()
(https://github.com/Microsoft/vscode/blob/962cd502224f7750cbf16bc676367ebab6ab35bc/src/main.js)
// Check if we have an English locale. If so fall to default since that is our
// English translation (we don't ship *.nls.en.json files)
From @joaomoreno on February 24, 2016 10:44
Testing #3156
When using vscode-nls
, I have to call nls.config()
in one file and loadMessageBundle
in all the others. Couldn't we align this such that I don't need to track whether I have called nls.config()
in one of my files at all?
Eg: just calling nls.config()
in all files would fix it for me.
Copied from original issue: microsoft/vscode#3397
I've read this issue, but still can't manage to make i18n work (source code).
I'm making vsix file with gulp package
command, log is clear, also I can see localization files inside vsix file. Then I'm installing vsix bundle locally, but it doesn't change anything: localize
call returns second argument, instead of key's value, specified in json.
Any ideas what I am missing?
vscode-nls version 4.0.0.
Repro:
In a 3rd party extension:
nls.bundle.*.json
files in the out folderconst localize = nls.loadMessageBundle()
where nls comes from import * as nls from 'vscode-nls';
loadMessageBundle
calls loadNlsBundle()
which hits this code: ...
if (!result) {
// No language pack found, but core is running in language pack mode
// Don't try to use old in the box bundles since the might be stale
// Fall right back to the default bundle.
if (options.languagePackSupport) {
return loadDefaultNlsBundle(bundlePath);
}
Workaround
There is no way options.languagePackSupport
can be configured via nls.config()
.
The only ugly workaround is to change process.env.VSCODE_NLS_CONFIG
and set _languagePackSupport
to false before loading the vscode-nls
module.
Impact:
3rd party extensions cannot use nls bundles.
I keep seeing this warning when I run my Create-React-App application.
./node_modules/yaml-language-server/node_modules/vscode-json-languageservice/node_modules/vscode-nls/lib/browser/main.js
Module not found: Can't resolve 'vscode-nls-web-data' in '/<localPath>/node_modules/yaml-language-server/node_modules/vscode-json-languageservice/node_modules/vscode-nls/lib/browser'
When my application is running in the browser, I see this error logged in the browser console.
Loading vscode-nls-web-data failed. Are you running this outside of VS Code? If so, you may need to intercept the import call with your bundled NLS data.
It's not directly affecting my code but I would like to know how to fix this?
Currently, the only workaround that works for me is if I just ignore this module in webpack as follows.
const { IgnorePlugin } = require('webpack')
....
....
config.plugins.push(new IgnorePlugin({
resourceRegExp: /vscode-nls-web-data/,
}))
But, Ignoring modules should never be the solution.
I would like to understand why this compile time warning and the browser error occurs and what can we do to fix this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.