-
-
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 (#1261)
- Loading branch information
Alberto Iannaccone
authored
Jul 29, 2022
1 parent
19c0334
commit 124738d
Showing
3 changed files
with
80 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
45 changes: 45 additions & 0 deletions
45
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,45 @@ | ||
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(); | ||
}); | ||
return 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 | ||
*/ | ||
const start = performance.now(); | ||
await this.initialized.promise; | ||
console.info( | ||
'Waiting for the deploy of the language plugins took: ' + | ||
(performance.now() - start) + | ||
' ms.' | ||
); | ||
locale = this.localizationProvider | ||
.getAvailableLanguages() | ||
.some((e) => e.languageId === locale) | ||
? locale | ||
: 'en'; | ||
this.localizationProvider.setCurrentLanguage(locale); | ||
res.send(this.localizationProvider.loadLocalization(locale)); | ||
}); | ||
} | ||
} |