robisim74 / angular-l10n

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

locale.language is empty, Error: angular-l10n (L10nDefaultTranslationLoader): Asset not found #336

Closed bhaynes777 closed 2 years ago

bhaynes777 commented 2 years ago

I am trying to get angular-l10n v.13.1.0 working in an Angular 13 project.

In my component, the injected L10nLocale has language set to an empty string. I added subscribe calls to an injected L10nTranslationService as suggested here: https://github.com/robisim74/angular-l10n/issues/321#issuecomment-758926804 and got this error: "Error: angular-l10n (L10nDefaultTranslationLoader): Asset not found"

My l10n-config looks like this:

import { L10nConfig } from "angular-l10n";

const i18nAsset = {
  'en-US': {
    "test": "Driver"
  },
};

export const l10nConfig: L10nConfig = {
  format: 'language-region',
  providers: [
      { name: 'app', asset: i18nAsset, options: { version: '13.0.0' } }
  ],
  fallback: true,
  cache: true,
  keySeparator: '.',
  defaultLocale: { language: 'en-US', currency: 'USD' },
  schema: [
      { locale: { language: 'en-US', currency: 'USD', units: { 'length': 'mile' } }, dir: 'ltr', text: 'United States' }
  ],
  defaultRouting: true
};
robisim74 commented 2 years ago

Hi @bhaynes777,

i think the problem here is fallback: true: are you handle it by also providing translations that are country independent?

When fallback is enabled, and you have as format language-region, it tries to get also languagedata, and not only language-region data.

See here: https://github.com/robisim74/angular-l10n#translation-fallback

In any case the library uses the default locale if a locale is not included in your schema, even without enabling fallback.

bhaynes777 commented 2 years ago

Thanks @robisim74 , setting fallback to false fixed the issue.