Skip to content

Commit

Permalink
Use IExtHostInitDataService to get the language (#161625)
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerLeonhardt committed Sep 23, 2022
1 parent 223e24c commit 41bdf03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/vs/base/common/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';

const LANGUAGE_DEFAULT = 'en';
export const LANGUAGE_DEFAULT = 'en';

let _isWindows = false;
let _isMacintosh = false;
Expand Down
14 changes: 10 additions & 4 deletions src/vs/workbench/api/common/extHostLocalizationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,38 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Language } from 'vs/base/common/platform';
import { LANGUAGE_DEFAULT } from 'vs/base/common/platform';
import { format } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { ExtHostLocalizationShape, IStringDetails, MainContext, MainThreadLocalizationShape } from 'vs/workbench/api/common/extHost.protocol';
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';

export class ExtHostLocalizationService implements ExtHostLocalizationShape {
readonly _serviceBrand: undefined;

private readonly _proxy: MainThreadLocalizationShape;
private readonly currentLanguage: string;
private readonly isDefaultLanguage: boolean;

private readonly bundleCache: Map<string, { contents: { [key: string]: string }; uri: URI }> = new Map();

constructor(
@IExtHostInitDataService initData: IExtHostInitDataService,
@IExtHostRpcService rpc: IExtHostRpcService,
@ILogService private readonly logService: ILogService
) {
this._proxy = rpc.getProxy(MainContext.MainThreadLocalization);
this.currentLanguage = initData.environment.appLanguage;
this.isDefaultLanguage = this.currentLanguage === LANGUAGE_DEFAULT;
}

getMessage(extensionId: string, details: IStringDetails): string {
const { message, args, comment } = details;
if (Language.isDefault()) {
if (this.isDefaultLanguage) {
return format(message, args);
}

Expand All @@ -52,7 +58,7 @@ export class ExtHostLocalizationService implements ExtHostLocalizationShape {
}

async initializeLocalizedMessages(extension: IExtensionDescription): Promise<void> {
if (Language.isDefault()
if (this.isDefaultLanguage
// TODO: support builtin extensions
|| !extension.l10n
) {
Expand All @@ -69,7 +75,7 @@ export class ExtHostLocalizationService implements ExtHostLocalizationShape {
this.logService.error(`No bundle location found for extension ${extension.identifier.value}`);
return;
}
const bundleUri = URI.joinPath(bundleLocation, `bundle.l10n.${Language.value()}.json`);
const bundleUri = URI.joinPath(bundleLocation, `bundle.l10n.${this.currentLanguage}.json`);

try {
const response = await this._proxy.$fetchBundleContents(bundleUri);
Expand Down

0 comments on commit 41bdf03

Please sign in to comment.