/[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 39 by alfonx, Mon Apr 6 19:14:55 2009 UTC revision 140 by alfonx, Sun Jun 14 17:24:44 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    
         //        
         // /**  
         // * @Returns an ImageIcon for a given ISO code or null.  
         // * @param code ISO Country Code  
         // */  
         // public static ImageIcon getFlagIcon(String code) {  
         //                
         // String ressourcename = "resource/flags/" + code.toUpperCase() + ".gif";  
         //                
         // URL resourceURL = TranslationEditJPanel.class.getResource(ressourcename);  
         //                
         // if (resourceURL != null)  
         // return new ImageIcon( resourceURL);  
         //                
         // return new ImageIcon();  
         // }  
         //        
         // /**  
         // * @Returns an {@link ImageIcon} flag for the language setup as  
         // Translation language  
         // */  
         // public static ImageIcon getFlagIcon() {  
         // return getFlagIcon( Translation.getActiveLang() );  
         // }  
   
22          /**          /**
23           * @author Stefan Alfons Krüger           * @author Stefan Alfons Krüger
24           * @param code           * @param code
# Line 66  public class I8NUtil { Line 44  public class I8NUtil {
44           */           */
45          public static Locale getLocaleFor(String code) {          public static Locale getLocaleFor(String code) {
46                  for (Locale l : Locale.getAvailableLocales()) {                  for (Locale l : Locale.getAvailableLocales()) {
47                          System.out.println(l.getLanguage()+" not = "+code);                          if (l.getLanguage().equals(code.toLowerCase())) {
                         if (l.getLanguage().toLowerCase().equals(code.toLowerCase())) {  
48                                  return l;                                  return l;
49                          }                          }
50                            LOGGER.debug(l.getLanguage() + " not = " + code);
51                  }                  }
52                  return null;  
53                    LOGGER.error("Can't create a Locale for code " + code
54                                    + "! Returning the system default locale to avoid NPEs.");
55    
56                    return Locale.getDefault();
57            }
58    
59            /**
60             * A convenience method that checks if the {@link Translation} object
61             * contains a translation for the active language. A {@link String}
62             * containing only spaces will return <code>false</code>.
63             *
64             * @param trans
65             *            {@link Translation} to check.
66             */
67            public static boolean isEmpty(final Translation trans) {
68                    if (trans == null)
69                            return true;
70                    return isEmpty(trans.toString());
71            }
72    
73            /**
74             * A convenience method that checks if the {@link String} returned by from a
75             * {@link Translation} object contains a "valid" translation for the active
76             * language. A {@link String} containing only spaces or equals
77             * {@link Translation}.NO_TRANSLATION will return <code>false</code>.
78             *
79             * @param transString
80             *            {@link String} to check.
81             */
82            public static boolean isEmpty(final String transString) {
83                    if (transString == null)
84                            return true;
85                    if (transString.trim().isEmpty())
86                            return true;
87                    if (transString.equals(Translation.NO_TRANSLATION))
88                            return true;
89                    return false;
90          }          }
91  }  }

Legend:
Removed from v.39  
changed lines
  Added in v.140

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26