Download

Online

Gallery

Blog

  Index  | Recent Threads  | List Attachments  | Search
 Welcome Guest  |  Register  |  Login
Login Name  Password
 

Sweet Home 3D Forum



No member browsing this thread
Thread Status: Active
Total posts in this thread: 13
Posts: 13   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 8485 times and has 12 replies Next Thread
hal9000
Advanced Member
Member's Avatar

Spain
Joined: May 9, 2012
Post Count: 154
Status: Offline
Reply to this Post  Reply with Quote 
Existing menus localization

I'm trying to put a plugin's option inside an existing SH3D menu, but since the menu names change depending on the current language I don't want to use for example "Plan", because if I do so then on my SH3D on Spanish I'll have the actual "Plano" menu (which is the Spanish translation for "Plan") with all the options and then a second "Plan" menu with only my plugin's option.

So, is there some way to get at runtime the localized strings for the menu names? That way the option will appear on the intended menu regardless of the current language.
----------------------------------------
If a long walk every day were healthy, mailmen would be immortal. tongue
[May 30, 2013, 5:28:56 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
hal9000
Advanced Member
Member's Avatar

Spain
Joined: May 9, 2012
Post Count: 154
Status: Offline
Reply to this Post  Reply with Quote 
Re: Existing menus localization

I've seen HomeView.ActionType for the menu options, but HomePane.MenuActionType is declared as private. sad
----------------------------------------
If a long walk every day were healthy, mailmen would be immortal. tongue
[May 31, 2013, 10:25:22 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9141
Status: Offline
Reply to this Post  Reply with Quote 
Re: Existing menus localization

Did you have a look at the section about localization at the end of the Plug-in developer's guide?
If you don't want to bother too much about this, you can use the Tools menu too.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer
[May 31, 2013, 10:31:51 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
hal9000
Advanced Member
Member's Avatar

Spain
Joined: May 9, 2012
Post Count: 154
Status: Offline
Reply to this Post  Reply with Quote 
Re: Existing menus localization

Did you have a look at the section about localization at the end of the Plug-in developer's guide?

Yes I did. But that allows me to localize the strings I use on my plugin, not to get the existing localized strings on the application.

Of course if I want to put my plugin option on the "3D View" menu, for example, I can just get all the translations for "3D View" from SH3D source and put them on my plugin. But the problem is that if in the future the localized string for "3D View" on some language changes, then on that language there will be two "3D View" menus, one with my localization (which coincides with the former official localization before the supposed change) and one with the new official localization.

The same problem will occur if a new language is added which is not included on the plugin: duplicated menu.

If there is a way to get the localized string at runtime then the option will always be displayed on the correct menu. If currently there is not a way to retrieve these strings, I think it's a good addition for a future release to prevent these menu duplications by the plugins.
----------------------------------------
If a long walk every day were healthy, mailmen would be immortal. tongue
[May 31, 2013, 10:52:47 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
hal9000
Advanced Member
Member's Avatar

Spain
Joined: May 9, 2012
Post Count: 154
Status: Offline
Reply to this Post  Reply with Quote 
Re: Existing menus localization

blushing blushing blushing blushing blushing blushing blushing

OK, forget what I said... I centered on the PluginAction constructors and overlooked the ResourceBundle part.

If somebody is interested, you can retrieve the name of a menu, lets say the "3D view" menu, like this:

ResourceBundle.getBundle("com.eteks.sweethome3d.swing.package").getString("HomePane.VIEW_3D_MENU.Name")


This is still not at runtime, but at least with this approach you don't need to copy to your plugin all the translations of the existing menus you want to use.

Thanks Emmanuel.
----------------------------------------
If a long walk every day were healthy, mailmen would be immortal. tongue
[May 31, 2013, 11:21:31 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
hal9000
Advanced Member
Member's Avatar

Spain
Joined: May 9, 2012
Post Count: 154
Status: Offline
Reply to this Post  Reply with Quote 
Re: Existing menus localization

By the way, can a plugin create a new submenu to group actions, or can only create actions on a first level menu?
----------------------------------------
If a long walk every day were healthy, mailmen would be immortal. tongue
[May 31, 2013, 1:06:51 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9141
Status: Offline
Reply to this Post  Reply with Quote 
Re: Existing menus localization

You can retrieve the resource with getLocalizedString method found in user preferences too:
getUserPreferences().getLocalizedString(HomePane.class, "VIEW_3D_MENU.Name")


There's no way to create a sub menu at this moment.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer
[May 31, 2013, 1:46:45 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
hal9000
Advanced Member
Member's Avatar

Spain
Joined: May 9, 2012
Post Count: 154
Status: Offline
Reply to this Post  Reply with Quote 
Re: Existing menus localization

You can retrieve the resource with getLocalizedString method found in user preferences too:
getUserPreferences().getLocalizedString(HomePane.class, "VIEW_3D_MENU.Name")

Good! That seems a cleaner way to do it.

Thanks.
----------------------------------------
If a long walk every day were healthy, mailmen would be immortal. tongue
[May 31, 2013, 2:22:25 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
hal9000
Advanced Member
Member's Avatar

Spain
Joined: May 9, 2012
Post Count: 154
Status: Offline
Reply to this Post  Reply with Quote 
Re: Existing menus localization

Now I have a related problem.

If I change the application language the plugin menu entry remains unchanged until I close and the open the application again. Is there some way to detect the language change so I can update the option name?
----------------------------------------
If a long walk every day were healthy, mailmen would be immortal. tongue
[Jun 14, 2013, 2:51:05 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9141
Status: Offline
Reply to this Post  Reply with Quote 
Re: Existing menus localization

Listen to UserPreferences.Property.LANGUAGE property changes, and be sure to use in the listener a weak reference to your plugin to avoid memory leaks (UserPreferences instance is some kind of global variable). See ResourceAction.LanguageChangeListener for an example.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer
[Jun 14, 2013, 3:48:13 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Posts: 13   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread

    Get Sweet Home 3D at SourceForge.net. Fast, secure and Free Open Source software downloads
   
© Copyright 2006-2024 eTeks - All rights reserved