Changeset 1065 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2008-11-02T15:06:01+01:00 (15 years ago)
Author:
stoecker
Message:

language handling fixed

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r1062 r1065  
    404404        synchronized public Collection<String> getCollection(String key, Collection<String> def) {
    405405                String s = get(key);
    406                 if(s != null)
     406                if(s != null && s.length() != 0)
    407407                {
    408408                        /* handle old comma separated stuff - remove in future */
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r1059 r1065  
    173173                    localeName = (String)(args.get("language").toArray()[0]);
    174174               
    175                 //TODO: Check preferences for language
    176        
    177                 //If override then set new default locale - otherwise, override
    178         if (localeName != null) {
    179             Locale.setDefault(new Locale(localeName));
    180         }
    181        
     175                if (localeName == null) {
     176                        localeName = Main.pref.get("language", null);
     177                }
     178
     179                if (localeName != null) {
     180                        Locale l;
     181                        int i = localeName.indexOf('_');
     182                        if (i > 0) {
     183                                l = new Locale(localeName.substring(0, i), localeName.substring(i + 1));
     184                        } else {
     185                                l = new Locale(localeName);
     186                        }
     187                        Locale.setDefault(l);
     188                }
    182189        try {
    183190            i18n = I18nFactory.getI18n(MainApplication.class);
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java

    r1053 r1065  
    123123                // order is important!
    124124                settings.add(new LafPreference());
     125                settings.add(new LanguagePreference());
    125126                settings.add(new DrawingPreference());
    126127                settings.add(new ColorPreference());
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r1058 r1065  
    33
    44import java.text.MessageFormat;
     5import java.util.Arrays;
     6import java.util.Comparator;
     7import java.util.Locale;
     8import java.util.Vector;
    59
    610/**
     
    1014 */
    1115public class I18n {
     16
     17        /* Base name for translation data. Used for detecting available translations */
     18        private static final String TR_BASE = "org.openstreetmap.josm.i18n.Translation_";
     19
    1220        /**
    1321         * Set by MainApplication. Changes here later will probably mess up everything, because
     
    4351                return i18n.trn(text, pluralText, n);
    4452        }
     53
     54        /**
     55         * Get a list of all available JOSM Translations.
     56         * @return an array of locale objects.
     57         */
     58        public static final Locale[] getAvailableTranslations() {
     59                Vector<Locale> v = new Vector<Locale>();
     60                Locale[] l = Locale.getAvailableLocales();
     61                for (int i = 0; i < l.length; i++) {
     62                        String cn = TR_BASE + l[i];
     63                        try {
     64                                Class.forName(cn);
     65                                v.add(l[i]);
     66                        } catch (ClassNotFoundException e) {
     67                        }
     68                }
     69                l = new Locale[v.size()];
     70                l = v.toArray(l);
     71                Arrays.sort(l, new Comparator<Locale>() {
     72                        public int compare(Locale o1, Locale o2) {
     73                                return o1.toString().compareTo(o2.toString());
     74                        }
     75                });
     76                return l;
     77        }
    4578}
Note: See TracChangeset for help on using the changeset viewer.