Support extension specific default language #238485
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Provide a mechanism for extension to specify it's own default language.
Allow extension owner to choose the language of untranslated string when using the builtin l10n API.
For motivation of this PR, please refer to #168127.
Proposed Solution
We check the default language specified by extension maintainer from
package.json
.And assume being
en
if not specified, for backward compatibility reason.Library Logic
When default-lang of extension match current VSCode language, we will not load any additional
string bundle. If default-lang is not matched, we will try loading
bundle.l10n.<locale>.json
bundle file for current VSCode language.
The rest logic remain untouched, e.g. how we bypass translation if there is no corresponding bundle.
Manifest Format in package.json
As proposed by TylerLeonhardt. In addition to original usage
Now we support the format like
as a way to specify default-lang for extensions by their maintainers.
How to Verify
Is's not so easy to verify the if logic is correct, since that all related logic are coupled with
a. vscode current language b. file system state of particular extension.
Prepare Extension
Write a extension that
vscode.l10n.t
to translate a string.en
bundle.l10n.en.json
Package the extension for following steps.
(I prepare a sample extension at https://github.com/wdhongtw/try-plugin, where the default-lang is
ja
Japanese.)Verify VSCode Logic
Now we need to launch a VSCode instance for three setup.
A. VSCode language match extension default-lang.
Try load the extension and verify the original string in
vscode.l10n.t
function call is used.B. VSCode language does not match extension default-lang and be in any language that the extension
do provide translated string bundle.
Try load the extension and verify the translated string in
bundle.l10n.<locale>.json
is used.C. VSCode language does not match extension default-lang and be in any language that extension
does not provide translated string bundle.
Try load the extension and verify the original string in
vscode.l10n.t
function call is used.(To change the language of VSCode quickly, we can patch
defaultNLSConfiguration
insrc\vs\base\node\nls.ts
)