Now OptionPane Yes No are translated

This commit is contained in:
huangyuhui
2017-07-28 09:44:29 +08:00
parent caa77387df
commit 34d560b75e
36 changed files with 86 additions and 36 deletions

View File

@@ -33,6 +33,7 @@ import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.X509TrustManager;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.RepaintManager;
import org.jackhuang.hmcl.api.HMCLApi;
import org.jackhuang.hmcl.api.HMCLog;
@@ -46,7 +47,7 @@ import org.jackhuang.hmcl.ui.MainFrame;
import org.jackhuang.hmcl.util.CrashReporter;
import org.jackhuang.hmcl.util.DefaultPlugin;
import org.jackhuang.hmcl.util.MathUtils;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.util.lang.SupportedLocales;
import org.jackhuang.hmcl.util.log.Configuration;
@@ -178,8 +179,9 @@ public final class Main {
String s = Settings.getInstance().getLocalization();
for (SupportedLocales sl : SupportedLocales.values())
if (sl.name().equals(s)) {
SupportedLocales.NOW_LOCALE = sl;
SupportedLocales.setNowLocale(sl);
Locale.setDefault(sl.self);
JOptionPane.setDefaultLocale(sl.self);
}
if (System.getProperty("java.vm.name").contains("Open")) // OpenJDK

View File

@@ -32,7 +32,7 @@ import org.jackhuang.hmcl.api.event.config.ProfileChangedEvent;
import org.jackhuang.hmcl.api.event.config.ProfileLoadingEvent;
import org.jackhuang.hmcl.laf.utils.AnimationController;
import org.jackhuang.hmcl.util.sys.FileUtils;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.UpdateChecker;
import org.jackhuang.hmcl.util.sys.IOUtils;

View File

@@ -23,7 +23,7 @@ import org.jackhuang.hmcl.api.ui.TopTabPage;
import org.jackhuang.hmcl.core.download.MinecraftRemoteVersions;
import org.jackhuang.hmcl.setting.Settings;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.util.task.ProgressProviderListener;
import org.jackhuang.hmcl.util.task.Task;

View File

@@ -36,7 +36,6 @@ import java.io.IOException;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
@@ -59,7 +58,7 @@ import org.jackhuang.hmcl.core.install.InstallerType;
import org.jackhuang.hmcl.api.game.GameDirType;
import org.jackhuang.hmcl.core.version.MinecraftVersion;
import org.jackhuang.hmcl.setting.VersionSetting;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.AbstractSwingWorker;
import org.jackhuang.hmcl.util.MinecraftVersionRequest;
import org.jackhuang.hmcl.util.sys.OS;
@@ -168,7 +167,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
JMenuItem itm = new JMenuItem(C.i18n("versions.manage.rename"));
itm.addActionListener((e) -> {
if (mcVersion != null) {
String newName = JOptionPane.showInputDialog(C.i18n("versions.manage.rename.message"), mcVersion);
String newName = MessageBox.showInputDialog(C.i18n("versions.manage.rename.message"), mcVersion);
if (newName != null)
if (Settings.getLastProfile().service().version().renameVersion(mcVersion, newName))
refreshVersions();
@@ -994,7 +993,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
fc.setFileSelectionMode(JSystemFileChooser.DIRECTORIES_ONLY);
if (fc.showOpenDialog(this) == JSystemFileChooser.APPROVE_OPTION) {
File newGameDir = fc.getSelectedFile();
String name = JOptionPane.showInputDialog(C.i18n("setupwindow.give_a_name"));
String name = MessageBox.showInputDialog(C.i18n("setupwindow.give_a_name"));
if (StrUtils.isBlank(name)) {
MessageBox.show(C.i18n("setupwindow.no_empty_name"));
return;

View File

@@ -28,7 +28,7 @@ import org.jackhuang.hmcl.core.install.InstallerType;
import org.jackhuang.hmcl.core.install.InstallerVersionList;
import org.jackhuang.hmcl.util.task.TaskRunnable;
import org.jackhuang.hmcl.util.task.TaskWindow;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.util.task.ProgressProviderListener;
import org.jackhuang.hmcl.util.task.Task;

View File

@@ -27,7 +27,7 @@ import org.jackhuang.hmcl.setting.Settings;
import org.jackhuang.hmcl.core.download.DownloadType;
import org.jackhuang.hmcl.util.MathUtils;
import org.jackhuang.hmcl.util.sys.IOUtils;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.lang.SupportedLocales;
import org.jackhuang.hmcl.util.ui.JFontComboBox;
import org.jackhuang.hmcl.util.ui.JSystemFileChooser;

View File

@@ -20,7 +20,6 @@ package org.jackhuang.hmcl.ui;
import java.io.File;
import java.io.IOException;
import java.io.PipedOutputStream;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.jackhuang.hmcl.api.HMCLApi;
import org.jackhuang.hmcl.api.event.process.JVMLaunchFailedEvent;
@@ -36,12 +35,13 @@ import org.jackhuang.hmcl.setting.Settings;
import org.jackhuang.hmcl.util.HMCLGameLauncher;
import org.jackhuang.hmcl.util.MinecraftCrashAdvicer;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.api.func.Consumer;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.api.event.launch.LaunchingState;
import org.jackhuang.hmcl.util.DefaultPlugin;
import org.jackhuang.hmcl.util.Log4jHandler;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.util.sys.FileUtils;
import org.jackhuang.hmcl.util.sys.PrintlnEvent;
import org.jackhuang.hmcl.util.sys.ProcessMonitor;
@@ -244,8 +244,8 @@ public class LaunchingUIDaemon {
private static final Consumer<LaunchSucceededEvent> LAUNCH_SCRIPT_FINISHER = event -> {
try {
String s = JOptionPane.showInputDialog(C.i18n("mainwindow.enter_script_name"));
if (s != null)
String s = MessageBox.showInputDialog(C.i18n("mainwindow.enter_script_name"));
if (StrUtils.isNotBlank(s))
MessageBox.show(C.i18n("mainwindow.make_launch_succeed") + " " + ((GameLauncher) event.getSource()).makeLauncher(s, event.getValue()).getAbsolutePath());
} catch (IOException ex) {
MessageBox.show(C.i18n("mainwindow.make_launch_script_failed"));

View File

@@ -57,7 +57,7 @@ import org.jackhuang.hmcl.api.PluginManager;
import org.jackhuang.hmcl.api.event.config.ThemeChangedEvent;
import org.jackhuang.hmcl.setting.Settings;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.util.ui.BasicColors;

View File

@@ -26,7 +26,6 @@ import java.awt.Font;
import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.jackhuang.hmcl.api.HMCLApi;
@@ -55,6 +54,7 @@ import org.jackhuang.hmcl.util.ui.SwingUtils;
import org.jackhuang.hmcl.util.ui.wizard.api.WizardDisplayer;
import org.jackhuang.hmcl.api.auth.IAuthenticator;
import org.jackhuang.hmcl.laf.button.CustomButtonUI;
import org.jackhuang.hmcl.util.ui.MessageBox;
/**
*
@@ -402,7 +402,9 @@ public class MainPagePanel extends Page {
fc.showOpenDialog(this);
if (fc.getSelectedFile() == null)
return;
String suggestedModpackId = JOptionPane.showInputDialog(C.i18n("modpack.enter_name"), FileUtils.getBaseName(fc.getSelectedFile().getName()));
String suggestedModpackId = MessageBox.showInputDialog(C.i18n("modpack.enter_name"), FileUtils.getBaseName(fc.getSelectedFile().getName()));
if (StrUtils.isBlank(suggestedModpackId))
return;
TaskWindow.factory().append(ModpackManager.install(MainFrame.INSTANCE, fc.getSelectedFile(), Settings.getLastProfile().service(), suggestedModpackId)).execute();
Settings.getLastProfile().service().version().refreshVersions();
}//GEN-LAST:event_btnImportModpackActionPerformed

View File

@@ -23,7 +23,7 @@ import java.io.IOException;
import java.util.Map;
import javax.swing.JOptionPane;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.util.net.WebPage;
import org.jackhuang.hmcl.util.ui.wizard.spi.WizardController;

View File

@@ -19,7 +19,7 @@ package org.jackhuang.hmcl.util;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

View File

@@ -17,7 +17,6 @@
*/
package org.jackhuang.hmcl.util;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.util.lang.SupportedLocales;
/**
@@ -34,7 +33,7 @@ public final class MinecraftCrashAdvicer {
public static String getAdvice(String trace, boolean selfCrash) {
if (trace == null)
return C.i18n("crash.advice.no");
trace = trace.toLowerCase(SupportedLocales.NOW_LOCALE.self);
trace = trace.toLowerCase(SupportedLocales.getNowLocale().self);
if (trace.contains("pixel format not accelerated"))
return C.i18n("crash.advice.LWJGLException");
else if (trace.contains("unsupportedclassversionrrror"))

View File

@@ -46,7 +46,7 @@ import org.jackhuang.hmcl.util.task.Task;
import org.jackhuang.hmcl.util.task.TaskWindow;
import org.jackhuang.hmcl.util.net.FileDownloadTask;
import org.jackhuang.hmcl.util.ArrayUtils;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.UpdateChecker;
import org.jackhuang.hmcl.util.Utils;
import org.jackhuang.hmcl.api.VersionNumber;

View File

@@ -30,7 +30,7 @@ import org.jackhuang.hmcl.core.service.IMinecraftAssetService;
import org.jackhuang.hmcl.core.service.IMinecraftService;
import org.jackhuang.hmcl.core.version.AssetIndexDownloadInfo;
import org.jackhuang.hmcl.core.version.MinecraftVersion;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.core.version.LoggingInfo;
import org.jackhuang.hmcl.util.task.Task;

View File

@@ -23,13 +23,13 @@ import org.jackhuang.hmcl.api.auth.AuthenticationException;
import com.google.gson.GsonBuilder;
import java.net.Proxy;
import java.util.Map;
import javax.swing.JOptionPane;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.util.ArrayUtils;
import org.jackhuang.hmcl.core.auth.yggdrasil.GameProfile;
import org.jackhuang.hmcl.core.auth.yggdrasil.UUIDTypeAdapter;
import org.jackhuang.hmcl.core.auth.yggdrasil.PropertyMap;
import org.jackhuang.hmcl.core.auth.yggdrasil.YggdrasilAuthentication;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.ui.SwingUtils;
/**
@@ -77,7 +77,7 @@ public final class YggdrasilAuthenticator extends AbstractAuthenticator {
selectedProfile = profiles[sel];
username = names[sel];
} else
username = JOptionPane.showInputDialog(C.i18n("login.no_charactor"));
username = MessageBox.showInputDialog(C.i18n("login.no_charactor"));
else
username = selectedProfile.name;
if (username == null)

View File

@@ -79,7 +79,7 @@ public class MojangDownloadProvider extends IDownloadProvider {
else if (str.contains("scala-swing") || str.contains("scala-xml") || str.contains("scala-parser-combinators"))
return str.replace("http://files.minecraftforge.net/maven", "http://ftb.cursecdn.com/FTB2/maven/");
else if (str.contains("typesafe") || str.contains("scala"))
if (SupportedLocales.NOW_LOCALE.self == Locale.CHINA)
if (SupportedLocales.getNowLocale().self == Locale.CHINA)
return str.replace("http://files.minecraftforge.net/maven", "http://maven.aliyun.com/nexus/content/groups/public");
else
return str.replace("http://files.minecraftforge.net/maven", "http://repo1.maven.org/maven2");

View File

@@ -29,7 +29,7 @@ import org.jackhuang.hmcl.core.service.IMinecraftService;
import org.jackhuang.hmcl.util.task.Task;
import org.jackhuang.hmcl.util.sys.FileUtils;
import org.jackhuang.hmcl.core.version.MinecraftLibrary;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.sys.IOUtils;
/**

View File

@@ -27,7 +27,7 @@ import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.util.sys.JdkVersion;
import org.jackhuang.hmcl.util.MathUtils;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.sys.OS;
import org.jackhuang.hmcl.util.sys.Platform;
import org.jackhuang.hmcl.util.StrUtils;

View File

@@ -25,7 +25,7 @@ import org.jackhuang.hmcl.core.download.DownloadLibraryJob;
import org.jackhuang.hmcl.api.auth.LoginInfo;
import org.jackhuang.hmcl.core.service.IMinecraftService;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.util.sys.CompressingUtils;
import org.jackhuang.hmcl.util.task.ParallelTask;

View File

@@ -39,7 +39,7 @@ import org.jackhuang.hmcl.core.service.IMinecraftService;
import org.jackhuang.hmcl.util.sys.FileUtils;
import org.jackhuang.hmcl.core.MCUtils;
import org.jackhuang.hmcl.util.task.TaskWindow;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.api.func.Consumer;
import org.jackhuang.hmcl.api.func.Predicate;

View File

@@ -42,7 +42,7 @@ public final class C {
}
public static String i18n(String a, Object... format) {
return SupportedLocales.NOW_LOCALE.translate(a, format);
return SupportedLocales.getNowLocale().translate(a, format);
}
}

View File

@@ -17,6 +17,7 @@
*/
package org.jackhuang.hmcl.util;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.api.VersionNumber;
import org.jackhuang.hmcl.api.event.EventHandler;
import org.jackhuang.hmcl.util.net.NetUtils;

View File

@@ -53,7 +53,15 @@ public enum SupportedLocales {
return NOW_LOCALE.translate(customized);
}
public static SupportedLocales NOW_LOCALE = def;
private static SupportedLocales NOW_LOCALE = def;
public static SupportedLocales getNowLocale() {
return NOW_LOCALE;
}
public static void setNowLocale(SupportedLocales newLocale) {
NOW_LOCALE = newLocale;
}
public String translate(String key, Object... format) {
try {

View File

@@ -24,7 +24,7 @@ import javax.swing.SwingUtilities;
import javax.swing.table.TableColumn;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.ui.MessageBox;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.util.ui.SwingUtils;

View File

@@ -15,10 +15,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hmcl.util;
package org.jackhuang.hmcl.util.ui;
import org.jackhuang.hmcl.util.ui.SwingUtils;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import org.jackhuang.hmcl.util.C;
/**
* @author huangyuhui
@@ -103,6 +104,18 @@ public class MessageBox {
}
return 0;
}
public static String showInputDialog(String msg) {
return showInputDialog(msg, UIManager.getString("OptionPane.inputDialogTitle"));
}
public static String showInputDialog(String msg, String title) {
return showInputDialog(msg, title, null);
}
public static String showInputDialog(String msg, String title, String init) {
return (String) JOptionPane.showInputDialog(null, msg, title, JOptionPane.QUESTION_MESSAGE, null, null, init);
}
/**
* Show MsgBox with options
@@ -130,4 +143,11 @@ public class MessageBox {
public static int showLocalized(String msg) {
return show(C.i18n(msg));
}
static {
UIManager.put("OptionPane.cancelButtonText", C.i18n("button.cancel"));
UIManager.put("OptionPane.noButtonText", C.i18n("button.no"));
UIManager.put("OptionPane.okButtonText", C.i18n("button.ok"));
UIManager.put("OptionPane.yesButtonText", C.i18n("button.yes"));
}
}

View File

@@ -46,7 +46,6 @@ import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import org.jackhuang.hmcl.util.C;
import org.jackhuang.hmcl.api.HMCLog;
import org.jackhuang.hmcl.util.MessageBox;
import org.jackhuang.hmcl.util.StrUtils;
import org.jackhuang.hmcl.util.Utils;
import org.jackhuang.hmcl.api.func.NonFunction;

View File

@@ -160,6 +160,8 @@ ui.button.test=Test
ui.button.preview=Preview
button.cancel=Cancel
button.ok=OK
button.yes=Yes
button.no=No
ui.label.version=Version
ui.label.password=Password

View File

@@ -160,6 +160,8 @@ ui.button.test=Test
ui.button.preview=Preview
button.cancel=Cancel
button.ok=OK
button.yes=Yes
button.no=No
ui.label.version=Version
ui.label.password=Password

View File

@@ -160,6 +160,8 @@ ui.button.test=Тест
ui.button.preview=Показать
button.cancel=Отменить
button.ok=OK
button.yes=да
button.no=Неа
ui.label.version=Версия
ui.label.password=Пароль

View File

@@ -160,6 +160,8 @@ ui.button.test=\u0422\u0435\u0441\u0442
ui.button.preview=\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c
button.cancel=\u041e\u0442\u043c\u0435\u043d\u0438\u0442\u044c
button.ok=OK
button.yes=\u0434\u0430
button.no=\u041d\u0435\u0430
ui.label.version=\u0412\u0435\u0440\u0441\u0438\u044f
ui.label.password=\u041f\u0430\u0440\u043e\u043b\u044c

View File

@@ -158,6 +158,8 @@ ui.button.test=Test
ui.button.preview=Xem trước
button.cancel=Thoát
button.ok=OK
button.yes=Yes
button.no=No
ui.label.version=Phiên bản
ui.label.password=Mật khẩu

View File

@@ -158,6 +158,8 @@ ui.button.test=Test
ui.button.preview=Xem tr\u01b0\u1edbc
button.cancel=Tho\u00e1t
button.ok=OK
button.yes=Yes
button.no=No
ui.label.version=Phi\u00ean b\u1ea3n
ui.label.password=M\u1eadt kh\u1ea9u

View File

@@ -160,6 +160,8 @@ ui.button.test=測試
ui.button.preview=預覽
button.cancel=取消
button.ok=確定
button.yes=是
button.no=不
ui.label.version=版本
ui.label.password=密碼

View File

@@ -160,6 +160,8 @@ ui.button.test=\u6e2c\u8a66
ui.button.preview=\u9810\u89bd
button.cancel=\u53d6\u6d88
button.ok=\u78ba\u5b9a
button.yes=\u662f
button.no=\u4e0d
ui.label.version=\u7248\u672c
ui.label.password=\u5bc6\u78bc

View File

@@ -160,6 +160,8 @@ ui.button.test=测试
ui.button.preview=预览
button.cancel=取消
button.ok=确定
button.yes=是
button.no=不
ui.label.version=版本
ui.label.password=密码

View File

@@ -160,6 +160,8 @@ ui.button.test=\u6d4b\u8bd5
ui.button.preview=\u9884\u89c8
button.cancel=\u53d6\u6d88
button.ok=\u786e\u5b9a
button.yes=\u662f
button.no=\u4e0d
ui.label.version=\u7248\u672c
ui.label.password=\u5bc6\u7801