robisim74 / angular-l10n

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

angular-l10n (formatLanguage): Invalid language thrown #325

Closed ihor-zinchenko closed 3 years ago

ihor-zinchenko commented 3 years ago

Hi! When i try to set confige like that

const l10nconfig = {
  ...
  schema: [
          { locale: { language: 'en', currency: 'USD', timeZone: 'America/Los_Angeles' }, dir: 'ltr', text: 'United States' },
          { locale: { language: 'fr-ca'}, dir: 'ltr', text: 'French (Canada)' },
  ]
}

i've got angular-l10n (formatLanguage): Invalid language thrown error but if i change language fr-ca to frc it works correctly but correct ISO code for French (Canada) is fr-ca. Also i have the same issue for the different language Please help me))

robisim74 commented 3 years ago

Hi @ihor-zinchenko,

the problem here is not fr-ca, the problem is that you have to setting formatoption to language-region, I guess.

Then if you want to use the language-region format, it would be better to use it for each locale.

ihor-zinchenko commented 3 years ago

There is my full config code:

export const l10nConfig: L10nConfig = {
    format: 'language-region',
    providers: [
        { name: 'app', asset: './assets/localizations/', options: { version: '11.0.0' } }
    ],
    fallback: false,
    cache: true,
    keySeparator: '.',
    defaultLocale: { language: 'en', currency: 'USD', timeZone: 'America/Los_Angeles' },
    schema: [
        { locale: { language: 'en', currency: 'USD', timeZone: 'America/Los_Angeles' }, dir: 'ltr', text: 'United States' },
        { locale: { language: 'da', currency: 'USD', timeZone: 'America/Los_Angeles' }, dir: 'ltr', text: 'Danish' },
        { locale: { language: 'fr', currency: 'USD', timeZone: 'America/Los_Angeles' }, dir: 'ltr', text: 'French' },
        { locale: { language: 'fr-ca'}, dir: 'ltr', text: 'French (Canada)' },
        { locale: { language: 'zh-sm', currency: 'USD', timeZone: 'America/Los_Angeles' }, dir: 'ltr', text: 'Chinese (simplified)' },
    ],
    defaultRouting: true
};

each line with language-EXAMPLE gives me error

So you mean if i set for example en-us for each line it will work?

robisim74 commented 3 years ago

If you use the language-region format would be appropriate to use it for all.

However perhaps the error here is that the correct form for the region is uppercase: fr-CA, zh-SM

ihor-zinchenko commented 3 years ago

@robisim74 yes, uppercase works correctly!) thanks!