Changeset 8232 in josm


Ignore:
Timestamp:
2015-04-19T13:12:20+02:00 (9 years ago)
Author:
stoecker
Message:

see #11148 - move language stuff to the correct place instead of spreading it in the code

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/LanguagePreference.java

    r8207 r8232  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.tools.I18n.trc;
    65
    76import java.awt.Component;
     
    2827import org.openstreetmap.josm.tools.GBC;
    2928import org.openstreetmap.josm.tools.I18n;
     29import org.openstreetmap.josm.tools.LanguageInfo;
    3030
    3131/**
     
    7373        else
    7474            return Main.pref.put("language",
    75                     ((Locale)langCombo.getSelectedItem()).toString());
     75                    LanguageInfo.getJOSMLocaleCode((Locale)langCombo.getSelectedItem()));
    7676    }
    7777
     
    8787            setSelectedItem(null);
    8888            if (language != null) {
     89                language = LanguageInfo.getJavaLocaleCode(language);
    8990                for (Locale locale: data) {
    9091                    if (locale == null) {
     
    121122                    l == null
    122123                            ? tr("Default (Auto determined)")
    123                             : "ca__valencia".equals(l.toString())
    124                             ? trc("language", "Valencian")
    125                             : l.getDisplayName(l),
     124                            : LanguageInfo.getDisplayName(l),
    126125                    index, isSelected, cellHasFocus);
    127126        }
  • trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java

    r8227 r8232  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
     3
     4import static org.openstreetmap.josm.tools.I18n.trc;
    35
    46import java.util.Locale;
     
    107109     * Replies the locale code used by Java for a given locale.
    108110     *
     111     * @param locale the locale. Replies "en" if null.
     112     * @return the Java code for the given locale
     113     * @since 8232
     114     */
     115    public static String getJavaLocaleCode(String localeName) {
     116        if (localeName == null) return "en";
     117        if ("ca@valencia".equals(localeName)) {
     118            localeName = "ca__valencia";
     119        } else if ("he".equals(localeName)) {
     120            localeName = "iw_IL";
     121        } else if ("id".equals(localeName)) {
     122            localeName = "in";
     123        }
     124        return localeName;
     125    }
     126
     127    /**
     128     * Replies the display string used by JOSM for a given locale.
     129     *
     130     * In most cases returns text replied by {@link Locale#getDisplayName()}, for some
     131     * locales an override is used (i.e. when unsupported by Java).
     132     *
     133     * @param locale the locale. Replies "en" if null.
     134     * @return the display string for the given locale
     135     * @since 8232
     136     */
     137    public static String getDisplayName(Locale locale) {
     138        String full = locale.toString();
     139        if ("ca__valencia".equals(full))
     140            return trc("language", "Valencian");
     141
     142        return locale.getDisplayName();
     143    }
     144
     145    /**
     146     * Replies the locale code used by Java for a given locale.
     147     *
    109148     * In most cases JOSM and Java uses the same codes, but for some exceptions this is needed.
    110149     *
     
    113152     */
    114153    public static Locale getLocale(String localeName) {
    115         if ("ca@valencia".equals(localeName)) {
     154        localeName = getJavaLocaleCode(localeName);
     155        if ("ca__valencia".equals(localeName)) {
    116156            return new Locale("ca", "", "valencia");
    117         }
    118         if ("he".equals(localeName)) {
    119             localeName = "iw_IL";
    120         }
    121         else if ("id".equals(localeName)) {
    122             localeName = "in";
    123157        }
    124158        Locale l;
Note: See TracChangeset for help on using the changeset viewer.