Re: Dynamic translation of a plug-in
Code: Select all
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
}Code: Select all
// addition start PVR-2.7
// Based on https://sourceforge.net/p/sweethome3d/code/8462/tree/trunk/SweetHome3D/src/com/eteks/sweethome3d/swing/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