From: BobHanson Date: Fri, 5 Jun 2020 15:22:33 +0000 (-0500) Subject: JAL-3446 new Locale("") moved to Platform for review. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=890d06e98f0ea0e6ef2b8415003447904fd2df61;p=jalview.git JAL-3446 new Locale("") moved to Platform for review. --- diff --git a/src/jalview/util/MessageManager.java b/src/jalview/util/MessageManager.java index 43b6c9e..2a07616 100644 --- a/src/jalview/util/MessageManager.java +++ b/src/jalview/util/MessageManager.java @@ -57,9 +57,7 @@ public class MessageManager // Locale.setDefault(loc); /* Getting messages for GV */ log.info("Getting messages for lang: " + loc); - if (Platform.isJS() && loc.getLanguage().equals("en")) - loc = new Locale(""); // meaning no language properties are available - rb = ResourceBundle.getBundle("lang.Messages", loc, Control.getControl(Control.FORMAT_PROPERTIES)); + rb = ResourceBundle.getBundle("lang.Messages", Platform.getLocaleOrNone(loc), Control.getControl(Control.FORMAT_PROPERTIES)); // if (log.isLoggable(Level.FINEST)) // { // // this might take a while, so we only do it if it will be shown @@ -95,7 +93,7 @@ public class MessageManager } catch (Exception e) { String msg = "I18N missing: " + loc + "\t" + key; - logWarning(key, msg); + logWarning(key, msg); } return value; } @@ -170,8 +168,8 @@ public class MessageManager } catch (Exception x) { String msg = "I18N missing key with root " + keyroot + ": " + loc + "\t" - + smkey; - logWarning(smkey, msg); + + smkey; + logWarning(smkey, msg); } return name; } @@ -184,10 +182,10 @@ public class MessageManager */ private static void logWarning(String key, String msg) { - if (!reportedMissing.contains(key)) - { + if (!reportedMissing.contains(key)) + { reportedMissing.add(key); - log.info(msg); - } + log.info(msg); + } } } diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index a47e2f8..8f8350f 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -37,6 +37,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.Date; +import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.logging.ConsoleHandler; @@ -938,4 +939,17 @@ public class Platform return id + (frameType == null ? "" : "-" + frameType); } + + /** + * Option to avoid unnecessary seeking of nonexistent resources in JavaScript. + * Works in Java as well. + * + * @param loc + * @return + */ + public static Locale getLocaleOrNone(Locale loc) + { + return (isJS && loc.getCountry() == "en" ? new Locale("") : loc); + } + }