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

Localization doesn't work #92

Closed
Brighttll opened this issue Sep 3, 2018 · 8 comments
Closed

Localization doesn't work #92

Brighttll opened this issue Sep 3, 2018 · 8 comments
Assignees

Comments

@Brighttll
Copy link

I tried to localize a message which should displays in ja(Japanese), but the message shows in en(English) after updating the locale as 'ja'. I noticed that localize('key', 'stringValue') are not transformed to localize(0, null) in extension.js after executing command gulp package. But the file extension.nls.ja.json would be generated correctly in the out folder.

I cannot figure out what's going on, did I missed anything?

I attached the source code, the reproduce steps are followings, you can refer the page [https://github.com/Brighttll/vscode-extension-samples/tree/master/i18n-sample] for details.

  1. Export the extension package and install it
  2. Update the locale as 'ja', restart vs code IDE.
  3. Run the command Tester: Create Application
    image
  4. Message box pop up, it's not in ja.
    image

Much appreciate if any one have a change to have a look at the issue.

Extension.zip

@Brighttll
Copy link
Author

I noticed that localize('key', 'stringValue') are transformed to localize(0, null) in extension.js if I debug start from "${workspaceRoot}/node_modules/gulp/bin/gulp.js".
When I execute command "gulp package", the localize('key', 'stringValue') are not transformed in extension.ts. I guess it is the root reason why localization does not work well.

extension.js generated by debug:
const message = localize(0, null);
vscode.window.showInformationMessage(message);
const message1 = localize(1, null);
vscode.window.showInformationMessage(message1);

extension.js generated by executing command "gulp package":
const message = localize('hello.text', 'Hello111');
vscode.window.showInformationMessage(message);
const message1 = localize('bye.text', 'Byebye');
vscode.window.showInformationMessage(message1);

@dbaeumer
Copy link
Member

dbaeumer commented Sep 5, 2018

@Brighttll yes, if the localize calls don't get replace localization doesn't work. But I don't know why this fails with the package task. It does work with the build task :-)

@dbaeumer
Copy link
Member

dbaeumer commented Sep 5, 2018

I know why: the gulp package task calls vsce package which calls npm run vscode:prepublish which calls npm run compile which does a normal compile again replace the *.js file generated by the nls compiler. Simply remove the vscode:prepublish script from the package.json and everything should work. However some observations:

For an extension you can simply do since version 3.x of the vscode-nls module:

import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();

which auto configures the NLS.

You can also checkout the lsp-sample we have here: https://github.com/Microsoft/vscode-extension-samples/tree/master/i18n-sample

@dbaeumer dbaeumer closed this as completed Sep 5, 2018
@Brighttll
Copy link
Author

@dbaeumer Thank you very much. Another question, the second argument of localize call must be a string literal, but I saved the text with default language(en) in a JSON file, is there any other way to load the default language text from JSON file to localize? Thanks again!

var commandText = require('../../i18n/en/out/extension.i18n.json');
localize('sayHello.text', commandText.sayHello.text.en);

@dbaeumer
Copy link
Member

dbaeumer commented Sep 7, 2018

Not sure I understand you. There is not need for you to load localization files by hand.

@Brighttll
Copy link
Author

The second argument of localize is the default local text, I have to pass a exact string value for it.
Do you mean it will load the default local text from JSON file? How to do it?

@Brighttll
Copy link
Author

If the second argument is different as the default local text in the localization file, it will display the second argument value, not the text defined in the localization file.

@Brighttll
Copy link
Author

@dbaeumer Never mind, I missed something. Thank you!

xsro added a commit to dosasm/masm-tasm that referenced this issue Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants