- Timestamp:
- 2015-04-27T21:03:55+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r7783 r8283 18 18 import java.util.concurrent.atomic.AtomicLong; 19 19 20 import org.openstreetmap.josm.tools.LanguageInfo; 20 21 import org.openstreetmap.josm.tools.Utils; 21 22 … … 694 695 695 696 /** 696 * Replies the a localized name for this primitive given by the value of the tags (in this order) 697 * <ul> 698 * <li>name:lang_COUNTRY_Variant of the current locale</li> 699 * <li>name:lang_COUNTRY of the current locale</li> 700 * <li>name:lang of the current locale</li> 701 * <li>name of the current locale</li> 702 * </ul> 703 * 704 * null, if no such tag exists 705 * 706 * @return the name of this primitive 697 * Replies a localized name for this primitive given by the value of the name tags 698 * accessed from very specific (language variant) to more generic (default name). 699 * 700 * @see LanguageInfo#getLanguageCodes() 701 * @return the name of this primitive, <code>null</code> if no name exists 707 702 */ 708 703 @Override 709 704 public String getLocalName() { 710 final Locale locale = Locale.getDefault(); 711 String key = "name:" + locale.toString(); 712 String val = get(key); 713 if (val != null) 714 return val; 715 716 final String language = locale.getLanguage(); 717 key = "name:" + language + "_" + locale.getCountry(); 718 val = get(key); 719 if (val != null) 720 return val; 721 722 key = "name:" + language; 723 val = get(key); 724 if (val != null) 725 return val; 705 for(String s : LanguageInfo.getLanguageCodes(null)) { 706 String val = get("name:" + s); 707 if (val != null) 708 return val; 709 } 726 710 727 711 return getName(); -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r8282 r8283 83 83 private static volatile PluralMode pluralMode = PluralMode.MODE_NOTONE; /* english default */ 84 84 private static volatile String loadedCode = "en"; 85 /** store the original system locale for further use */ 86 public static final Locale SystemLocale = Locale.getDefault(); 85 87 86 88 /* Localization keys for file chooser (and color chooser). */ … … 494 496 URL tr = getTranslationFile(l); 495 497 if (tr == null || !languages.containsKey(l)) { 496 int i = l.indexOf('_'); 497 if (i > 0) { 498 l = l.substring(0, i); 499 } 500 tr = getTranslationFile(l); 501 if (tr == null || !languages.containsKey(l)) 502 return false; 498 return false; 503 499 } 504 500 try ( … … 738 734 739 735 /** 740 * Setup special font for Khmer script, as the default Java font do not display these characters.736 * Setup special font for Khmer script, as the default Java fonts do not display these characters. 741 737 * 742 * @since 828 1738 * @since 8282 743 739 */ 744 740 public static void setupLanguageFonts() { -
trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java
r8241 r8283 4 4 import static org.openstreetmap.josm.tools.I18n.trc; 5 5 6 import java.util.Collection; 7 import java.util.LinkedList; 6 8 import java.util.Locale; 7 9 … … 86 88 * to identify the locale of a localized resource, but in some cases it may use the 87 89 * programmatic name for locales, as replied by {@link Locale#toString()}. 90 * 91 * For unknown country codes and variants this functuion already does fallback to 92 * internally known translations. 88 93 * 89 94 * @param locale the locale. Replies "en" if null. … … 92 97 public static String getJOSMLocaleCode(Locale locale) { 93 98 if (locale == null) return "en"; 94 String full = locale.toString(); 95 if ("iw_IL".equals(full)) 96 return "he"; 97 else if ("in".equals(full)) 98 return "id"; 99 else if ("ca__valencia".equals(full)) 100 return "ca@valencia"; 101 else if (I18n.hasCode(full)) // catch all non-single codes 102 return full; 103 104 // return single code 99 for(String full : getLanguageCodes(locale)) { 100 if ("iw_IL".equals(full)) 101 return "he"; 102 else if ("in".equals(full)) 103 return "id"; 104 else if (I18n.hasCode(full)) // catch all non-single codes 105 return full; 106 } 107 108 // return single code as fallback 105 109 return locale.getLanguage(); 106 110 } … … 154 158 */ 155 159 public static Locale getLocale(String localeName) { 156 localeName = getJavaLocaleCode(localeName);157 i f ("ca__valencia".equals(localeName)) {158 return new Locale("ca", "", "valencia");159 }160 int country = localeName.indexOf("_"); 161 int variant = localeName.indexOf("@"); 162 if (variant < 0 && country >= 0) 163 variant = localeName.indexOf("_", country+1); 160 164 Locale l; 161 int i = localeName.indexOf('_'); 162 if (i > 0) { 163 l = new Locale(localeName.substring(0, i), localeName.substring(i + 1)); 165 if (variant > 0 && country > 0) { 166 l = new Locale(localeName.substring(0, country), localeName.substring(country+1, variant), localeName.substring(variant + 1)); 167 } else if (variant > 0) { 168 l = new Locale(localeName.substring(0, variant), "", localeName.substring(variant + 1)); 169 } else if (country > 0) { 170 l = new Locale(localeName.substring(0, country), localeName.substring(country + 1)); 164 171 } else { 165 172 l = new Locale(localeName); … … 208 215 return code+"_"; 209 216 } 217 218 /** 219 * Replies a list of language codes for local names. Prefixes range from very specific 220 * to more generic. 221 * <ul> 222 * <li>lang_COUNTRY@variant of the current locale</li> 223 * <li>lang@variant of the current locale</li> 224 * <li>lang_COUNTRY of the current locale</li> 225 * <li>lang of the current locale</li> 226 * </ul> 227 * 228 * @param locale the locale to use, <code>null</code> for default locale 229 * @since 8283 230 * @return list of codes 231 */ 232 public static Collection<String> getLanguageCodes(Locale l) { 233 Collection<String> list = new LinkedList<String>(); 234 if(l == null) 235 l = Locale.getDefault(); 236 String lang = l.getLanguage(); 237 String c = l.getCountry(); 238 String v = l.getVariant(); 239 if(c.isEmpty()) 240 c = null; 241 if(v != null && !v.isEmpty()) { 242 if(c != null) 243 list.add(lang+"_"+c+"@"+v); 244 list.add(lang+"@"+v); 245 } 246 if(c != null) 247 list.add(lang+"_"+c); 248 list.add(lang); 249 return list; 250 } 210 251 }
Note:
See TracChangeset
for help on using the changeset viewer.