Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT dynamic internationalization

In my application(GWT(EXT_GWT) + Spring) I need to set user(after login) his native language, without get params. For example: user filling his login&pass at login form and then redirecting at ready-to-work form (this form must be with native user language. Locale I get from db). My language files written at .properties files and enumerated in module.gwt.xml config.

So question is - how I can set language? Maybe with session or post params? But I don't understand how GWT before loading page choose needed locale. Some methods to set locale at gwt before page loaded?

Thanks!

like image 686
0dd_b1t Avatar asked Jun 19 '26 11:06

0dd_b1t


1 Answers

I think, after receving user locale info from db you should redirect him to url such as (if he is from Russia):

http://www.example.org/myapp.html?locale=ru

For example, you can save boolen flag that app was localized in session and implement this steps:

  • get current locale LocaleInfo.getCurrentLocale().getLocaleName();
  • compare it with user's locale value
  • if it differs, get base url using GWT.getModuleBaseURL()
  • construct new url based on previous base url with ?locale=locale_value on end
  • make localize flag true and save it to session;
  • redirect to new url using Window.Location.replace(newUrl)

for example localizeApp method may look like this:

    void localizeApp(User user) {
      if (!localized) {
        String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
        if (!locale.equals(user.getLocale)) {
          String url = GWT.getModuleBaseURL();
          String newUrl = url + "?locale="+currentLocale;
          localized = true; //and save to session here
          Window.Location.replace(newUrl);
        }
      }     
    }

More info abou localization in GWT you can find here Internationalizing a GWT Application and here Internationalizing a GWT Application Think It will help you!

like image 62
BraginiNI Avatar answered Jun 24 '26 00:06

BraginiNI