Message Format
Last updated
Was this helpful?
Last updated
Was this helpful?
The @jsverse/transloco-messageformat package integrates Transloco with @messageformat/core, enabling the compilation of translations using ICU syntax. This allows for advanced handling of pluralization and gender in your app's translations.
MessageFormat provides a robust mechanism for handling linguistic rules, making your app's translations more dynamic and user-friendly. For a detailed guide on its syntax, refer to .
The MessageFormatTranspiler
is fully compatible with Transloco's default transpiler, so you can safely switch without impacting your existing translations. With this plugin, you can use ICU syntax in your translation files:
To enable the plugin, include the following provider in your app providers:
By default, MessageFormat initializes all locales. You can customize this by specifying the locales you need:
MessageFormat provides additional options, such as:
customFormatters
: Add custom formatting functions.
biDiSupport
: Enable bidirectional support for right-to-left languages.
strictNumberSign
: Strictly interpret #
in plural rules.
Example configuration with advanced options:
From version 3 onward, the compiled output of MessageFormat is cached by default to improve performance. If you wish to disable caching, you can set the enableCache
option to false
:
This integration empowers you to use ICU syntax for advanced pluralization, gender, and linguistic rules, making your translations more accurate and expressive.
locales
: Accepts a string or an array of strings. The first locale is used as the default by MessageFormat.
For more details, refer to .