/[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 185 by alfonx, Fri Jul 3 14:36:08 2009 UTC revision 243 by alfonx, Tue Jul 28 12:40:08 2009 UTC
# Line 58  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 74  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 84  public class Translation extends HashMap Line 100  public class Translation extends HashMap
100    
101                  Translation.activeLang = newLang;                  Translation.activeLang = newLang;
102    
103                  fireChangeEvents();                  fireLocaleChangeEvents();
104    
105                  log.info("skrueger.i8n.Translation switched ActiveLang to " + newLang);                  log.info("skrueger.i8n.Translation switched ActiveLang to " + newLang);
106          }          }
107    
108          /**          /**
109           * Initializes a new {@link Translation} with a default translation if a           * Initializes a new {@link Translation} with a default translation if a
110           * simple text is passed. If a "oneLine" text is parsed, it is           * simple text is passed. If a "oneLine" text is parsed, it is interpreted.
111           * interpreted. Other translations may be added later - this is a HashMap<br/>           * Other translations may be added later - this is a HashMap<br/>
112           *           *
113           * @param defaultTranslation           * @param defaultTranslation
114           *           *
# Line 213  public class Translation extends HashMap Line 229  public class Translation extends HashMap
229                                                  return s;                                                  return s;
230                                  }                                  }
231                  }                  }
232                  log.warn("No translation found!");  //              log.warn("No translation found!");
233                  return NO_TRANSLATION;                  return NO_TRANSLATION;
234          }          }
235    
# Line 248  public class Translation extends HashMap Line 264  public class Translation extends HashMap
264           * Informs all registered {@link PropertyChangeListener}s about a change of           * Informs all registered {@link PropertyChangeListener}s about a change of
265           * the the {@link Locale}.           * the the {@link Locale}.
266           */           */
267          public static void fireChangeEvents() {          public static void fireLocaleChangeEvents() {
268                  PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(                  PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(
269                                  new ArrayList<String>(), "fakeSource"), LOCALECHANGE_PROPERTY,                                  new ArrayList<String>(), "fakeSource"), LOCALECHANGE_PROPERTY,
270                                  null, getActiveLang());                                  null, getActiveLang());

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26