This plugin provides localization(l10n) support for Transloco.
Localization refers to the adaptation of a product, application or document content to meet the language, cultural and other requirements of a specific target market (a locale).
TranslocoLocaleModule along with
Transform a date into the locale's date format.
The date expression could be: a Date object, a number (milliseconds since UTC epoch), or an ISO string.
Transform a given number into the locale's currency format.
The library comes out of the box with locale currency mapping, so once the locale is change the currency will automatically display the right currency.
The currency mapping could be customise if needed through the config, and could be provided by
Transform a given number into current locale's decimal number format.
Transform a given number into current locale's percent number format.
The library provides three different ways to set the locale.
Using locale format for the translation files will automatically declare the locale on
Users who don't have more than one locale per language
could provide a language to locale mapping object using the config's
The third option in manually setting the locale, this could be done by calling
setLocale method from
Let's go over each one of the
localeConfig?: Declare the default configuration of the locale's formatting. A general configuration could be set using the
globalproperty, for a configuration by locale use
defaultLocale?: The default locale formatted in BCP 47 (default value:
langToLocaleMapping?: A key value
objectthat maps Transloco language to it's Locale (default value:
localeToCurrencyMapping?: A key value
objectthat maps the Locale to it's currency (formatted in ISO 4217) (the library provide a default value with all of the existing mapping).
There are two types of formatting options, one for
date and one for
The formatted options could be declared in three levels
- In the module's configuration (as mentioned above):
- It could be set in the component's providers using
- We can pass it to each pipe in the HTML template:
Note the format option of the global, locale's format and the one's being passed in the template, will be merged. While the template is the stronger one and then the locale and the global.
useGrouping- Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. Possible values are true and false; the (default is true).
minimumIntegerDigits- The minimum number of integer digits to use. Possible values are from 1 to 21 (default is 1).
minimumFractionDigits- The minimum number of fraction digits to use. Possible values are from 0 to 20 (default is 0).
maximumFractionDigits- The maximum number of fraction digits to use. Possible values are from 0 to 20 (default is 3).
minimumSignificantDigits- The minimum number of significant digits to use. Possible values are from 1 to 21 (default is 1).
maximumSignificantDigits- The maximum number of significant digits to use. Possible values are from 1 to 21 (default is 21).
dateStyle- The date formatting style.
timeStyle- The time formatting style.
timeZone- The time zone to use. The only value implementations must recognize is "UTC"; the default is the runtime's default time zone. Implementations may also recognize the time zone names of the IANA time zone database, such as "Asia/Shanghai", "Asia/Kolkata", "America/New_York".
localeChanges$- Observable of the active locale.
localizeDate()- Transform a date into a locale's date format.
localizeNumber()- Transform a number into the locale's number format according to the number type.
getLocale- Gets the active locale.
setLocale- Sets the active locale.
getCurrencySymbol- Gets the currency symbol for a given locale. If no locale is specified the currently active one is used.
In some cases you might want to customize the localization transformation, to achieve that you could provide your own localization transformer class.
There are two types of transformers for date and number: