问题
I'm trying to internationalize my GWT application.
I read the tutorials and see some examples.
Is there a way to do the language change without adding the url the tag "?locale=de"
My objective is at the menu login screen, the user selects the languague, and then it reloads. I managed to do that with the adding of the locale to the url.[Ugly way to me]
I was reading that there is possible with meta tags in Html file. So i tryed to put that in the html file
It loads in that language, but i can't change no more the language.
Is possible to chage the language only using meta tags?
In code, i can read and chage the meta tag value but when i refresh the change i made is lost
NodeList<Element> tags = Document.get().getElementsByTagName("meta");
for (int i = 0; i < tags.getLength(); i++) {
MetaElement metaTag = ((MetaElement) tags.getItem(i));
System.out.println("metaTag.getName() = " + metaTag.getName());
System.out.println("metaTag.getContent = " + metaTag.getContent());
if (metaTag.getName().equals("gwt:property")) {
metaTag.setContent("locale=de");
}
}
Window.Location.reload();
回答1:
You can use cookies to read/write information about your locale instead of meta tag or url.
In your .gwt.xml file
<set-configuration-property name="locale.cookie"
value="GWT_LOCALE" />
In you java code to read locale info
final String cookieName = LocaleInfo.getLocaleCookieName();
String cookie = Cookies.getCookie( cookieName );
In you java code to write locale info
private void setLocaleCookie( String locale )
{
final String cookieName = LocaleInfo.getLocaleCookieName();
if ( cookieName != null )
{
Date expires = new Date();
expires.setYear( expires.getYear() + 1 );
Cookies.setCookie( cookieName, locale, expires );
}
if ( !control )
{
com.google.gwt.user.client.Window.Location.reload();
}
}
Also Reference
1) https://developers.google.com/web-toolkit/doc/latest/DevGuideI18nLocale
2) http://learninggwt.blogspot.in/2011/07/gwt-internationalization-and-cookies.html
来源:https://stackoverflow.com/questions/14363596/gwt-i18n-change-metatag-and-reload-application