Hi, all.
I have installed language pack like Chinese (Simplified) Language Pack in Theia, all of the default content have been changed to Chinese, but how can custom extension do?
what parts of the documentation do not work for you? Do you mind sharing a bit more information your setup, so we can help you fix this?
Be aware that nls.localize alone does not automatically translate your content, you’ll have to add your translated text as a LocalizationContribution in the backend.
Yes, I added LocalizationContribution in the backend with translated json file. Full demo please check this repo. nls.localize in sample-menu-contribution.ts and LocalizationContribution in the backend.
I tried to debug, it appears that nls key not found in localization.translations, seems not merge custom extension LocalizationContribution
Thank you for sharing an example. So, there are two small issues which prevent this from working. You’re really close:
Your LocalizationContribution is not decorated as @injectable() (imported from @theia/core/shared/inversify)
The require paths are wrong, because your JS files end up in the lib folder, while your localization files are in your src folder. I would generally recommend to put the data folder on the same level as the lib and src folders.
The following will translate your sample menu correctly:
import { injectable } from '@theia/core/shared/inversify';
@injectable()
export class CustomLocalizationContribution implements LocalizationContribution {
async registerLocalizations(registry: LocalizationRegistry): Promise<void> {
console.error('registerLocalizations');
// Theia uses language codes, e.g. "de" for German
registry.registerLocalizationFromRequire('en', require('../../../src/backend/data/i18n/nls.en.json'));
registry.registerLocalizationFromRequire('zh-cn', require('../../../src/backend/data/i18n/nls.zh-cn.json'));
}
}