|
Posted by enkonyito
at Jan 16, 2024, 11:31:10 PM
|
Re: Dynamic translation of a plug-in
Thanks to both of you for the information, it works for the photo creation panel (title, components).
Based on the ResourceAction class, dynamic translation works for plug-in actions, but the menu remains unchanged despite the new value.
public SimplePhotoRenderingAction(PhotoVideoRendering photoVideoRendering) { // modification start PVR-2.7 ResourceBundle resource = ResourceBundle.getBundle("sh3dPlugin.ApplicationPlugin", Locale.getDefault(), getClass().getClassLoader()); putPropertyValue(Property.NAME, photoVideoRendering.getUserPreferences().getLocalizedString(HomePane.class, "CREATE_PHOTO.Name") + " (PVR-" + photoVideoRendering.getVersion() + ")"); putPropertyValue(Property.SHORT_DESCRIPTION, photoVideoRendering.getUserPreferences().getLocalizedString(HomePane.class, "CREATE_PHOTO.ShortDescription")); putPropertyValue(Property.MENU, resource.getString("SimplePhotoRenderingAction.MENU")); setEnabled(true);
SimplePhotoRenderingAction.photoVideoRenderingPlugin = photoVideoRendering;
photoVideoRendering.getUserPreferences().addPropertyChangeListener(UserPreferences.Property.LANGUAGE , new LanguageChangeListener(this)); // modification end PVR-2.7 }
// addition start PVR-2.7 // Based on https://sourceforge.net/p/sweethome3d/code/84...g/ResourceAction.java#l89 (SH3D-7.1) /** * Preferences property listener bound to this action with a weak reference to avoid * strong link between preferences and this action. */ private static class LanguageChangeListener implements PropertyChangeListener { private final WeakReference<SimplePhotoRenderingAction> pluginAction; public LanguageChangeListener(SimplePhotoRenderingAction pluginAction) { this.pluginAction = new WeakReference<SimplePhotoRenderingAction>(pluginAction); }
public void propertyChange(PropertyChangeEvent ev) { // If action was garbage collected, remove this listener from preferences SimplePhotoRenderingAction pluginAction = this.pluginAction.get(); if (pluginAction == null) { ((UserPreferences)ev.getSource()).removePropertyChangeListener( UserPreferences.Property.LANGUAGE, this); } else { ResourceBundle resource = ResourceBundle.getBundle("sh3dPlugin.ApplicationPlugin", Locale.getDefault(), getClass().getClassLoader()); pluginAction.putPropertyValue(Property.NAME, ((UserPreferences)ev.getSource()).getLocalizedString(HomePane.class, "CREATE_PHOTO.Name") + " (PVR-" + SimplePhotoRenderingAction.photoVideoRenderingPlugin.getVersion() + ")"); pluginAction.putPropertyValue(Property.SHORT_DESCRIPTION, ((UserPreferences)ev.getSource()).getLocalizedString(HomePane.class, "CREATE_PHOTO.ShortDescription")); pluginAction.putPropertyValue(Property.MENU, resource.getString("SimplePhotoRenderingAction.MENU")); } } } // addition end PVR-2.7
I could have put the plug-in actions in the existing 3D View menu, but I prefer to avoid doing so so that there is no confusion with the default actions of Sweet Home 3D.
----------------------------------------
EnkoNyito
|