]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/I18nManager.java
Version 16, February 2014
[GpsPrune.git] / tim / prune / I18nManager.java
index b9ce3cc0e59e07888f7bd2cbfef679dcc065fea8..24a4fde41ab2a73288dcdb7975c9c7791f54cf47 100644 (file)
@@ -86,22 +86,19 @@ public abstract class I18nManager
         */
        public static String getText(String inKey)
        {
-               String value = null;
                // look in external props file if available
                if (ExternalPropsFile != null)
                {
-                       value = ExternalPropsFile.getProperty(inKey);
-                       if (value != null && !value.equals(""))
-                               return value;
+                       String extText = ExternalPropsFile.getProperty(inKey);
+                       if (extText != null) return extText;
                }
                // look in extra texts if available
                if (LocalTexts != null)
                {
                        try
                        {
-                               value = LocalTexts.getString(inKey);
-                               if (value != null && !value.equals(""))
-                                       return value;
+                               String localText = LocalTexts.getString(inKey);
+                               if (localText != null) return localText;
                        }
                        catch (MissingResourceException mre) {}
                }
@@ -110,13 +107,30 @@ public abstract class I18nManager
                {
                        try
                        {
-                               value = EnglishTexts.getString(inKey);
-                               if (value != null && !value.equals(""))
-                                       return value;
+                               String engText = EnglishTexts.getString(inKey);
+                               if (engText != null) return engText;
                        }
                        catch (MissingResourceException mre) {}
                }
                // return the key itself
                return inKey;
        }
+
+       /**
+        * Lookup the given key and return the associated text, formatting with the number
+        * @param inKey key to lookup (text should contain a %d)
+        * @param inNumber number to substitute into the %d
+        * @return associated text, or the key if not found
+        */
+       public static String getTextWithNumber(String inKey, int inNumber)
+       {
+               String localText = getText(inKey);
+               try
+               {
+                       localText = String.format(localText, inNumber);
+               }
+               catch (Exception e)
+               {} // printf formatting didn't work, maybe the placeholders are wrong?
+               return localText;
+       }
 }