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

Diff of /trunk/src/skrueger/i8n/Translation.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 186 by alfonx, Fri Jul 3 14:40:10 2009 UTC
# Line 8  import java.util.List; Line 8  import java.util.List;
8  import java.util.Locale;  import java.util.Locale;
9    
10  import javax.swing.JComponent;  import javax.swing.JComponent;
11    import javax.swing.JTable;
12    
13  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
14    
# Line 57  public class Translation extends HashMap Line 58  public class Translation extends HashMap
58          /**          /**
59           * Set up the {@link Translation}-system to use language. If a change is           * Set up the {@link Translation}-system to use language. If a change is
60           * performed, events are fired to listeners. Nothing is done if the new           * performed, events are fired to listeners. Nothing is done if the new
61           * language equals the old language.           * language equals the old language. The system's default locale is changed.
62           *           *
63           * @param newLang           * @param newLang
64           *            The ISO Code of the new active language           *            The ISO Code of the new active language
65           */           */
66          public static void setActiveLang(String newLang) {          public static void setActiveLang(String newLang) {
67                    setActiveLang(newLang, true);
68            }
69    
70            /**
71             * Set up the {@link Translation}-system to use language. If a change is
72             * performed, events are fired to listeners. Nothing is done if the new
73             * language equals the old language.
74             *
75             * @param newLang
76             *            The ISO Code of the new active language
77             *
78             * @param setDefaultLocale
79             *            Shall the system's default locale be changed?
80             */
81            public static void setActiveLang(String newLang, boolean setDefaultLocale) {
82                  if (getActiveLang().equals(newLang)) {                  if (getActiveLang().equals(newLang)) {
83                          return;                          return;
84                  }                  }
# Line 73  public class Translation extends HashMap Line 89  public class Translation extends HashMap
89                  }                  }
90    
91                  Locale newLocale = new Locale(newLang);                  Locale newLocale = new Locale(newLang);
92                  Locale.setDefault(newLocale);                  if (setDefaultLocale)
93                            Locale.setDefault(newLocale);
94    
95                  /**                  /**
96                   * Setting default locale for Swing JComponents to work around bug                   * Setting default locale for Swing JComponents to work around bug
# Line 89  public class Translation extends HashMap Line 106  public class Translation extends HashMap
106          }          }
107    
108          /**          /**
109           * Initializes a new {@link Translation} with a default translation. Other           * Initializes a new {@link Translation} with a default translation if a
110           * translations may be added later.           * simple text is passed. If a "oneLine" text is parsed, it is interpreted.
111             * Other translations may be added later - this is a HashMap<br/>
112           *           *
113           * @param defaultTranslation           * @param defaultTranslation
114           *           *
          * @deprecated SK: The concept of the default translation doesn't seem so  
          *             nice to me anymore.. I would prefer the default translation  
          *             to be set for all valid languages.  
          *  
115           * @see public Translation(List<String> languages, String           * @see public Translation(List<String> languages, String
116           *      defaultTranslation) {           *      defaultTranslation) {
117           *           *
118           */           */
119          public Translation(String defaultTranslation) {          public Translation(String defaultTranslation) {
120                  put(DEFAULT_KEY, defaultTranslation);  
121                    fromOneLine(defaultTranslation);
122    
123          }          }
124    
125          /**          /**
# Line 128  public class Translation extends HashMap Line 144  public class Translation extends HashMap
144           * Sometimes Translations are optional, like for keywords.           * Sometimes Translations are optional, like for keywords.
145           */           */
146          public Translation() {          public Translation() {
                 super();  
147          }          }
148    
149          /**          /**
# Line 145  public class Translation extends HashMap Line 160  public class Translation extends HashMap
160          public void fromOneLine(final String oneLineCoded) {          public void fromOneLine(final String oneLineCoded) {
161                  clear();                  clear();
162                  if ((oneLineCoded == null) || (oneLineCoded.equals(""))) {                  if ((oneLineCoded == null) || (oneLineCoded.equals(""))) {
163                          put(DEFAULT_KEY, NO_TRANSLATION);                          put(DEFAULT_KEY, "");
164                          return;                          return;
165                  }                  }
166    
# Line 175  public class Translation extends HashMap Line 190  public class Translation extends HashMap
190           * @author Stefan Alfons Krüger           * @author Stefan Alfons Krüger
191           */           */
192          public String toOneLine() {          public String toOneLine() {
193                  StringBuffer oneLine = new StringBuffer();                  return I8NUtil.toOneLine(this);
                 for (String key : keySet()) {  
                         oneLine.append(key + "{" + get(key) + "}");  
                 }  
                 return oneLine.toString();  
194          }          }
195    
196          /**          /**
# Line 207  public class Translation extends HashMap Line 218  public class Translation extends HashMap
218                  // MS:                  // MS:
219                  else {                  else {
220                          if (get(DEFAULT_KEY) != null) {                          if (get(DEFAULT_KEY) != null) {
221                                  // log.debug("default lng returned, cuz the translation to "+activeLang+" was not found. Schmeiss raus martin, wenn du das mit der default trans geklärt hast.");                                  // log.debug("default lang returned, cuz the translation to "+activeLang+" was not found. Schmeiss raus martin, wenn du das mit der default trans geklärt hast.");
222                                  return get(DEFAULT_KEY);                                  return get(DEFAULT_KEY);
223                          }                          }
224    
# Line 263  public class Translation extends HashMap Line 274  public class Translation extends HashMap
274                  }                  }
275          }          }
276    
   
277  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26