Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for fallback language #393

Open
jstoup111 opened this issue Jan 14, 2017 · 9 comments
Open

Support for fallback language #393

jstoup111 opened this issue Jan 14, 2017 · 9 comments

Comments

@jstoup111
Copy link

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?

@SamFarrington
Copy link

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');
        }

@andys8
Copy link

andys8 commented Mar 16, 2018

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.

@ocombe ocombe changed the title Question Support for fallback language May 8, 2018
@malikhasan
Copy link

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

@deyankush
Copy link

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

@LendaVadym
Copy link

Any update on this?

@sebastientromp
Copy link

I don't know if you offer a way to vote for enhancements, but this would be my #1 request as well :)

@NuxXDev
Copy link

NuxXDev commented Aug 18, 2022

@jstoup111 Did you ever find a solution for this? I am facing the same issue.

@jstoup111
Copy link
Author

@jstoup111 Did you ever find a solution for this? I am facing the same issue.

I did not and have been off the project that I needed this in for quite awhile now. It might be best to keep a reference to each language you support and then just split the string if it doesn't find it in the set.

const langs = new Set() //contains all your supported langs.

selectedLang = "en-US" // assume this isn't found

while(!langs.has(selectedLang)) {
  if(selectedLang.includes("-") {
    selectedLang = selectedLang.split("-")[0];
  else {
    selectedLang = defaultLang
  }
}

this.translate.use(selectedLang)

I haven't used this package in a long time so the code above likely needs some love, but the concept should work great.

@NuxXDev
Copy link

NuxXDev commented Aug 18, 2022

Thanks, that is almost exactly what I ended up doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants