mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Merge branch 'main' into notebookMultiMove
This commit is contained in:
@@ -8,6 +8,7 @@ import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/ext
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { ILanguagePackService } from 'vs/platform/languagePacks/common/languagePacks';
|
||||
|
||||
@extHostNamedCustomer(MainContext.MainThreadLocalization)
|
||||
export class MainThreadLocalization extends Disposable implements MainThreadLocalizationShape {
|
||||
@@ -15,10 +16,20 @@ export class MainThreadLocalization extends Disposable implements MainThreadLoca
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
@IFileService private readonly fileService: IFileService,
|
||||
@ILanguagePackService private readonly languagePackService: ILanguagePackService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async $fetchBuiltInBundleUri(id: string): Promise<URI | undefined> {
|
||||
try {
|
||||
const uri = await this.languagePackService.getTranslationsUri(id);
|
||||
return uri;
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async $fetchBundleContents(uriComponents: UriComponents): Promise<string> {
|
||||
const contents = await this.fileService.readFile(URI.revive(uriComponents));
|
||||
return contents.value.toString();
|
||||
|
||||
@@ -2144,6 +2144,7 @@ export interface MainThreadThemingShape extends IDisposable {
|
||||
}
|
||||
|
||||
export interface MainThreadLocalizationShape extends IDisposable {
|
||||
$fetchBuiltInBundleUri(id: string): Promise<UriComponents | undefined>;
|
||||
$fetchBundleContents(uriComponents: UriComponents): Promise<string>;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ export class ExtHostLocalizationService implements ExtHostLocalizationShape {
|
||||
async initializeLocalizedMessages(extension: IExtensionDescription): Promise<void> {
|
||||
if (this.isDefaultLanguage
|
||||
// TODO: support builtin extensions
|
||||
|| !extension.l10n
|
||||
|| (!extension.l10n && !extension.isBuiltin)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -70,16 +70,17 @@ export class ExtHostLocalizationService implements ExtHostLocalizationShape {
|
||||
}
|
||||
|
||||
let contents: { [key: string]: string } | undefined;
|
||||
const bundleLocation = this.getBundleLocation(extension);
|
||||
if (!bundleLocation) {
|
||||
const bundleUri = await this.getBundleLocation(extension);
|
||||
if (!bundleUri) {
|
||||
this.logService.error(`No bundle location found for extension ${extension.identifier.value}`);
|
||||
return;
|
||||
}
|
||||
const bundleUri = URI.joinPath(bundleLocation, `bundle.l10n.${this.currentLanguage}.json`);
|
||||
|
||||
try {
|
||||
const response = await this._proxy.$fetchBundleContents(bundleUri);
|
||||
contents = JSON.parse(response);
|
||||
const result = JSON.parse(response);
|
||||
// 'contents.bundle' is a well-known key in the language pack json file that contains the _code_ translations for the extension
|
||||
contents = extension.isBuiltin ? result.contents?.bundle : result;
|
||||
} catch (e) {
|
||||
this.logService.error(`Failed to load translations for ${extension.identifier.value} from ${bundleUri}: ${e.message}`);
|
||||
return;
|
||||
@@ -93,14 +94,14 @@ export class ExtHostLocalizationService implements ExtHostLocalizationShape {
|
||||
}
|
||||
}
|
||||
|
||||
private getBundleLocation(extension: IExtensionDescription): URI | undefined {
|
||||
// TODO: support builtin extensions using IExtHostInitDataService
|
||||
// if (extension.isBuiltin && this.initData.nlsBaseUrl) {
|
||||
// return URI.joinPath(this.initData.nlsBaseUrl, extension.identifier.value, 'main');
|
||||
// }
|
||||
private async getBundleLocation(extension: IExtensionDescription): Promise<URI | undefined> {
|
||||
if (extension.isBuiltin) {
|
||||
const uri = await this._proxy.$fetchBuiltInBundleUri(extension.identifier.value);
|
||||
return URI.revive(uri);
|
||||
}
|
||||
|
||||
return extension.l10n
|
||||
? URI.joinPath(extension.extensionLocation, extension.l10n)
|
||||
? URI.joinPath(extension.extensionLocation, extension.l10n, `bundle.l10n.${this.currentLanguage}.json`)
|
||||
: undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user