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

Default language with empty string is overwritten to current language when it should be used #971

Closed
JuleSch opened this issue Dec 13, 2018 · 0 comments

Comments

@JuleSch
Copy link
Contributor

JuleSch commented Dec 13, 2018

Current behavior

The string of my default language, is an empty string.
If I use a language that contains a missing translation, the default language is normally used.
But if the default language consists an empty string (in my case), it will be overwritten with the used language.

Expected behavior

The default language should not be overwritten.

How do you think that we should fix this?

In the file ngx-translate/core/src/lib/translate.service.ts there are three queries for existing default language.
Lines 170 and 460 contain
if (!this.defaultLang)
and in line 343
if (typeof res === "undefined" && this.defaultLang ...

These queries should be changed to:
if (this.defaultLang == null)
and to
if (typeof res === "undefined" && this.defaultLang != null...

Minimal reproduction of the problem with instructions

app.component.ts

constructor(private translate: TranslateService) {
translate.setDefaultLang("");
translate.use("");
translate.addLangs(['de', 'en']);
}

changeLang(lang){
this.translate.use(lang);
}

If the method changeLang() is called with the language 'de' and the translation key in 'de' does not exist, the system does not switch to the default language, but simply displays the key string.

Environment


ngx-translate version: 10.0.2
Angular version: 6.1.8


Browser:
- [x ] Chrome (desktop) version 62.0.3202.89
 
For Tooling issues:
- Node version: 10.7.0
- Platform:  ubuntu 16.04 LTS


JuleSch added a commit to JuleSch/core that referenced this issue Dec 13, 2018
An empty string is now also allowed as default language.
It checks if the default language is null. 
The check for 'undefined' is implied because of the use of == instead of ===.
@ocombe ocombe closed this as completed in 94bdc0d Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant