Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to use @Translation in E4 application(Unit test illustrating Translation mechanism fails)
How to use @Translation in E4 application [message #1746625] Wed, 02 November 2016 08:37 Go to next message
Erik Vande Velde is currently offline Erik Vande VeldeFriend
Messages: 82
Registered: September 2012
Member
I'm trying to write a unit test to illustrate how the locale of the user can be used to internationalize an E4 application, my current code is attached. There are many theories I found on how to get the translation service mechanism working, but none of them seem to work for me:
-> setting equinox.root.locale, as advised in http://blog.vogella.com/2013/05/22/eclipse-internationalization-part-24-new-message-extension-by-dirk-fauth-and-tom-schindl/
-> context.getParent().set(TranslationService.LOCALE, "de") as in https://www.eclipse.org/forums/index.php/t/354924/
My current unit test is simple enough, trying to show a Dutch message for locale "nl", and an English message for all other locales, but no matter what I try I also get the English message for Dutch users ... What am I missing ??
  • Attachment: i18n.zip
    (Size: 45.34KB, Downloaded 94 times)
Re: How to use @Translation in E4 application [message #1746633 is a reply to message #1746625] Wed, 02 November 2016 10:11 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I can not download the ZIP file. My browser says it is harmful and therefore blocks it.

You misunderstand the explanation on equinox.root.locale. We do not advice to set it to specify a different locale. We say that you can change that value to specify a different fallback locale. Default is en (which you want) but you could change that if your base resource bundle file contains localizations for another locale.

context.getParent().set() only works on the context you are working. Which context are you on? Probably not high enough to catch all.

The question is, do you want to set the localization on startup or change it at runtime?

If you want to set it on startup, use the -nl runtime option as Program Argument (e.g. in a launch configuration)
http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html

If you want to change it at runtime use the ILocaleChangeService which sets the locale to the application context, updates the application model and sends an locale change event via EventBroker.

A sample can be found here (also linked in our blog post series):
https://github.com/fipro78/e4translationexample
Re: How to use @Translation in E4 application [message #1746663 is a reply to message #1746633] Wed, 02 November 2016 15:35 Go to previous messageGo to next message
Erik Vande Velde is currently offline Erik Vande VeldeFriend
Messages: 82
Registered: September 2012
Member
I've put the current code on https://github.com/erikatfugro/i18n
In the real application I want to set the localisation after login, based on the data we find about the user in our server database. But in this specific case I just want to show that it's possible with the translation service to show a Dutch user a dutch message and a non-dutch user an english message. Because I have 1 run configuration to run both test methods the program argument is not an option for my test case/class, so I need runtime localisation. Currently the context is just created with IEclipseContext context = EclipseContextFactory.create(), like you say 'Probably not high enough to catch all' ? I'll have a deeper look at your e4translationexample soon, maybe everything will become clear after that ...
Re: How to use @Translation in E4 application [message #1746665 is a reply to message #1746663] Wed, 02 November 2016 16:01 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
You are putting some more abstractions and complexities in with your test scenario.
a) you create a new EclipseContext without a parent. That one is not connected to the application or service context.
b) The E4 translation mechanism is based on DS ... which means you need the DS bundle in your test runtime. And since you typically don't specify that dependency explicitly, you need to to it in another way. Either by specifying it via Tycho or via p2.inf. I wrote a blog post about that recently: http://blog.vogella.com/2016/07/04/osgi-component-testing/

You can also check the Platform JUnit tests for the E4 translation mechanism to get an idea how to achieve your goals: https://github.com/eclipse/eclipse.platform.runtime/blob/master/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java

In the end it is the infrastructure that makes your tests fail.
Previous Topic:Why is @EventTopic in an internal package?
Next Topic:Eclipse plugin life cycle
Goto Forum:
  


Current Time: Wed Apr 24 20:59:43 GMT 2024

Powered by FUDForum. Page generated in 0.03093 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top