Maps a value to a string that pluralizes the value according to locale rules.
Pipe usage
{{ value_expression | i18nPlural:pluralMap:locale }}API
class I18nPluralPipe implements PipeTransform {
constructor(_localization: NgLocalization): I18nPluralPipe;
transform(value: number | null | undefined, pluralMap: { [count: string]: string; }, locale?: string | undefined): string;
}
constructor
I18nPluralPipe
@returns
I18nPluralPipe
transform
string
@paramvalue
number | null | undefinedthe number to be formatted
@parampluralMap
{ [count: string]: string; }an object that mimics the ICU format, see https://unicode-org.github.io/icu/userguide/format_parse/messages/.
@paramlocale
string | undefineda string defining the locale to use (uses the current LOCALE_ID by default).
@returns
string
Description
Maps a value to a string that pluralizes the value according to locale rules.
Exported by
Usage Notes
Example
@Component({
selector: 'i18n-plural-pipe',
imports: [I18nPluralPipe],
template: `<div>{{ messages.length | i18nPlural: messageMapping }}</div>`,
})
export class I18nPluralPipeComponent {
messages: any[] = ['Message 1'];
messageMapping: {[k: string]: string} = {
'=0': 'No messages.',
'=1': 'One message.',
'other': '# messages.',
};
}