admin管理员组文章数量:1393641
When I try to pass language dynamically from select dropdown list, It shows following error:
Uncaught TypeError: Cannot read property 'properties' of undefined at changeLanguage
where changeLanguage
is my function as follows:
function changeLanguage(lang)
{
lang = lang || "en_EN"; // if no language is set, use the browser's default
jQuery.i18n.properties({
path : 'language',
mode : 'both', language: lang,
name: 'Messages',
callback: refresh_i18n });
}
The following are the pictures of it:
What is wrong with the code? Please do suggest! Thanks
UPDATE: FOR MORE EXPLANATION: This is my index file and initially I call it with onload it works fine.
<script>
function refresh_i18n() {
console.log('Some code...')
}
function changeLanguage(lang) {
lang = lang || "en_EN";
jQuery.i18n.properties({
path : 'js/libs/language',
mode : 'both',
language: lang,
callback: refresh_i18n
});
}
changeLanguage("en_US");
</script>
but when i call by changing dropdown like:
$('#selectLanguage').change(function(){
changeLanguage(this.value);
});
It gives above error
When I try to pass language dynamically from select dropdown list, It shows following error:
Uncaught TypeError: Cannot read property 'properties' of undefined at changeLanguage
where changeLanguage
is my function as follows:
function changeLanguage(lang)
{
lang = lang || "en_EN"; // if no language is set, use the browser's default
jQuery.i18n.properties({
path : 'language',
mode : 'both', language: lang,
name: 'Messages',
callback: refresh_i18n });
}
The following are the pictures of it:
What is wrong with the code? Please do suggest! Thanks
UPDATE: FOR MORE EXPLANATION: This is my index file and initially I call it with onload it works fine.
<script>
function refresh_i18n() {
console.log('Some code...')
}
function changeLanguage(lang) {
lang = lang || "en_EN";
jQuery.i18n.properties({
path : 'js/libs/language',
mode : 'both',
language: lang,
callback: refresh_i18n
});
}
changeLanguage("en_US");
</script>
but when i call by changing dropdown like:
$('#selectLanguage').change(function(){
changeLanguage(this.value);
});
It gives above error
Share Improve this question edited Jun 15, 2023 at 23:45 Michael M. 11.1k11 gold badges21 silver badges44 bronze badges asked Jul 12, 2017 at 10:51 BharatBharat 1392 gold badges4 silver badges17 bronze badges 3- 1 Have you added i18n reference and initialized it? – Ved Commented Jul 12, 2017 at 10:55
- 1 Did you properly include the library? github./wikimedia/jquery.i18n – Matus Commented Jul 12, 2017 at 10:56
- update your question. Do not add code in ments. – Ved Commented Jul 12, 2017 at 11:07
1 Answer
Reset to default 1Probrably the i18n library is loading before the jquery (problems haha).
So, put the jQuery loading in the head of the html and the plugin i18n (and others, if you are using) in the body (I suggest in the end of body) of the html.
That must solve the problem.
本文标签: javascriptCan not read property of undefined i18nStack Overflow
版权声明:本文标题:javascript - Can not read property of undefined i18n - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744761507a2623782.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论