Skip to content
Leonty Chudinov edited this page Dec 13, 2018 · 4 revisions

i18n

i18n for strings in templates

Prerequisites

i18n steps

  • Add i18n attribute to every string in template that needs to be translated. Always add message id (e.g. @@introduction-header). Refer https://angular.io/guide/i18n for details (pluralization, ICU expressions, etc.)
<h1 i18n="site header|An introduction header for this sample@@introduction-header">Hello i18n!</h1>
  • Run npm run i18n command
  • Translate xlf files in src/assets/i18n folder

i18n for strings in TypeScript files

Prerequisites

 imports: [
 TranslationModule.forRoot({
      translation: {
        providers: [],
        composedLanguage: [ISOCode.Language, ISOCode.Country]
      }}
    ),
  ]
// ...
export class AppModule {
  constructor(
    private l10nLoader: L10nLoader,
    @Inject(Angular2InjectionTokens.L10N_CONFIG) private l10nConfig: Angular2L10nConfig,
    @Inject(LOCALE_CONFIG) private localeConfig: LocaleConfig,
    @Inject(TRANSLATION_CONFIG) private translationConfig: TranslationConfig,

  ) {
    this.localeConfig.defaultLocale = this.l10nConfig.defaultLocale;
    this.translationConfig.providers = this.l10nConfig.providers;
    this.l10nLoader.load();
  }
}

some.component.ts

constructor(private translation: TranslationService)
  • Use the service for translation, e.g.:
this.message = this.translation.translate('MyMessage');
  • Add message.LANG.json(or message.LANG-COUNTRY.json) files under src/assets/i18n. Note that message.en.json is used when a trasnlation files for a given language is not found. message.fr.json
{
  "MyMessage": "Salut"
}

i18n for plugin definitions

  • Put pluginDefinition.LANG.json(or pluginDefinition.LANG-COUNTRY.json) files under src/assets/i18n folder. Keys must be the same as in your pluginDefinition.json. Example: pluginDefinition.json
{
  "identifier": "org.zowe.zossystem.subsystems",
  "apiVersion": "1.0.0",
  "pluginVersion": "0.9.4",
  "pluginType": "application",
  "webContent": {
    "framework": "angular2",
    "launchDefinition": {
      "pluginShortNameKey": "ZOS Subsystems",
      "pluginShortNameDefault": "ZOS Subsystems",
      "imageSrc": "assets/subsystems.png"
    },
    "descriptionKey": "ZOSSubystemsDescription",
    "descriptionDefault": "ZOS Subsystems Plugin",
  }
}

pluginDefinition.fr.json

{
  "ZOS Subsystems": "Sous-systèmes de zOS",
  "ZOSSubystemsDescription": "Sous-systèmes de zOS"
}
  • Restart zlux-proxy-server