GWT i18n,更改metaTag并重新加载应用程序 [英] GWT i18n, change metaTag and reload application
问题描述
阅读教程并查看一些示例。
有没有办法在不添加url的情况下更改语言标记locale = de
我的目标是在菜单登录屏幕上,用户选择语言,然后重新加载。
我设法通过将语言环境添加到网址来实现这一点[丑陋的方式给我]
我读到meta标签在Html文件中。
所以我试着把它放在html文件
中,它用这种语言加载,但我不能再改变语言。
只有使用meta标签才有可能使语言变得更大?
在代码中,我可以阅读和修改元标记值,但当我刷新我所做的更改丢失
NodeList< Element> tags = Document.get()。getElementsByTagName(meta); (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();
您可以使用cookie读取/
在您的.gwt.xml文件中
< set-configuration-property name =locale.cookie
value =GWT_LOCALE/>
在您的java代码中读取语言环境信息
final String cookieName = LocaleInfo.getLocaleCookieName();
字符串cookie = Cookies.getCookie(cookieName);
在您的java代码中编写语言环境信息
< pre $ 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();
}
}
另请参阅 p>
1) https:// developers.google.com/web-toolkit/doc/latest/DevGuideI18nLocale
<2> http://learninggwt.blogspot.in/2011/07/gwt-internationalization-and-cookies.html
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();
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
这篇关于GWT i18n,更改metaTag并重新加载应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!