Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Change 'locale' attribute in TranslationService at Runtime
Change 'locale' attribute in TranslationService at Runtime [message #876286] Thu, 24 May 2012 10:08 Go to next message
Marko Herchet is currently offline Marko Herchet
Messages: 11
Registered: May 2012
Junior Member
There is an attribute
@Inject
	@Named(LOCALE)
	protected String locale;

in the org.eclipse.e4.core.services.translation.TranslationService class which is used in the translate-implementation of org.eclipse.e4.core.internal.services.BundleTranslationProvider to get the ResourceBundle for the given locale.

I thought that the injection-logic will update the locale-attribute when I do the following:
m_Application.getContext().set(TranslationService.LOCALE, "de");

but nothing happens (breakpoint in translate showed that the value of locale was still 'en' -> the locale.getdefault)

Am I missing smth?

Thanks,
Marko

Re: Change 'locale' attribute in TranslationService at Runtime [message #876331 is a reply to message #876286] Thu, 24 May 2012 11:42 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5417
Registered: July 2009
Senior Member
The TranslationService is currently created on the Root-Context which is
the parent of the context attached to MApplication.

The problem is that the important code parts (most import ones are the
Renderers) are not reacting on the change of a locale so dynamic switch
the UI won't work as you'd expect it to work ;-)

We only had time to create the foundation for future in implementations.

Tom

Am 24.05.12 12:08, schrieb Marko Herchet:
> There is an attribute @Inject
> @Named(LOCALE)
> protected String locale;
> in the org.eclipse.e4.core.services.translation.TranslationService class
> which is used in the translate-implementation of
> org.eclipse.e4.core.internal.services.BundleTranslationProvider to get
> the ResourceBundle for the given locale.
>
> I thought that the injection-logic will update the locale-attribute when
> I do the following:
> m_Application.getContext().set(TranslationService.LOCALE, "de");
> but nothing happens (breakpoint in translate showed that the value of
> locale was still 'en' -> the locale.getdefault)
>
> Am I missing smth?
>
> Thanks,
> Marko
>
>
Re: Change 'locale' attribute in TranslationService at Runtime [message #876362 is a reply to message #876331] Thu, 24 May 2012 13:02 Go to previous messageGo to next message
Marko Herchet is currently offline Marko Herchet
Messages: 11
Registered: May 2012
Junior Member
Thanks for the answer Tom.
I replaced my code with
m_Application.getContext().getParent().set(TranslationService.LOCALE, "de");

and it works the way I want.

Quote:

The problem is that the important code parts (most import ones are the
Renderers) are not reacting on the change of a locale so dynamic switch
the UI won't work as you'd expect it to work Wink

I think I understand what you mean, but at the time I want to change the locale, the workbench is empty except for MainWindow, MainMenu and the MainToolbar. So it will be no problem as long as there is a way for me to tell the renderers that they have to update/recreate the said 3 elements. Think I've seen smth like MenuManagerRenderer.clean(MUIElement) but I'm not sure if this is what iam looking for.

Some suggests how to archieve this?

Thanks,
Marko

[Updated on: Thu, 24 May 2012 13:03]

Report message to a moderator

Re: Change 'locale' attribute in TranslationService at Runtime [message #876445 is a reply to message #876362] Thu, 24 May 2012 15:52 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5417
Registered: July 2009
Senior Member
If you use a lifecycle-handler you can get in even earlier (before any
rendering has happened!).

I don't think there's currently a way to instruct the renderers to
reread informations beside setting a new value on the label which will
lead to a model event the renderer is registered on.

Tom

Am 24.05.12 15:02, schrieb Marko Herchet:
> Thanks for the answer Tom.
> I replaced my code with
> m_Application.getContext().getParent().set(TranslationService.LOCALE,
> "de");
> and it works the way I want.
>
> Quote:
>> The problem is that the important code parts (most import ones are the
>> Renderers) are not reacting on the change of a locale so dynamic switch
>> the UI won't work as you'd expect it to work ;)
>
> I think I understand what you mean, but at the time I want to change the
> locale, the workbench is empty except for MainWindow, MainMenu and the
> MainToolbar. So it will be no problem as long as there is a way for me
> to tell the renderer that he has to update/recreate the said 3 elements.
> Think I've seen smth like MenuManagerRenderer.clean(MUIElement) but I'm
> not sure if this is what iam looking for.
>
> Some suggests how to archieve this?
>
> Thanks,
> Marko
Re: Change 'locale' attribute in TranslationService at Runtime [message #877399 is a reply to message #876286] Sat, 26 May 2012 17:09 Go to previous message
Marko Herchet is currently offline Marko Herchet
Messages: 11
Registered: May 2012
Junior Member
What I found out, is that some Texts will change automatically after running my code. Tooltips of MainToolbarItems for example seems to be updated on every enablement check. Don't know if this is by design. Labels of Submenus will occur in the right language too, when opened (even if it was opened before the language-change). But iam not sure if the submenu-items are newly created on every menuShow like I usually do it in ContextMenus for my Trees and Tables.

For the other Widgets are not too many, I will just iterate over them after language change and manually change their labels to smth. like MMenuElement.getTranslatedLabel(). Already tried it and it seems to work.


Thanks for your help Tom
Previous Topic:API to programmatically modify product configuration
Next Topic:What happens to the class HandlerUtil
Goto Forum:
  


Current Time: Thu Oct 23 12:35:50 GMT 2014

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

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