Skip to content

Commit

Permalink
wait for language packs to be deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Iannaccone committed Jul 29, 2022
1 parent f22be3c commit c7ed2a2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 29 deletions.
8 changes: 7 additions & 1 deletion arduino-ide-extension/src/node/arduino-ide-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import {
} from '../common/protocol/authentication-service';
import { ArduinoFirmwareUploaderImpl } from './arduino-firmware-uploader-impl';
import { PlotterBackendContribution } from './plotter/plotter-backend-contribution';
import { ArduinoLocalizationContribution } from './arduino-localization-contribution';
import { ArduinoLocalizationContribution } from './i18n/arduino-localization-contribution';
import { LocalizationContribution } from '@theia/core/lib/node/i18n/localization-contribution';
import { MonitorManagerProxyImpl } from './monitor-manager-proxy-impl';
import { MonitorManager, MonitorManagerName } from './monitor-manager';
Expand All @@ -102,6 +102,8 @@ import WebSocketProviderImpl from './web-socket/web-socket-provider-impl';
import { WebSocketProvider } from './web-socket/web-socket-provider';
import { ClangFormatter } from './clang-formatter';
import { FormatterPath } from '../common/protocol/formatter';
import { LocalizationBackendContribution } from './i18n/localization-backend-contribution';
import { LocalizationBackendContribution as TheiaLocalizationBackendContribution } from '@theia/core/lib/node/i18n/localization-backend-contribution';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(BackendApplication).toSelf().inSingletonScope();
Expand Down Expand Up @@ -395,4 +397,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(BackendApplicationContribution).toService(PlotterBackendContribution);
bind(ArduinoLocalizationContribution).toSelf().inSingletonScope();
bind(LocalizationContribution).toService(ArduinoLocalizationContribution);
bind(LocalizationBackendContribution).toSelf().inSingletonScope();
rebind(TheiaLocalizationBackendContribution).toService(
LocalizationBackendContribution
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,142 +11,142 @@ export class ArduinoLocalizationContribution
async registerLocalizations(registry: LocalizationRegistry): Promise<void> {
registry.registerLocalizationFromRequire(
'af',
require('../../build/i18n/af.json')
require('../../../build/i18n/af.json')
);

registry.registerLocalizationFromRequire(
'en',
require('../../build/i18n/en.json')
require('../../../build/i18n/en.json')
);

registry.registerLocalizationFromRequire(
'fr',
require('../../build/i18n/fr.json')
require('../../../build/i18n/fr.json')
);

registry.registerLocalizationFromRequire(
'ko',
require('../../build/i18n/ko.json')
require('../../../build/i18n/ko.json')
);

registry.registerLocalizationFromRequire(
'pt-br',
require('../../build/i18n/pt.json')
require('../../../build/i18n/pt.json')
);

registry.registerLocalizationFromRequire(
'uk_UA',
require('../../build/i18n/uk_UA.json')
require('../../../build/i18n/uk_UA.json')
);

registry.registerLocalizationFromRequire(
'ar',
require('../../build/i18n/ar.json')
require('../../../build/i18n/ar.json')
);

registry.registerLocalizationFromRequire(
'es',
require('../../build/i18n/es.json')
require('../../../build/i18n/es.json')
);

registry.registerLocalizationFromRequire(
'he',
require('../../build/i18n/he.json')
require('../../../build/i18n/he.json')
);

registry.registerLocalizationFromRequire(
'my_MM',
require('../../build/i18n/my_MM.json')
require('../../../build/i18n/my_MM.json')
);

registry.registerLocalizationFromRequire(
'ro',
require('../../build/i18n/ro.json')
require('../../../build/i18n/ro.json')
);

registry.registerLocalizationFromRequire(
'zh-cn',
require('../../build/i18n/zh.json')
require('../../../build/i18n/zh.json')
);

registry.registerLocalizationFromRequire(
'bg',
require('../../build/i18n/bg.json')
require('../../../build/i18n/bg.json')
);

registry.registerLocalizationFromRequire(
'eu',
require('../../build/i18n/eu.json')
require('../../../build/i18n/eu.json')
);

registry.registerLocalizationFromRequire(
'hu',
require('../../build/i18n/hu.json')
require('../../../build/i18n/hu.json')
);

registry.registerLocalizationFromRequire(
'ne',
require('../../build/i18n/ne.json')
require('../../../build/i18n/ne.json')
);

registry.registerLocalizationFromRequire(
'ru',
require('../../build/i18n/ru.json')
require('../../../build/i18n/ru.json')
);

registry.registerLocalizationFromRequire(
'zh_TW',
require('../../build/i18n/zh_TW.json')
require('../../../build/i18n/zh_TW.json')
);

registry.registerLocalizationFromRequire(
'de',
require('../../build/i18n/de.json')
require('../../../build/i18n/de.json')
);

registry.registerLocalizationFromRequire(
'fa',
require('../../build/i18n/fa.json')
require('../../../build/i18n/fa.json')
);

registry.registerLocalizationFromRequire(
'it',
require('../../build/i18n/it.json')
require('../../../build/i18n/it.json')
);

registry.registerLocalizationFromRequire(
'nl',
require('../../build/i18n/nl.json')
require('../../../build/i18n/nl.json')
);

registry.registerLocalizationFromRequire(
'sv_SE',
require('../../build/i18n/sv_SE.json')
require('../../../build/i18n/sv_SE.json')
);

registry.registerLocalizationFromRequire(
'el',
require('../../build/i18n/el.json')
require('../../../build/i18n/el.json')
);

registry.registerLocalizationFromRequire(
'fil',
require('../../build/i18n/fil.json')
require('../../../build/i18n/fil.json')
);

registry.registerLocalizationFromRequire(
'ja',
require('../../build/i18n/ja.json')
require('../../../build/i18n/ja.json')
);

registry.registerLocalizationFromRequire(
'pl',
require('../../build/i18n/pl.json')
require('../../../build/i18n/pl.json')
);

registry.registerLocalizationFromRequire(
'tr',
require('../../build/i18n/tr.json')
require('../../../build/i18n/tr.json')
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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();
await this.localizationRegistry.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));
});
}
}

0 comments on commit c7ed2a2

Please sign in to comment.