Skip to content

Commit 0c3f387

Browse files
committed
Improve parallelization of l10n loading
1 parent ca057fa commit 0c3f387

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

packages/plugin-ext/src/hosted/node/hosted-plugin-localization-service.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,29 @@ export class HostedPluginLocalizationService implements BackendApplicationContri
9797
const pluginId = plugin.metadata.model.id;
9898
const packageUri = new URI(plugin.metadata.model.packageUri);
9999
if (plugin.contributes?.localizations) {
100+
const l10nPromises: Promise<void>[] = [];
100101
for (const localization of plugin.contributes.localizations) {
101102
for (const translation of localization.translations) {
102-
const l10n = await getL10nTranslation(plugin.metadata.model.packageUri, translation);
103-
if (l10n) {
104-
const translatedPluginId = translation.id;
105-
const translationUri = packageUri.resolve(translation.path);
106-
const locale = localization.languageId;
107-
// We store a bundle for another extension in here
108-
// Hence we use `translatedPluginId` instead of `pluginId`
109-
this.languagePackService.storeBundle(translatedPluginId, locale, {
110-
contents: processL10nBundle(l10n),
111-
uri: translationUri.toString()
112-
});
113-
disposable.push(Disposable.create(() => {
114-
// Only dispose the deleted locale for the specific plugin
115-
this.languagePackService.deleteBundle(translatedPluginId, locale);
116-
}));
117-
}
103+
l10nPromises.push(getL10nTranslation(plugin.metadata.model.packageUri, translation).then(l10n => {
104+
if (l10n) {
105+
const translatedPluginId = translation.id;
106+
const translationUri = packageUri.resolve(translation.path);
107+
const locale = localization.languageId;
108+
// We store a bundle for another extension in here
109+
// Hence we use `translatedPluginId` instead of `pluginId`
110+
this.languagePackService.storeBundle(translatedPluginId, locale, {
111+
contents: processL10nBundle(l10n),
112+
uri: translationUri.toString()
113+
});
114+
disposable.push(Disposable.create(() => {
115+
// Only dispose the deleted locale for the specific plugin
116+
this.languagePackService.deleteBundle(translatedPluginId, locale);
117+
}));
118+
}
119+
}));
118120
}
119121
}
122+
await Promise.all(l10nPromises);
120123
}
121124
// The `l10n` field of the plugin model points to a relative directory path within the plugin
122125
// It is supposed to contain localization bundles that contain translations of the plugin strings into different languages
@@ -147,11 +150,13 @@ export class HostedPluginLocalizationService implements BackendApplicationContri
147150
*/
148151
async localizePlugin(plugin: DeployedPlugin): Promise<DeployedPlugin> {
149152
const currentLanguage = this.localizationProvider.getCurrentLanguage();
150-
const localization = await this.localizationProvider.loadLocalization(currentLanguage);
151153
const pluginPath = new URI(plugin.metadata.model.packageUri).path.fsPath();
152154
const pluginId = plugin.metadata.model.id;
153155
try {
154-
const translations = await loadPackageTranslations(pluginPath, currentLanguage);
156+
const [localization, translations] = await Promise.all([
157+
this.localizationProvider.loadLocalization(currentLanguage),
158+
loadPackageTranslations(pluginPath, currentLanguage),
159+
]);
155160
plugin = localizePackage(plugin, translations, (key, original) => {
156161
const fullKey = `${pluginId}/package/${key}`;
157162
return Localization.localize(localization, fullKey, original);

0 commit comments

Comments
 (0)