4
I’m trying to use this jQuery plugin to internationalize my web app.
Specifically, I want to use the data API in the fields that should be translated but the alert
returns "one" and not "one" and spans continue with One and Two.
Page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery i18n Demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" ></script>
<script src="../src/jquery.i18n.js"></script>
<script src="../src/jquery.i18n.messagestore.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/bootstrap.min.js"></script>
<script>
$.i18n({
locale: 'en'
});
alert($.i18n("um"));
</script>
</head>
<body>
<span data-i18n="um">Um</span>.
<span data-i18n="dois">Dois</span>.
</body>
</html>
en json.
{
"um": "ONE",
"dois": "TWO"
}
Someone has used it and can help?
The same goes for using the properties in Java, you put
label.teste=Teste
and using the Spring you call the keylabel.teste
to appear the text, therefore, what is the advantage and disadvantage of using both? Can the two be used in the same application? It would be good practice?– Giancarlo Abel Giulian
@Giancarlogiulian virtually every MVC framework (Struts, JSF, Spring MVC) works with i18n. The main difference is that using i18n in this way, the back-end will send the HTML already with the result of internationalization. If the user wants to change the language, the framework will perform a new request to recover the HTML again. Using the jquery plugin, the responsibility for internationalization lies with the front-end layer. Changes may or may not carry out a new request, depending on the implementation. For the vast majority of cases, only one of the solutions will already suit well.
– Romulo
Thank you @Romulo, if you manage to list more advantages and disadvantages of using one or the other would appreciate again.
– Giancarlo Abel Giulian
As the language option is stored in the database and later in Session (after login), what do you think of me creating one . js for each language (en.js and pt.js) already with the initialization code (your changeLocale method) and add them to the page according to its Session?
– Onaiggac
@Onaiggac seems like a fully functional option
– Romulo