ngx-translate/core: instant method returns object instead from default lang
Language fallback not working for Spanish user when user, rather it is showing [object Object] as the translated value
Scenario:
en.json
"USER" : "User"
es.json
"USER" : {
"COMPANY" : "Miembro"
"VENDOR" : "Vendedor"
}
fr.json:
"USER" : {
"DEFAULT": "Consommateur"
"COMPANY" : "Membre"
"VENDOR" : "Vendeur"
}
Usage:
{{ 'USER' | envlabel }}
envlabel: A pipe which will translate by checking user type
Explanation:
- For en user: it should always show "User" as the translated label
- For es user: it should show "Miembro" if the user type is company or
"Vendedor" if user type is vendor or "User" for any other type - For fr user: it should show "Membre" if the user type is company or
"Vendeur" if user type is vendor or "Consommateur" for any other type
Implementation:
- We have logic for each steps to check with "USER.${TYPE}" type and if
not found we remove type and just translate with "USER". - Where for spanish user: "USER.COMPANY" and "USER.VENDOR" will work,
but "USER.DEFAULT" will not work. - So we do translate using "USER" which returns object from "es.json"
- This was returning "User" from "en.json" in "angular-translate"
rather than the object from "es.json"
Fix for now: To make it work, we change language by use(defaultLang) and get the translated string and again use(userLang) after that before returning the translated text.
angular angular7 ngx-translate
add a comment |
Language fallback not working for Spanish user when user, rather it is showing [object Object] as the translated value
Scenario:
en.json
"USER" : "User"
es.json
"USER" : {
"COMPANY" : "Miembro"
"VENDOR" : "Vendedor"
}
fr.json:
"USER" : {
"DEFAULT": "Consommateur"
"COMPANY" : "Membre"
"VENDOR" : "Vendeur"
}
Usage:
{{ 'USER' | envlabel }}
envlabel: A pipe which will translate by checking user type
Explanation:
- For en user: it should always show "User" as the translated label
- For es user: it should show "Miembro" if the user type is company or
"Vendedor" if user type is vendor or "User" for any other type - For fr user: it should show "Membre" if the user type is company or
"Vendeur" if user type is vendor or "Consommateur" for any other type
Implementation:
- We have logic for each steps to check with "USER.${TYPE}" type and if
not found we remove type and just translate with "USER". - Where for spanish user: "USER.COMPANY" and "USER.VENDOR" will work,
but "USER.DEFAULT" will not work. - So we do translate using "USER" which returns object from "es.json"
- This was returning "User" from "en.json" in "angular-translate"
rather than the object from "es.json"
Fix for now: To make it work, we change language by use(defaultLang) and get the translated string and again use(userLang) after that before returning the translated text.
angular angular7 ngx-translate
When the user changes the language, you need to callTranslateService.use(currentLang)
for ngx-translate to change the defaultLang. So you "fix for now" is the current implementation I guess.
– KiraAG
Dec 28 '18 at 11:25
Thats what TranslateService.setDefaultLang does. check this.
– KiraAG
Dec 28 '18 at 11:38
use() function set currentLang for fallback if the translation not found in the user language file. For default langulage we use setDefaultLang(). Where as fix for now we use to change the user language to 'en' so ngx-translate won't look for in "es" it will check only in en file
– Mahavir
Dec 28 '18 at 11:41
So when the user changes, how are you initimating the ngx-tranlate to use the selected lang?
– KiraAG
Dec 28 '18 at 11:43
After user login, i'm setting the current language with use() and setting default by setDefaultLang(). The above scenario is when we want translation with type of user, where we use different pipe called "envlabel" with TranslateService instant method.
– Mahavir
Dec 28 '18 at 11:49
add a comment |
Language fallback not working for Spanish user when user, rather it is showing [object Object] as the translated value
Scenario:
en.json
"USER" : "User"
es.json
"USER" : {
"COMPANY" : "Miembro"
"VENDOR" : "Vendedor"
}
fr.json:
"USER" : {
"DEFAULT": "Consommateur"
"COMPANY" : "Membre"
"VENDOR" : "Vendeur"
}
Usage:
{{ 'USER' | envlabel }}
envlabel: A pipe which will translate by checking user type
Explanation:
- For en user: it should always show "User" as the translated label
- For es user: it should show "Miembro" if the user type is company or
"Vendedor" if user type is vendor or "User" for any other type - For fr user: it should show "Membre" if the user type is company or
"Vendeur" if user type is vendor or "Consommateur" for any other type
Implementation:
- We have logic for each steps to check with "USER.${TYPE}" type and if
not found we remove type and just translate with "USER". - Where for spanish user: "USER.COMPANY" and "USER.VENDOR" will work,
but "USER.DEFAULT" will not work. - So we do translate using "USER" which returns object from "es.json"
- This was returning "User" from "en.json" in "angular-translate"
rather than the object from "es.json"
Fix for now: To make it work, we change language by use(defaultLang) and get the translated string and again use(userLang) after that before returning the translated text.
angular angular7 ngx-translate
Language fallback not working for Spanish user when user, rather it is showing [object Object] as the translated value
Scenario:
en.json
"USER" : "User"
es.json
"USER" : {
"COMPANY" : "Miembro"
"VENDOR" : "Vendedor"
}
fr.json:
"USER" : {
"DEFAULT": "Consommateur"
"COMPANY" : "Membre"
"VENDOR" : "Vendeur"
}
Usage:
{{ 'USER' | envlabel }}
envlabel: A pipe which will translate by checking user type
Explanation:
- For en user: it should always show "User" as the translated label
- For es user: it should show "Miembro" if the user type is company or
"Vendedor" if user type is vendor or "User" for any other type - For fr user: it should show "Membre" if the user type is company or
"Vendeur" if user type is vendor or "Consommateur" for any other type
Implementation:
- We have logic for each steps to check with "USER.${TYPE}" type and if
not found we remove type and just translate with "USER". - Where for spanish user: "USER.COMPANY" and "USER.VENDOR" will work,
but "USER.DEFAULT" will not work. - So we do translate using "USER" which returns object from "es.json"
- This was returning "User" from "en.json" in "angular-translate"
rather than the object from "es.json"
Fix for now: To make it work, we change language by use(defaultLang) and get the translated string and again use(userLang) after that before returning the translated text.
angular angular7 ngx-translate
angular angular7 ngx-translate
asked Dec 28 '18 at 11:05
MahavirMahavir
25236
25236
When the user changes the language, you need to callTranslateService.use(currentLang)
for ngx-translate to change the defaultLang. So you "fix for now" is the current implementation I guess.
– KiraAG
Dec 28 '18 at 11:25
Thats what TranslateService.setDefaultLang does. check this.
– KiraAG
Dec 28 '18 at 11:38
use() function set currentLang for fallback if the translation not found in the user language file. For default langulage we use setDefaultLang(). Where as fix for now we use to change the user language to 'en' so ngx-translate won't look for in "es" it will check only in en file
– Mahavir
Dec 28 '18 at 11:41
So when the user changes, how are you initimating the ngx-tranlate to use the selected lang?
– KiraAG
Dec 28 '18 at 11:43
After user login, i'm setting the current language with use() and setting default by setDefaultLang(). The above scenario is when we want translation with type of user, where we use different pipe called "envlabel" with TranslateService instant method.
– Mahavir
Dec 28 '18 at 11:49
add a comment |
When the user changes the language, you need to callTranslateService.use(currentLang)
for ngx-translate to change the defaultLang. So you "fix for now" is the current implementation I guess.
– KiraAG
Dec 28 '18 at 11:25
Thats what TranslateService.setDefaultLang does. check this.
– KiraAG
Dec 28 '18 at 11:38
use() function set currentLang for fallback if the translation not found in the user language file. For default langulage we use setDefaultLang(). Where as fix for now we use to change the user language to 'en' so ngx-translate won't look for in "es" it will check only in en file
– Mahavir
Dec 28 '18 at 11:41
So when the user changes, how are you initimating the ngx-tranlate to use the selected lang?
– KiraAG
Dec 28 '18 at 11:43
After user login, i'm setting the current language with use() and setting default by setDefaultLang(). The above scenario is when we want translation with type of user, where we use different pipe called "envlabel" with TranslateService instant method.
– Mahavir
Dec 28 '18 at 11:49
When the user changes the language, you need to call
TranslateService.use(currentLang)
for ngx-translate to change the defaultLang. So you "fix for now" is the current implementation I guess.– KiraAG
Dec 28 '18 at 11:25
When the user changes the language, you need to call
TranslateService.use(currentLang)
for ngx-translate to change the defaultLang. So you "fix for now" is the current implementation I guess.– KiraAG
Dec 28 '18 at 11:25
Thats what TranslateService.setDefaultLang does. check this.
– KiraAG
Dec 28 '18 at 11:38
Thats what TranslateService.setDefaultLang does. check this.
– KiraAG
Dec 28 '18 at 11:38
use() function set currentLang for fallback if the translation not found in the user language file. For default langulage we use setDefaultLang(). Where as fix for now we use to change the user language to 'en' so ngx-translate won't look for in "es" it will check only in en file
– Mahavir
Dec 28 '18 at 11:41
use() function set currentLang for fallback if the translation not found in the user language file. For default langulage we use setDefaultLang(). Where as fix for now we use to change the user language to 'en' so ngx-translate won't look for in "es" it will check only in en file
– Mahavir
Dec 28 '18 at 11:41
So when the user changes, how are you initimating the ngx-tranlate to use the selected lang?
– KiraAG
Dec 28 '18 at 11:43
So when the user changes, how are you initimating the ngx-tranlate to use the selected lang?
– KiraAG
Dec 28 '18 at 11:43
After user login, i'm setting the current language with use() and setting default by setDefaultLang(). The above scenario is when we want translation with type of user, where we use different pipe called "envlabel" with TranslateService instant method.
– Mahavir
Dec 28 '18 at 11:49
After user login, i'm setting the current language with use() and setting default by setDefaultLang(). The above scenario is when we want translation with type of user, where we use different pipe called "envlabel" with TranslateService instant method.
– Mahavir
Dec 28 '18 at 11:49
add a comment |
1 Answer
1
active
oldest
votes
setDefaulrLang() use only for all users in app in appComponent or if you get an user location from browser then u can change it. Best way in my opinion is to learn how .json files works all files shuld have same lines so there cannot be line in en.json like "user": "User"
and in es file user: {...}
becous first one is variable name: string data and second one is variable name + map data !!!
example how it schould be written:
en.json
"USER" : {
"user": "user"
}
es.json
"USER" : {
"user": "Alejandro"
"COMPANY" : "Miembro"
"VENDOR" : "Vendedor"
}
fr.json:
"USER" : {
"user": "Pedro"
"DEFAULT": "Consommateur"
"COMPANY" : "Membre"
"VENDOR" : "Vendeur"
}
{{ 'USER.user' | translate }}
To change lang wright on user browser function to call button event witch will use corect languege.
$('.dropdown-menu>li>button').on('click', function () {
switch (this.id) {
case "en":
Cookies.set('user_lang', 'en', { expires: 60 });
break;
case "no":
Cookies.set('user_lang', 'no', { expires: 60 });
break;
case "pl":
Cookies.set('user_lang', 'pl', { expires: 60 });
break;
default:
}
});
function langTriger(code) {
$(code).trigger('click'); // trigger button to call back-end event
};
function trigerUserLang() {
switch (Cookies.get('user_lang')) {
case "en":
langTriger('#en');
break;
case "no":
langTriger('#no');
break;
case "pl":
langTriger('#pl');
break;
default:
};
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957529%2fngx-translate-core-instant-method-returns-object-instead-from-default-lang%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
setDefaulrLang() use only for all users in app in appComponent or if you get an user location from browser then u can change it. Best way in my opinion is to learn how .json files works all files shuld have same lines so there cannot be line in en.json like "user": "User"
and in es file user: {...}
becous first one is variable name: string data and second one is variable name + map data !!!
example how it schould be written:
en.json
"USER" : {
"user": "user"
}
es.json
"USER" : {
"user": "Alejandro"
"COMPANY" : "Miembro"
"VENDOR" : "Vendedor"
}
fr.json:
"USER" : {
"user": "Pedro"
"DEFAULT": "Consommateur"
"COMPANY" : "Membre"
"VENDOR" : "Vendeur"
}
{{ 'USER.user' | translate }}
To change lang wright on user browser function to call button event witch will use corect languege.
$('.dropdown-menu>li>button').on('click', function () {
switch (this.id) {
case "en":
Cookies.set('user_lang', 'en', { expires: 60 });
break;
case "no":
Cookies.set('user_lang', 'no', { expires: 60 });
break;
case "pl":
Cookies.set('user_lang', 'pl', { expires: 60 });
break;
default:
}
});
function langTriger(code) {
$(code).trigger('click'); // trigger button to call back-end event
};
function trigerUserLang() {
switch (Cookies.get('user_lang')) {
case "en":
langTriger('#en');
break;
case "no":
langTriger('#no');
break;
case "pl":
langTriger('#pl');
break;
default:
};
}
add a comment |
setDefaulrLang() use only for all users in app in appComponent or if you get an user location from browser then u can change it. Best way in my opinion is to learn how .json files works all files shuld have same lines so there cannot be line in en.json like "user": "User"
and in es file user: {...}
becous first one is variable name: string data and second one is variable name + map data !!!
example how it schould be written:
en.json
"USER" : {
"user": "user"
}
es.json
"USER" : {
"user": "Alejandro"
"COMPANY" : "Miembro"
"VENDOR" : "Vendedor"
}
fr.json:
"USER" : {
"user": "Pedro"
"DEFAULT": "Consommateur"
"COMPANY" : "Membre"
"VENDOR" : "Vendeur"
}
{{ 'USER.user' | translate }}
To change lang wright on user browser function to call button event witch will use corect languege.
$('.dropdown-menu>li>button').on('click', function () {
switch (this.id) {
case "en":
Cookies.set('user_lang', 'en', { expires: 60 });
break;
case "no":
Cookies.set('user_lang', 'no', { expires: 60 });
break;
case "pl":
Cookies.set('user_lang', 'pl', { expires: 60 });
break;
default:
}
});
function langTriger(code) {
$(code).trigger('click'); // trigger button to call back-end event
};
function trigerUserLang() {
switch (Cookies.get('user_lang')) {
case "en":
langTriger('#en');
break;
case "no":
langTriger('#no');
break;
case "pl":
langTriger('#pl');
break;
default:
};
}
add a comment |
setDefaulrLang() use only for all users in app in appComponent or if you get an user location from browser then u can change it. Best way in my opinion is to learn how .json files works all files shuld have same lines so there cannot be line in en.json like "user": "User"
and in es file user: {...}
becous first one is variable name: string data and second one is variable name + map data !!!
example how it schould be written:
en.json
"USER" : {
"user": "user"
}
es.json
"USER" : {
"user": "Alejandro"
"COMPANY" : "Miembro"
"VENDOR" : "Vendedor"
}
fr.json:
"USER" : {
"user": "Pedro"
"DEFAULT": "Consommateur"
"COMPANY" : "Membre"
"VENDOR" : "Vendeur"
}
{{ 'USER.user' | translate }}
To change lang wright on user browser function to call button event witch will use corect languege.
$('.dropdown-menu>li>button').on('click', function () {
switch (this.id) {
case "en":
Cookies.set('user_lang', 'en', { expires: 60 });
break;
case "no":
Cookies.set('user_lang', 'no', { expires: 60 });
break;
case "pl":
Cookies.set('user_lang', 'pl', { expires: 60 });
break;
default:
}
});
function langTriger(code) {
$(code).trigger('click'); // trigger button to call back-end event
};
function trigerUserLang() {
switch (Cookies.get('user_lang')) {
case "en":
langTriger('#en');
break;
case "no":
langTriger('#no');
break;
case "pl":
langTriger('#pl');
break;
default:
};
}
setDefaulrLang() use only for all users in app in appComponent or if you get an user location from browser then u can change it. Best way in my opinion is to learn how .json files works all files shuld have same lines so there cannot be line in en.json like "user": "User"
and in es file user: {...}
becous first one is variable name: string data and second one is variable name + map data !!!
example how it schould be written:
en.json
"USER" : {
"user": "user"
}
es.json
"USER" : {
"user": "Alejandro"
"COMPANY" : "Miembro"
"VENDOR" : "Vendedor"
}
fr.json:
"USER" : {
"user": "Pedro"
"DEFAULT": "Consommateur"
"COMPANY" : "Membre"
"VENDOR" : "Vendeur"
}
{{ 'USER.user' | translate }}
To change lang wright on user browser function to call button event witch will use corect languege.
$('.dropdown-menu>li>button').on('click', function () {
switch (this.id) {
case "en":
Cookies.set('user_lang', 'en', { expires: 60 });
break;
case "no":
Cookies.set('user_lang', 'no', { expires: 60 });
break;
case "pl":
Cookies.set('user_lang', 'pl', { expires: 60 });
break;
default:
}
});
function langTriger(code) {
$(code).trigger('click'); // trigger button to call back-end event
};
function trigerUserLang() {
switch (Cookies.get('user_lang')) {
case "en":
langTriger('#en');
break;
case "no":
langTriger('#no');
break;
case "pl":
langTriger('#pl');
break;
default:
};
}
answered Jan 3 at 23:28
MisesMises
92
92
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957529%2fngx-translate-core-instant-method-returns-object-instead-from-default-lang%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
When the user changes the language, you need to call
TranslateService.use(currentLang)
for ngx-translate to change the defaultLang. So you "fix for now" is the current implementation I guess.– KiraAG
Dec 28 '18 at 11:25
Thats what TranslateService.setDefaultLang does. check this.
– KiraAG
Dec 28 '18 at 11:38
use() function set currentLang for fallback if the translation not found in the user language file. For default langulage we use setDefaultLang(). Where as fix for now we use to change the user language to 'en' so ngx-translate won't look for in "es" it will check only in en file
– Mahavir
Dec 28 '18 at 11:41
So when the user changes, how are you initimating the ngx-tranlate to use the selected lang?
– KiraAG
Dec 28 '18 at 11:43
After user login, i'm setting the current language with use() and setting default by setDefaultLang(). The above scenario is when we want translation with type of user, where we use different pipe called "envlabel" with TranslateService instant method.
– Mahavir
Dec 28 '18 at 11:49