robisim74 / angular-l10n

Angular library to translate texts, dates and numbers
MIT License
380 stars 59 forks source link

Allow override currency options #309

Closed dvanschepdael closed 4 years ago

dvanschepdael commented 4 years ago

Problem

I need to display prices in different currencies but with the same locale. According to the context, the currency could be platform or user specific.

Question

I would like to know if it is possible to override the currency defined in L10nConfig with the currency defined in the l10nNumber options directive ?

export const l10nConfig: L10nConfig = {
    ...,
    schema: [
        { locale: { language: 'en', currency: 'USD', timeZone: 'America/Los_Angeles' }, dir: 'ltr', text: 'United States' },
        { locale: { language: 'fr', currency: 'EUR', timeZone: 'Europe/Paris' }, dir: 'ltr', text: 'France' }
    ]
}
<span [options]="{ digits: '1.2-2', style: 'currency', currency: 'USD' }" l10nNumber>{{price}}</span>

When I specify a currency in the L10nConfig, it ignores the currency in [options]. Ideally, I would like to keep the default behavior in L10nConfig and override it only at specific moment.

Ps: Thanks for this amazing framework !

dvanschepdael commented 4 years ago

After studying the formatNumber() method, I guess the best way to solve my problem is to specify the currency each times in [options] and don't use it in L10nConfig.

Sorry for inconvenience 😅