Core: Support for fallback language

Created on 14 Jan 2017  路  4Comments  路  Source: ngx-translate/core

I wasn't able to find this is the docs or on the internet. Is there a way to have the translation fallback to the standard language if it can't find a dialect?

I.E

I have a en.json file. When I retrieve the locale, I'd like to set it and have it fall back to the language if it can't find the dialect.

en-US & en-GB & en-UK should fall back to en.json if the file doesn't exist.
fr-CA should fallback to fr.json and then whatever I specified as default if it doesn't find fr.json

Is this how the library works, and if not how can I get it to function this way?

feature request

Most helpful comment

I'd expect the same behavior to be provided. It seems it isn't available.

@SamFarrington This won't fall back to the specific language. Think about en-US and de-AT.

All 4 comments

Hey - here is how we do it:

In our root component's ngOnInit we have the following logic:

        const langs = [
            'en-GB',
            'de'
        ];

        let isSupported = langs.find(supportedLanguage => supportedLanguage === navigator.language);

        if (isSupported) {
            this.translate.use(navigator.language);
        }
        else {
            this.translate.use('en-GB');
        }

I'd expect the same behavior to be provided. It seems it isn't available.

@SamFarrington This won't fall back to the specific language. Think about en-US and de-AT.

The fallback language support was excellent in angular-translate. There should be a stack or chain of fallback languages
https://angular-translate.github.io/docs/#/guide/08_fallback-languages

Are there any plans to get this feature in near future?

Was this page helpful?
0 / 5 - 0 ratings