mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
multi-language support
This commit is contained in:
@@ -34,6 +34,7 @@ import org.apache.log4j.PropertyConfigurator;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.PropertyInjector;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.lang.TranslateUtil;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.gui.MainFrame;
|
||||
import org.diylc.swing.gui.TemplateDialog;
|
||||
@@ -67,7 +68,7 @@ public class DIYLCStarter {
|
||||
} catch (Exception e) {
|
||||
System.out.println("Splash screen could not be initialized: " + e.getMessage());
|
||||
splashException = e;
|
||||
}
|
||||
}
|
||||
|
||||
URL url = DIYLCStarter.class.getResource("log4j.properties");
|
||||
Properties properties = new Properties();
|
||||
@@ -79,6 +80,8 @@ public class DIYLCStarter {
|
||||
}
|
||||
|
||||
ConfigurationManager.initialize("diylc");
|
||||
|
||||
TranslateUtil.configure();
|
||||
|
||||
LOG.debug("Java version: " + System.getProperty("java.runtime.version") + " by "
|
||||
+ System.getProperty("java.vm.vendor"));
|
||||
|
||||
@@ -67,6 +67,7 @@ import org.diylc.common.ITask;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.lang.TranslateUtil;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.IDynamicSubmenuHandler;
|
||||
import org.diylc.swing.ISwingUI;
|
||||
@@ -279,7 +280,7 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
|
||||
@Override
|
||||
public void showMessage(String message, String title, int messageType) {
|
||||
JOptionPane.showMessageDialog(this, message, title, messageType);
|
||||
JOptionPane.showMessageDialog(this, message, TranslateUtil.translate(title), messageType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -295,7 +296,7 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
@Override
|
||||
public boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties) {
|
||||
PropertyEditorDialog editor =
|
||||
DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Selection", true);
|
||||
DialogFactory.getInstance().createPropertyEditorDialog(properties, TranslateUtil.translate("Edit Selection"), true);
|
||||
editor.setVisible(true);
|
||||
defaultedProperties.addAll(editor.getDefaultedProperties());
|
||||
return ButtonDialog.OK.equals(editor.getSelectedButtonCaption());
|
||||
@@ -346,11 +347,19 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
@Override
|
||||
public void injectMenuAction(Action action, String menuName) {
|
||||
LOG.info(String.format("injectMenuAction(%s, %s)", action == null ? "Separator" : action.getValue(Action.NAME),
|
||||
menuName));
|
||||
JMenu menu = findOrCreateMenu(menuName);
|
||||
menuName));
|
||||
if (menuName != null)
|
||||
menuName = TranslateUtil.translate(menuName);
|
||||
|
||||
JMenu menu = findOrCreateMenu(menuName);
|
||||
if (action == null) {
|
||||
menu.addSeparator();
|
||||
} else {
|
||||
} else {
|
||||
// translate
|
||||
String name = (String) action.getValue(Action.NAME);
|
||||
if (name != null)
|
||||
action.putValue(Action.NAME, TranslateUtil.translate(name));
|
||||
|
||||
Boolean isCheckBox = (Boolean) action.getValue(IView.CHECK_BOX_MENU_ITEM);
|
||||
String groupName = (String) action.getValue(IView.RADIO_BUTTON_GROUP_KEY);
|
||||
if (isCheckBox != null && isCheckBox) {
|
||||
@@ -373,8 +382,13 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectSubmenu(String name, Icon icon, String parentMenuName) {
|
||||
LOG.info(String.format("injectSubmenu(%s, icon, %s)", name, parentMenuName));
|
||||
public void injectSubmenu(String name, Icon icon, String parentMenuName) {
|
||||
LOG.info(String.format("injectSubmenu(%s, icon, %s)", name, parentMenuName));
|
||||
|
||||
// translate
|
||||
name = TranslateUtil.translate(name);
|
||||
parentMenuName = parentMenuName == null ? null : TranslateUtil.translate(parentMenuName);
|
||||
|
||||
JMenu menu = findOrCreateMenu(parentMenuName);
|
||||
JMenu submenu = new JMenu(name);
|
||||
submenu.setIcon(icon);
|
||||
@@ -389,7 +403,12 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
|
||||
@Override
|
||||
public void injectDynamicSubmenu(String name, Icon icon, String parentMenuName, final IDynamicSubmenuHandler handler) {
|
||||
LOG.info(String.format("injectDynamicSubmenu(%s, icon, %s)", name, parentMenuName));
|
||||
LOG.info(String.format("injectDynamicSubmenu(%s, icon, %s)", name, parentMenuName));
|
||||
|
||||
// translate
|
||||
name = TranslateUtil.translate(name);
|
||||
parentMenuName = parentMenuName == null ? null : TranslateUtil.translate(parentMenuName);
|
||||
|
||||
final JMenu menu = findOrCreateMenu(parentMenuName);
|
||||
final JMenu submenu = new JMenu(name);
|
||||
submenu.setIcon(icon);
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.lang.TranslateUtil;
|
||||
import org.diylc.swing.ActionFactory;
|
||||
import org.diylc.swing.ISwingUI;
|
||||
import org.diylc.swing.plugins.help.HelpMenuPlugin;
|
||||
@@ -55,7 +56,7 @@ public class ActionBarPlugin implements IPlugIn {
|
||||
private ConfigToolbar configToolbar;
|
||||
private JLabel donateLabel;
|
||||
|
||||
private static final String DONATE_HTML = "<html><u>Enjoying DIYLC? Click here to buy me a coffe :)</u></html>";
|
||||
private static final String DONATE_HTML = "<html><u>" + TranslateUtil.translate("Enjoying DIYLC? Click here to buy me a coffe :)") + "</u></html>";
|
||||
|
||||
public ActionBarPlugin(ISwingUI swingUI) {
|
||||
this.swingUI = swingUI;
|
||||
|
||||
@@ -21,14 +21,18 @@
|
||||
*/
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JComboBox;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JList;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.lang.TranslateUtil;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
public class EnumEditor extends JComboBox {
|
||||
@@ -44,7 +48,19 @@ public class EnumEditor extends JComboBox {
|
||||
Object[] values = property.getType().getEnumConstants();
|
||||
if (property.isReadOnly())
|
||||
setEnabled(false);
|
||||
setModel(new DefaultComboBoxModel(values));
|
||||
setModel(new DefaultComboBoxModel(values));
|
||||
setRenderer(new DefaultListCellRenderer() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
|
||||
boolean isSelected, boolean cellHasFocus) {
|
||||
// TODO Auto-generated method stub
|
||||
return super.getListCellRendererComponent(list, value == null ? null : TranslateUtil.translate(value.toString()), index, isSelected, cellHasFocus);
|
||||
}
|
||||
|
||||
});
|
||||
setSelectedItem(property.getValue());
|
||||
addItemListener(new ItemListener() {
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import javax.swing.JPanel;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.ValidationException;
|
||||
import org.diylc.lang.TranslateUtil;
|
||||
import org.diylc.swingframework.ButtonDialog;
|
||||
|
||||
public class PropertyEditorDialog extends ButtonDialog {
|
||||
@@ -127,7 +128,7 @@ public class PropertyEditorDialog extends ButtonDialog {
|
||||
gbc.weightx = 0;
|
||||
gbc.insets = new Insets(4, 2, 2, 2);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
editorPanel.add(new JLabel(property.getName() + ": "), gbc);
|
||||
editorPanel.add(new JLabel(TranslateUtil.translate(property.getName()) + ": "), gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.lang.TranslateUtil;
|
||||
import org.diylc.swing.ISwingUI;
|
||||
import org.diylc.swing.gui.DialogFactory;
|
||||
import org.diylc.swingframework.AboutDialog;
|
||||
@@ -122,7 +123,7 @@ public class HelpMenuPlugin implements IPlugIn {
|
||||
|
||||
public AboutAction() {
|
||||
super();
|
||||
putValue(AbstractAction.NAME, "About");
|
||||
putValue(AbstractAction.NAME, TranslateUtil.translate("About"));
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.About.getIcon());
|
||||
}
|
||||
|
||||
@@ -138,7 +139,7 @@ public class HelpMenuPlugin implements IPlugIn {
|
||||
|
||||
public RecentUpdatesAction() {
|
||||
super();
|
||||
putValue(AbstractAction.NAME, "Recent Updates");
|
||||
putValue(AbstractAction.NAME, TranslateUtil.translate("Recent Updates"));
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.ScrollInformation.getIcon());
|
||||
}
|
||||
|
||||
@@ -164,7 +165,7 @@ public class HelpMenuPlugin implements IPlugIn {
|
||||
public NavigateURLAction(String name, Icon icon, String url) {
|
||||
super();
|
||||
this.url = url;
|
||||
putValue(AbstractAction.NAME, name);
|
||||
putValue(AbstractAction.NAME, TranslateUtil.translate(name));
|
||||
putValue(AbstractAction.SMALL_ICON, icon);
|
||||
}
|
||||
|
||||
@@ -187,7 +188,7 @@ public class HelpMenuPlugin implements IPlugIn {
|
||||
public NavigateFolderAction(String name, Icon icon, String url) {
|
||||
super();
|
||||
this.url = url;
|
||||
putValue(AbstractAction.NAME, name);
|
||||
putValue(AbstractAction.NAME, TranslateUtil.translate(name));
|
||||
putValue(AbstractAction.SMALL_ICON, icon);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user