Skip to content

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

@JuleSch

Description

@JuleSch

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


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions