Skip to content

Commit

Permalink
Improve parallelization of l10n loading
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Sep 26, 2023
1 parent ca057fa commit 0c3f387
Showing 1 changed file with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,29 @@ export class HostedPluginLocalizationService implements BackendApplicationContri
const pluginId = plugin.metadata.model.id;
const packageUri = new URI(plugin.metadata.model.packageUri);
if (plugin.contributes?.localizations) {
const l10nPromises: Promise<void>[] = [];
for (const localization of plugin.contributes.localizations) {
for (const translation of localization.translations) {
const l10n = await getL10nTranslation(plugin.metadata.model.packageUri, translation);
if (l10n) {
const translatedPluginId = translation.id;
const translationUri = packageUri.resolve(translation.path);
const locale = localization.languageId;
// We store a bundle for another extension in here
// Hence we use `translatedPluginId` instead of `pluginId`
this.languagePackService.storeBundle(translatedPluginId, locale, {
contents: processL10nBundle(l10n),
uri: translationUri.toString()
});
disposable.push(Disposable.create(() => {
// Only dispose the deleted locale for the specific plugin
this.languagePackService.deleteBundle(translatedPluginId, locale);
}));
}
l10nPromises.push(getL10nTranslation(plugin.metadata.model.packageUri, translation).then(l10n => {
if (l10n) {
const translatedPluginId = translation.id;
const translationUri = packageUri.resolve(translation.path);
const locale = localization.languageId;
// We store a bundle for another extension in here
// Hence we use `translatedPluginId` instead of `pluginId`
this.languagePackService.storeBundle(translatedPluginId, locale, {
contents: processL10nBundle(l10n),
uri: translationUri.toString()
});
disposable.push(Disposable.create(() => {
// Only dispose the deleted locale for the specific plugin
this.languagePackService.deleteBundle(translatedPluginId, locale);
}));
}
}));
}
}
await Promise.all(l10nPromises);
}
// The `l10n` field of the plugin model points to a relative directory path within the plugin
// It is supposed to contain localization bundles that contain translations of the plugin strings into different languages
Expand Down Expand Up @@ -147,11 +150,13 @@ export class HostedPluginLocalizationService implements BackendApplicationContri
*/
async localizePlugin(plugin: DeployedPlugin): Promise<DeployedPlugin> {
const currentLanguage = this.localizationProvider.getCurrentLanguage();
const localization = await this.localizationProvider.loadLocalization(currentLanguage);
const pluginPath = new URI(plugin.metadata.model.packageUri).path.fsPath();
const pluginId = plugin.metadata.model.id;
try {
const translations = await loadPackageTranslations(pluginPath, currentLanguage);
const [localization, translations] = await Promise.all([
this.localizationProvider.loadLocalization(currentLanguage),
loadPackageTranslations(pluginPath, currentLanguage),
]);
plugin = localizePackage(plugin, translations, (key, original) => {
const fullKey = `${pluginId}/package/${key}`;
return Localization.localize(localization, fullKey, original);
Expand Down

0 comments on commit 0c3f387

Please sign in to comment.