Skip to content

TranslateParser API

The TranslateParser is responsible for formatting the translated messages and using parameters that are passed in.

Usually, you would not use the TranslateParser directly. It’s called in the background when a translation string is requested in your app.

It’s also most likely that you don’t have to create your own parser at all.

The default parser

interpolate

interpolate(expr: string | Function, params?: any): string

Interpolates a string to replace parameters or calls the interpolation function with the parameters.

Example:

parser.interpolate('This is a {{key}}!', {key: 'banana'})

Returns This is a banana!

Example:

parser.interpolate((params) => `This is a ${params.key}`, {key: 'banana'})

Returns This is a banana!

Custom parser

A TranslateParser implements this interface - you can create your own parser and plug in into the TranslateModule using the config.

export abstract class TranslateParser
{
abstract interpolate(expr: string | Function, params?: any): string | undefined;
}
Imprint Privacy