mirror of https://github.com/zlatinb/muwire
show language selection dialog if gui.properties does not exist
parent
c3e66bde2f
commit
8293a5128d
|
@ -1,4 +1,5 @@
|
|||
import griffon.core.GriffonApplication
|
||||
import groovy.swing.SwingBuilder
|
||||
import groovy.util.logging.Log
|
||||
import net.i2p.util.SystemVersion
|
||||
|
||||
|
@ -12,22 +13,26 @@ import com.muwire.gui.UISettings
|
|||
import javax.annotation.Nonnull
|
||||
import javax.inject.Inject
|
||||
import javax.swing.ImageIcon
|
||||
import javax.swing.JFrame
|
||||
import javax.swing.JLabel
|
||||
import javax.swing.JPopupMenu
|
||||
import javax.swing.JTable
|
||||
import javax.swing.LookAndFeel
|
||||
import javax.swing.SwingUtilities
|
||||
import javax.swing.UIManager
|
||||
import javax.swing.plaf.FontUIResource
|
||||
|
||||
import static griffon.util.GriffonApplicationUtils.isMacOSX
|
||||
import static groovy.swing.SwingBuilder.lookAndFeel
|
||||
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Font
|
||||
import java.awt.MenuItem
|
||||
import java.awt.PopupMenu
|
||||
import java.awt.SystemTray
|
||||
import java.awt.Toolkit
|
||||
import java.awt.TrayIcon
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.logging.Level
|
||||
import java.util.logging.LogManager
|
||||
|
||||
|
@ -119,6 +124,8 @@ class Initialize extends AbstractLifecycleHandler {
|
|||
uiSettings.fontSize = defaultFont.getSize()
|
||||
uiSettings.fontStyle = defaultFont.getStyle()
|
||||
rowHeight = uiSettings.fontSize + 3
|
||||
|
||||
uiSettings.locale = showLanguageDialog()
|
||||
}
|
||||
|
||||
application.context.put("row-height", rowHeight)
|
||||
|
@ -196,5 +203,37 @@ class Initialize extends AbstractLifecycleHandler {
|
|||
}
|
||||
defaultHome.getAbsolutePath()
|
||||
}
|
||||
|
||||
private String showLanguageDialog() {
|
||||
def builder = new SwingBuilder()
|
||||
def languageComboBox
|
||||
def chooseButton
|
||||
def frame = builder.frame (visible : true, locationRelativeTo: null,
|
||||
defaultCloseOperation : JFrame.EXIT_ON_CLOSE,
|
||||
iconImage : builder.imageIcon("/MuWire-48x48.png").image) {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.NORTH) {
|
||||
label("Select Language")
|
||||
}
|
||||
|
||||
languageComboBox = comboBox (editable: false, items : Translator.LOCALE_WRAPPERS, constraints : BorderLayout.CENTER)
|
||||
|
||||
panel (constraints : BorderLayout.SOUTH) {
|
||||
chooseButton = button(text : "Choose")
|
||||
}
|
||||
}
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1)
|
||||
chooseButton.addActionListener({
|
||||
frame.setVisible(false)
|
||||
latch.countDown()
|
||||
})
|
||||
SwingUtilities.invokeAndWait({
|
||||
frame.pack()
|
||||
frame.setVisible(true)
|
||||
})
|
||||
latch.await()
|
||||
languageComboBox.getSelectedItem().locale.toLanguageTag()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,29 @@
|
|||
package com.muwire.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
public class Translator {
|
||||
|
||||
|
||||
public static final Set<Locale> SUPPORTED_LOCALES = new LinkedHashSet<>();
|
||||
static {
|
||||
SUPPORTED_LOCALES.add(Locale.US);
|
||||
SUPPORTED_LOCALES.add(Locale.forLanguageTag("bg"));
|
||||
// add more as they get translated
|
||||
}
|
||||
|
||||
public static final List<LocaleWrapper> LOCALE_WRAPPERS = new ArrayList<>();
|
||||
static {
|
||||
for (Locale l : SUPPORTED_LOCALES)
|
||||
LOCALE_WRAPPERS.add(new LocaleWrapper(l));
|
||||
}
|
||||
|
||||
private static Locale locale = Locale.US;
|
||||
private static ResourceBundle usBundle = ResourceBundle.getBundle("messages");
|
||||
private static ResourceBundle localeBundle;
|
||||
|
@ -24,5 +42,16 @@ public class Translator {
|
|||
return usBundle.getString(key);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LocaleWrapper {
|
||||
private final Locale locale;
|
||||
LocaleWrapper(Locale locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return locale.getDisplayLanguage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue