-
Notifications
You must be signed in to change notification settings - Fork 39.3k
Enable locale picker in web #150496
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
Merged
Merged
Enable locale picker in web #150496
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
40446b9
Enable locale picker in web
TylerLeonhardt f155b9d
fix the test by getting the locale from the loader config
TylerLeonhardt f16607c
Merge branch 'main' into tyler/enable-picker-for-web
TylerLeonhardt 32581bd
Merge branch 'main' into tyler/enable-picker-for-web
TylerLeonhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { ILanguagePackItem, LanguagePackBaseService } from 'vs/platform/languagePacks/common/languagePacks'; | ||
|
|
||
| export class WebLanguagePacksService extends LanguagePackBaseService { | ||
| // Web doesn't have a concept of language packs, so we just return an empty array | ||
| getInstalledLanguages(): Promise<ILanguagePackItem[]> { | ||
| return Promise.resolve([]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/vs/workbench/contrib/localization/browser/localization.contribution.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { registerAction2 } from 'vs/platform/actions/common/actions'; | ||
| import { ClearDisplayLanguageAction, ConfigureDisplayLanguageAction } from 'vs/workbench/contrib/localization/browser/localizationsActions'; | ||
|
|
||
| // Register action to configure locale and related settings | ||
| registerAction2(ConfigureDisplayLanguageAction); | ||
| registerAction2(ClearDisplayLanguageAction); |
26 changes: 26 additions & 0 deletions
26
src/vs/workbench/services/localization/browser/localeService.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { language } from 'vs/base/common/platform'; | ||
| import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; | ||
| import { ILocaleService } from 'vs/workbench/services/localization/common/locale'; | ||
|
|
||
| export class WebLocaleService implements ILocaleService { | ||
| declare readonly _serviceBrand: undefined; | ||
|
|
||
| async setLocale(locale: string | undefined): Promise<boolean> { | ||
| if (locale === language || (!locale && language === navigator.language)) { | ||
| return false; | ||
| } | ||
| if (locale) { | ||
| window.localStorage.setItem('vscode.nls.locale', locale); | ||
| } else { | ||
| window.localStorage.removeItem('vscode.nls.locale'); | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| registerSingleton(ILocaleService, WebLocaleService, true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexdima do you know if this is this the best way to get the locale out of the loader configuration?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could export proper API for it via
vs/nls. Today,vs/nlsexports a function calledlocalize, as well as other functions like.setPseudoTranslation,.create,.load. You could export via proper API fromvs/nlsthe current configured locale. You can then define typings for it atnls.d.ts. If you decide to do it, then please also add a mock implementation for it atnls.mock.ts.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooo this is a great idea!