getText
A method that’s used to localize a string.
getText(text: string): string
Summary
This method is called primarily by LazyString (the result of strf()), for each string that should be translated. The implementation of this method may use a lookup table to provide a translation for a particular language, or it may return the same string if translation isn’t necessary. Both the input and output strings may start with translation markers (up to the first space, i.e. ##MARKER_ID
) and descriptions (between :
characters, i.e. ##MARKER_ID:Some description:
). These markers and descriptions can be used by this method, and will be removed from the output string.
Note
The input string may include formatting and plural form placeholders; translated text should include the same placeholders.
Example
// Part of an I18nProvider implementation:
getText(text: string): string {
let marker = text.match(/^##([^: ]+)/)?.[1];
return this.translationTable[marker || text] || text;
}
Related
- interface I18nProviderAn interface that can be implemented to support a specific locale.