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
Add a ment  | 

1 Answer 1

Reset to default 1

Probrably 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