/[schmitzm]/trunk/src/skrueger/i8n/I8NUtil.java
ViewVC logotype

Diff of /trunk/src/skrueger/i8n/I8NUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 41 by alfonx, Mon Apr 6 19:54:46 2009 UTC revision 185 by alfonx, Fri Jul 3 14:36:08 2009 UTC
# Line 4  import java.util.Locale; Line 4  import java.util.Locale;
4  import java.util.Set;  import java.util.Set;
5  import java.util.TreeSet;  import java.util.TreeSet;
6    
7    import org.apache.log4j.Logger;
8    
9  public class I8NUtil {  public class I8NUtil {
10            static final Logger LOGGER = Logger.getLogger(I8NUtil.class);
11    
12          private static Set<String> languageCodes = new TreeSet<String>();          private static Set<String> languageCodes = new TreeSet<String>();
13          static {          static {
# Line 16  public class I8NUtil { Line 19  public class I8NUtil {
19                  // }                  // }
20          }          }
21    
22          //                /**
23          // /**           * Creates a {@link Translation}<br/>
24          // * @Returns an ImageIcon for a given ISO code or null.           * <p>
25          // * @param code ISO Country Code           * <li>If <code>oneLineCoded</code> is empty or null, NO TRANSLATION is set.
26          // */           * <li>If format can't be recognized, the {@link String} is interpreted as
27          // public static ImageIcon getFlagIcon(String code) {           * the translation in the <code>{@value #DEFAULT_KEY}</code> language
28          //                         *
29          // String ressourcename = "resource/flags/" + code.toUpperCase() + ".gif";           * @author Stefan Alfons Krüger
30          //                         */
31          // URL resourceURL = TranslationEditJPanel.class.getResource(ressourcename);          public static Translation createFromOneLIne(final String oneLineCoded) {
32          //                                Translation result = new Translation();
33          // if (resourceURL != null)                  result.fromOneLine(oneLineCoded);
34          // return new ImageIcon( resourceURL);                  return result;
35          //                        }
36          // return new ImageIcon();  
37          // }          /**
38          //                 * Returns the Translation to a String of the Format: "de{Baum}en{tree}" <br/>
39          // /**           *
40          // * @Returns an {@link ImageIcon} flag for the language setup as           *
41          // Translation language           * @author Stefan Alfons Krüger
42          // */           */
43          // public static ImageIcon getFlagIcon() {          public static String toOneLine(Translation source) {
44          // return getFlagIcon( Translation.getActiveLang() );                  StringBuffer oneLine = new StringBuffer();
45          // }                  for (String key : source.keySet()) {
46                            oneLine.append(key + "{" + source.get(key) + "}");
47                    }
48                    return oneLine.toString();
49            }
50    
51          /**          /**
52           * @author Stefan Alfons Krüger           * @author Stefan Alfons Krüger
# Line 66  public class I8NUtil { Line 73  public class I8NUtil {
73           */           */
74          public static Locale getLocaleFor(String code) {          public static Locale getLocaleFor(String code) {
75                  for (Locale l : Locale.getAvailableLocales()) {                  for (Locale l : Locale.getAvailableLocales()) {
76  //                      System.out.println(l.getLanguage()+" not = "+code);                          if (l.getLanguage().equals(code.toLowerCase())) {
                         if (l.getLanguage().toLowerCase().equals(code.toLowerCase())) {  
77                                  return l;                                  return l;
78                          }                          }
79                            // LOGGER.debug(l.getLanguage() + " not = " + code);
80                  }                  }
81                  return null;  
82                    LOGGER.error("Can't create a Locale for code " + code
83                                    + "! Returning the system default locale to avoid NPEs.");
84    
85                    return Locale.getDefault();
86            }
87    
88            /**
89             * A convenience method that checks if the {@link Translation} object
90             * contains a translation for the active language. A {@link String}
91             * containing only spaces will return <code>false</code>.
92             *
93             * @param trans
94             *            {@link Translation} to check.
95             */
96            public static boolean isEmpty(final Translation trans) {
97                    if (trans == null)
98                            return true;
99                    return isEmpty(trans.toString());
100            }
101    
102            /**
103             * A convenience method that checks if the {@link String} returned by from a
104             * {@link Translation} object contains a "valid" translation for the active
105             * language. A {@link String} containing only spaces or equals
106             * {@link Translation}.NO_TRANSLATION will return <code>false</code>.
107             *
108             * @param transString
109             *            {@link String} to check.
110             */
111            public static boolean isEmpty(final String transString) {
112                    if (transString == null)
113                            return true;
114                    if (transString.trim().isEmpty())
115                            return true;
116                    if (transString.equals(Translation.NO_TRANSLATION))
117                            return true;
118                    return false;
119          }          }
120  }  }

Legend:
Removed from v.41  
changed lines
  Added in v.185

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26