Skip to content

Commit

Permalink
make i18n express endpoint await for the plugin loading process to end
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Iannaccone <[email protected]>
  • Loading branch information
Alberto Iannaccone committed Aug 1, 2022
1 parent f4327c2 commit dd1c8d8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/core/src/node/i18n/localization-backend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ export class LocalizationBackendContribution implements BackendApplicationContri
@inject(LocalizationProvider)
protected readonly localizationProvider: LocalizationProvider;

@inject(PluginDeployer)
protected readonly pluginDeployer: PluginDeployerImpl;

protected readonly initialized = new Deferred<void>();

async initialize(): Promise<void> {
this.pluginDeployer.onDidDeploy(() => {
this.initialized.resolve();
});
await this.localizationRegistry.initialize();
}

configure(app: express.Application): void {
app.get('/i18n/:locale', (req, res) => {
app.get('/i18n/:locale', async (req, res) => {
let locale = req.params.locale;
await this.initialized.promise;
locale = this.localizationProvider.getAvailableLanguages().some(e => e.languageId === locale) ? locale : 'en';
this.localizationProvider.setCurrentLanguage(locale);
res.send(this.localizationProvider.loadLocalization(locale));
Expand Down

0 comments on commit dd1c8d8

Please sign in to comment.