-
-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wait for language packs to be deployed
- Loading branch information
Alberto Iannaccone
committed
Jul 29, 2022
1 parent
f22be3c
commit 7ef1f02
Showing
3 changed files
with
74 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
arduino-ide-extension/src/node/i18n/localization-backend-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as express from 'express'; | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { LocalizationBackendContribution as TheiaLocalizationBackendContribution } from '@theia/core/lib/node/i18n/localization-backend-contribution'; | ||
import { PluginDeployer } from '@theia/plugin-ext/lib/common/plugin-protocol'; | ||
import { PluginDeployerImpl } from '@theia/plugin-ext/lib/main/node/plugin-deployer-impl'; | ||
import { Deferred } from '@theia/core/lib/common/promise-util'; | ||
|
||
@injectable() | ||
export class LocalizationBackendContribution extends TheiaLocalizationBackendContribution { | ||
@inject(PluginDeployer) | ||
private readonly pluginDeployer: PluginDeployerImpl; | ||
|
||
private readonly initialized = new Deferred<void>(); | ||
|
||
override async initialize(): Promise<void> { | ||
this.pluginDeployer.onDidDeploy(() => { | ||
this.initialized.resolve(); | ||
}); | ||
super.initialize(); | ||
} | ||
|
||
override configure(app: express.Application): void { | ||
app.get('/i18n/:locale', async (req, res) => { | ||
let locale = req.params.locale; | ||
/* | ||
Waiting for the deploy of the language plugins is neecessary to avoid checking the available | ||
languages before they're finished to be loaded: https://github.com/eclipse-theia/theia/issues/11471 | ||
*/ | ||
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)); | ||
}); | ||
} | ||
} |