i18n support

Hi,

Does IT Mill Toolkit have i18n support? And if so, what does it have?

I’ve noticed that com.itmill.toolkit.Application has both a getLocale() method and a setLocale(Locale) method. What’s their purpose?

Thank you for your attention,

Johnny

Hi,

Application.setLocale() sets the default locale for the application, which can be used by components that are locale-dependent; DateField uses this to format date and time correctly.

IT Mill Toolkit does not have it’s own i18n framework, but supports ‘standard’ java i18n practices. It seems every team has their own needs and ideas on how to implement i18n in their app (using resource bundles, db, separate frameworks, etc), so we’ve decided to leave that particular decision to the developer. Having said that, it would probably be helpful to provide a default/recommended method and best practices.

Let us know if you have thoughts about what kind of i18n support you’d like to have (or if the current approach +more documentation on the subject seems sufficient).

Some links on the subject…
Basic java tutorial on the subject:
http://java.sun.com/docs/books/tutorial/i18n/intro/index.html
There is an “externalize strings” function in eclipse that might be handy:
http://www.eclipse.org/articles/Article-Internationalization/how2I18n.html

Best Regards,
Marc

I suppose Toolkit could offer some features that could make internationalization easier. Unlike desktop applications, web applications often need to change their language on the fly. It might be useful to have some built-in support for changing at least the caption labels, etc., according to the current application locale. Well, I’m not sure if it would help much, as you anyhow have to change the language of all visible data.

It would also be useful to set the locale from the browser “Accept-Language” information, I suppose that should be easy?

Hi!

Actually getting browser locale is possible already. The only non-easy part is to know that it is safe to cast getContext() to WebApplicationContext.


        WebApplicationContext context2 = (WebApplicationContext) getContext();

        Locale locale2 = context2.getBrowser().getLocale();

If I remember correctly you don’t need the web application context. The application locale is also initialized to reflect the browser’s locale by default.

Is there a way to change (translate) the toolkit messages like the “Session Expired: Take note of any unsaved data, and click here to continue.” for the final users?

Are those strings externalized or should I modify the source code? What file(s) should I look for?

In the case of external file for the strings, I would be happy to translate it to Portuguese and return the results to the community :mrgreen:

Hi,

Those messages are handled by a mechanism called ‘system messages’ - in practice you should override (or actually implement) the static Application.getSystemMessages() in your application and return CustomSystemMessages.

This may seem odd or awkward, but the reason for it is that there is not necessarily a Application instance available when the message should be shown (e.g. Session Expired). Note that if the session is expired, and there is no Application instance, you can not (currently) know which language the user wants, and you’ll probably want to say “Session Expired” in all languages available for your application.

The system message mechanism should probably be extended so that we can get the language from the browser and display the message in that language - I think there is a ticket for this, but I’m not sure, will have to check.

Please feel free to comment on the current system message mechanism: Did it work for you? What features or changes would you like to see?

Best Regards,
Marc

Thank you very much, Marc, for the directions. Knowing it, it was easy to find the right javadocs, which also was very useful. This is what I’ve done with success in my Application child class:


	public static SystemMessages getSystemMessages() {
		CustomizedSystemMessages m = new CustomizedSystemMessages();
		
		m.setSessionExpiredURL(null);
		m.setSessionExpiredNotificationEnabled(true);
		m.setSessionExpiredCaption("Sessão Expirada");
		m.setSessionExpiredMessage("Tome nota de quaisquer dados não salvos e <u>clique aqui</u> para continuar.");
		
		m.setInternalErrorURL(null);
		m.setInternalErrorNotificationEnabled(true);
		m.setInternalErrorCaption("Erro Interno");
		m.setInternalErrorMessage("Favor notiticar o administrador.<br/>Tome nota de quaisquer dados não salvos e <u>clique aqui</u> para continuar.");
		
		m.setOutOfSyncURL(null);
		m.setOutOfSyncNotificationEnabled(true);
		m.setOutOfSyncCaption("Fora de Sincronia");
		m.setOutOfSyncMessage("Algo fez com que perdêssemos a sincronia com o servidor.<br/>Tome nota de quaisquer dados não salvos e <u>clique aqui</u> para ressincronizar.");
		
		return m;
	}

The above strings are in Portuguese language. I hope it perhaps could be useful to people looking for similar solution.

My application, for now, will only be used by Brazilian Portuguese speakers, so the present code is doing fine the system messages job. Nevertheless, I think it would be useful to “multinational” applications to get the idiom from the browser and show the right message based on this instead of exibiting some sort of mixed language message. Still, it’s not a need. The present way works fine.

Again, thanks a lot.

Regards,

Hi again…

I’ve noted in 5.3 RC 9 there’s a new communicationErrorMessage, but I could not find any CustomizedSystemMessages.setCommunicationErrorMessage(String).

If this is true, please let’s get it corrected.

I wrote a ticket for it: http://dev.itmill.com/ticket/2521

Thanks a lot.

Good call - fixed it!

Best Regards,
Marc

Hi,

Chk this out for i18n Support and Captcha support:
http://code.google.com/p/tpt/

HTH
Ashwanth Kumar

Yep, you can use TPT (or take it as an example) for i18n support in vaadin applications. Unfortunately, it has not moved to 1.0 release yet as I almost had not any time to make the rest things done and also had a vacation, but I plan to complete documentation and release 1.0 in October. For now only javadocs are available, also, please feel free to ask anything on tpt, will be glad to help

Dmitri


Jain-I18N
is an another alternative API for internationalization support in the Vaadin-7.


Jain-I18N
is an another alternative API for internationalization support in the Vaadin-7.