API

 

TranslationService

Provides methods to access the translations.

class TranslationService {
  constructor( http: HttpClient );
  readonly activeLanguage: string;
  readonly isDownloading: boolean;
  readonly languageChanged: EventEmitter< string >;
  readonly statusChange: EventEmitter< TranslationChange >;
  initializeApp( config: TranslationConfig ): Promise< boolean >;
  initializeSection( route: Route ): Promise< boolean >;
  changeLanguage( language: string ): Promise< any >;
  get( key: string, args?: any ): string;
  getGroup( key: string ): object;
  insert( key: string, text: string, args?: any ): string;
  // localization helper methods:
  number( value: number, options: string ): string;
  percent( value: number, options: string ): string;
  currency( value: CurrencyValue, options: string ): string;
  ccy( value: number, currencyCode: string, options: string ): string;
  datetime( value: Date | number | string, options: string ): string;
}

constructor()

Creates a new instance of the service.

http
The HttpClient service.

activeLanguage

Gets the code of the current language.

isDownloading

Indicates that the download of one or more translation files is in progress.

languageChanged

Having changed the active language emits the code of the current language.

statusChange

Indicates changes in the state of the translation service related to the downloads of the translation files.

initializeApp()

Initializes the service and loads the translations of eager loaded modules for the default and active languages.

config
The translation configuration.

Returns a promise indicating whether the language of the browser is supported.

initializeSection()

Loads the translations of a lazy loaded module for all languages already in use.

route
The route of a lazy loaded module.

Returns a promise indicating whether loading has succeeded.

changeLanguage()

Sets the new active language and loads the translations of the language for all loaded modules.

language
The code of the new active language.

Returns a promise.

get()

Gets the text identified by the key in the current language. If the text contains placeholders for values, then they are replaced with the values provided by the second argument.

key
The key of the text to return.
args
That optional argument provides the eventual values to interpolate.

Returns the translated text.

getGroup()

Gets the translation node identified by the key in the current language.

key
The key of the translation node to return.

Returns an object containing translated texts.

insert()

Replaces the placeholders in the translation text with the values provided by the second argument.

key
The key of the translation text.
text
The translation text.
args
That argument provides the eventual values to interpolate.

Returns the translated text.

number()
percent()
currency()
ccy()
datetime()

Localization helper methods. See LocalizeContext.