Changeset 15501 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-11-03T16:31:40+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java
r14185 r15501 10 10 import java.awt.Font; 11 11 import java.util.Collection; 12 import java.util.Locale;13 12 import java.util.Map; 14 13 import java.util.Objects; 15 14 import java.util.Optional; 16 15 import java.util.concurrent.CopyOnWriteArrayList; 17 import java.util.regex.Matcher;18 import java.util.regex.Pattern;19 16 20 17 import javax.swing.JLabel; … … 28 25 import org.openstreetmap.josm.data.preferences.CachingProperty; 29 26 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 27 import org.openstreetmap.josm.tools.I18n; 28 import org.openstreetmap.josm.tools.Pair; 30 29 31 30 /** … … 43 42 private static final CachingProperty<Boolean> DISCARDABLE 44 43 = new BooleanProperty("display.discardable-keys", false).cached(); 45 46 // Matches ISO-639 two and three letters language codes47 private static final Pattern LANGUAGE_NAMES = Pattern.compile("name:(\\p{Lower}{2,3})");48 44 49 45 static { … … 118 114 boolean knownNameKey = false; 119 115 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 knownNameKey = !code.equals(label); 116 Pair<String, Boolean> label = I18n.getLocalizedLanguageName(str); 117 if (label != null) { 118 knownNameKey = label.b; 125 119 if (knownNameKey) { 126 120 str = new StringBuilder("<html><body>").append(str) 127 .append(" <i><").append(label ).append("></i></body></html>").toString();121 .append(" <i><").append(label.a).append("></i></body></html>").toString(); 128 122 } 129 123 } -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r15494 r15501 19 19 import java.util.Locale; 20 20 import java.util.Map; 21 import java.util.regex.Matcher; 22 import java.util.regex.Pattern; 21 23 import java.util.zip.ZipEntry; 22 24 import java.util.zip.ZipFile; … … 140 142 languages.put("zh_TW", PluralMode.MODE_NONE); 141 143 } 144 145 private static final String HIRAGANA = "hira"; 146 private static final String KATAKANA = "kana"; 147 private static final String LATIN = "latn"; 148 private static final String PINYIN = "pinyin"; 149 private static final String ROMAJI = "rm"; 150 151 // Matches ISO-639 two and three letters language codes + scripts 152 private static final Pattern LANGUAGE_NAMES = Pattern.compile( 153 "name:(\\p{Lower}{2,3})(?:[-_](?i:(" + String.join("|", HIRAGANA, KATAKANA, LATIN, PINYIN, ROMAJI) + ")))?"); 142 154 143 155 private static String format(String text, Object... objects) { … … 668 680 return originalLocale; 669 681 } 682 683 /** 684 * Returns the localized name of the given script. Only scripts used in the OSM database are known. 685 * @param script Writing system 686 * @return the localized name of the given script, or null 687 * @since 15501 688 */ 689 public static String getLocalizedScript(String script) { 690 if (script != null) { 691 switch (script.toLowerCase(Locale.ENGLISH)) { 692 case HIRAGANA: 693 return tr("Hiragana"); 694 case KATAKANA: 695 return tr("Katakana"); 696 case LATIN: 697 return tr("Latin"); 698 case PINYIN: 699 return tr("Pinyin"); 700 case ROMAJI: 701 return tr("Rōmaji"); 702 default: 703 Logging.warn("Unsupported script: " + script); 704 } 705 } 706 return null; 707 } 708 709 /** 710 * Returns the localized name of the given language and optional script. 711 * @param language Language 712 * @return the pair of localized name + known state of the given language, or null 713 * @since 15501 714 */ 715 public static Pair<String, Boolean> getLocalizedLanguageName(String language) { 716 Matcher m = LANGUAGE_NAMES.matcher(language); 717 if (m.matches()) { 718 String code = m.group(1); 719 String label = new Locale(code).getDisplayLanguage(); 720 boolean knownNameKey = !code.equals(label); 721 String script = getLocalizedScript(m.group(2)); 722 if (script != null) { 723 label += " (" + script + ")"; 724 } 725 return new Pair<>(label, knownNameKey); 726 } 727 return null; 728 } 670 729 }
Note:
See TracChangeset
for help on using the changeset viewer.