Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Privacy
    • Imprint
    • Contact
    • Login methods
  • Sign in
  • A arsnova-lite
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • ARSnova
  • arsnova-lite
  • Wiki
  • Translation

Last edited by Lukas Maximilian Kimpel Apr 05, 2018
Page history

Translation

WARNING: This site is still work in progress. For more information, see !106 (merged)

In HTML

In HTML, replace any text with handlebars with the translate pipe. You can use this syntax inside a tag and inside placeholders etc.

The selector for the string has to be unique. Please follow these rules for the selector: <component-name>.<string-name>. Selectors have to stand in single quotes '

<button>{{ 'header.english' | translate }}</button>
<input type="password" placeholder="{{ 'login.password' | translate }}" name="password"/>

In Typescript

In Typescript, you can reach for any text string via the TranslateService.

First, you have to add the TranslateService to the constructor of the component: constructor(private translationService: TranslateService) {}. After making the translationService available, you can access the strings via this.translationService.get('<identifier>'). Please note that the TranslateService uses a http loader. Therefore, fetching translations is asynchronous and needs to be subscribed. An example can be found underneath.

constructor (private notificationService: NotificationService,
  private translationService: TranslateService) {
}

...

// Shows a notification
this.translationService.get('login.login-successful').subscribe(message => {
  this.notificationService.show(message);
};

Generating translation files

To generate translation files, run npm run extract. The extraction tool scans all files for string requests and creates a map of all needed strings. These will be generated in a json file.

Per default, a language file for english (en) and german (de) will be created at ./src/assets/i18n/.

Existing translations remain untouched, so that translations will not be lost (so you do not have to worry about backups and/or merging translation files).

Also, the extraction tool tracks any unused translation identifier and cleans the translation file.

Adding languages

To add another language, two steps are required:

  1. Add the language to the extraction tool command: In the package.json file, there is an entry under "scripts" called "extract": "...". Find the place in the second string where the ouput files are referenced (after --output) and add an output path for your language ./src/assets/i18n/<language-code>.json.
  2. Add the language to the language select in the header component: Add a new element into the #langMenu like this <button mat-menu-item (click)="useLanguage('<language-code>')">{{ 'header.<language-name>' | translate }}</button>
Clone repository
  • Conventions
  • Daily Log
  • Friday, march 9th
  • Monday, march 12th
  • Project setup
  • Translation
  • Wednesday, march 7th
  • domain model
  • friday, march 16th
  • Home
  • monday, march 5th
  • thursday, march 15th
  • thursday, march 8th
  • tuesday, march 13th
  • tuesday, march 6th
View All Pages