Changeset 14174 in josm for trunk/src/org


Ignore:
Timestamp:
2018-08-21T02:00:41+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16107 - display languages in human form for name:xx keys

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java

    r13809 r14174  
    1010import java.awt.Font;
    1111import java.util.Collection;
     12import java.util.Locale;
    1213import java.util.Map;
    1314import java.util.Objects;
    1415import java.util.Optional;
    1516import java.util.concurrent.CopyOnWriteArrayList;
     17import java.util.regex.Matcher;
     18import java.util.regex.Pattern;
    1619
    1720import javax.swing.JLabel;
     
    4043    private static final CachingProperty<Boolean> DISCARDABLE
    4144            = new BooleanProperty("display.discardable-keys", false).cached();
     45
     46    // Matches ISO-639 two and three letters language codes
     47    private static final Pattern LANGUAGE_NAMES = Pattern.compile("name:(\\p{Lower}{2,3})");
    4248
    4349    static {
     
    111117                }
    112118            }
     119            if (column == 0 && str != null) {
     120                Matcher m = LANGUAGE_NAMES.matcher(str);
     121                if (m.matches()) {
     122                    String code = m.group(1);
     123                    String label = new Locale(code).getDisplayLanguage();
     124                    if (!code.equals(label)) {
     125                        str = new StringBuilder(str).append(" <").append(label).append('>').toString();
     126                    }
     127                }
     128            }
    113129            ((JLabel) c).putClientProperty("html.disable", Boolean.TRUE); // Fix #8730
    114130            ((JLabel) c).setText(str);
Note: See TracChangeset for help on using the changeset viewer.