with Custom Translate Service

Demo

Demo Page / Demo Component

Installation

You can create your own Translate Service, for example using Fetch to load JSON files for translations.

Main.ts

Create a Custom Translate Service and make sure to implement all functions that the TranslaterService interface requires.

export class TranslateService implements TranslaterService {
  /** Method to return the current language used by the App */
  getCurrentLanguage(): string {}

  /** Method which receives a translation key and returns the translated value from that key */
  translate(translationKey: string, params?: any): string {}

  /** Method to set the language to use in the App and Translate Service */
  use(language: string): Promise<any> | any {}
}

for a full translater service implementation demo with Fetch, take a look at translate.service.ts.

Class sample

You need to add a translation key via the property headerKey to each column definition, for example: headerKey: 'TITLE'

Note

For the Select Filter, you will use labelKey instead of label. Anytime a translation key will come in play, we will add the word key to the end (hence headerKey, labelKey, more to come...)

Load App

Load the App (i.e.: main.ts) and instantiate the TranslateService

Use it

Custom Formatter (cell values)

You can define your own custom Formatter by providing the TranslateService Service into the Formatter and using the .translate(key) function to translate the cell value.

Using Formatters.Translate

Instead of defining a custom formatter over and over, you could also use the built-in Formatters.translate. However for the formatter to work, you need to provide the TranslateService instance, you can do so using the params properties which is made to pass any type of data.

Passing translater in the Grid Options for the Translate Service

Last updated