- Timestamp:
- 2015-02-21T15:27:40+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r8067 r8091 28 28 import org.openstreetmap.josm.tools.CheckParameterUtil; 29 29 import org.openstreetmap.josm.tools.ImageProvider; 30 import org.openstreetmap.josm.tools.LanguageInfo; 30 31 31 32 /** … … 152 153 /** name of the imagery entry (gets translated by josm usually) */ 153 154 private String name; 154 /** original name of the imagery entry in case of translation call */155 /** original name of the imagery entry in case of translation call, for multiple languages English when possible */ 155 156 private String origName; 157 /** (original) language of the translated name entry */ 158 private String langName; 156 159 /** id for this imagery entry, optional at the moment */ 157 160 private String id; … … 166 169 private ImageryBounds bounds = null; 167 170 private List<String> serverProjections; 171 /** description of the imagery entry, should contain notes what type of data it is */ 168 172 private String description; 173 /** language of the description entry, "" for tr() result */ 174 private String langDescription; 169 175 private String attributionText; 170 176 private String attributionLinkURL; … … 686 692 687 693 /** 688 * Sets the entry name and translates it. 694 * Sets the entry name and handle translation. 695 * @param name The used language 689 696 * @param name The entry name 690 * @since 6968 691 */ 692 public void setTranslatedName(String name) { 693 this.name = tr(name); 694 this.origName = name; 697 * @since 8091 698 */ 699 public void setName(String language, String name) { 700 boolean isdefault = LanguageInfo.getJOSMLocaleCode(null).equals(language); 701 if(LanguageInfo.isBetterLanguage(langName, language)) { 702 this.name = isdefault ? tr(name) : name; 703 this.langName = language; 704 } 705 if(origName == null || isdefault) { 706 this.origName = name; 707 } 695 708 } 696 709 … … 791 804 /** 792 805 * Sets the description text when existing. 806 * @param name The used language 793 807 * @param description the imagery description text 794 * @since 8065 795 */ 796 public void setDescription(String description) { 797 this.description = description; 808 * @since 8091 809 */ 810 public void setDescription(String language, String description) { 811 boolean isdefault = LanguageInfo.getJOSMLocaleCode(null).equals(language); 812 if(LanguageInfo.isBetterLanguage(langDescription, language)) { 813 this.description = isdefault ? tr(description) : description; 814 this.langDescription = language; 815 } 798 816 } 799 817 -
trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java
r8065 r8091 20 20 import org.openstreetmap.josm.io.CachedFile; 21 21 import org.openstreetmap.josm.io.UTFInputStreamReader; 22 import org.openstreetmap.josm.tools.LanguageInfo; 22 23 import org.xml.sax.Attributes; 23 24 import org.xml.sax.InputSource; … … 82 83 ImageryBounds bounds; 83 84 Shape shape; 85 // language of last element, does only work for simple ENTRY_ATTRIBUTE's 86 String lang; 84 87 List<String> projections; 85 88 … … 133 136 }).contains(qName)) { 134 137 newState = State.ENTRY_ATTRIBUTE; 138 lang = atts.getValue("lang"); 135 139 } else if ("bounds".equals(qName)) { 136 140 try { … … 207 211 switch(qName) { 208 212 case "name": 209 /* TODO: don't ignore lang attribute */ 210 entry.setTranslatedName(accumulator.toString()); 213 entry.setName(lang == null ? LanguageInfo.getJOSMLocaleCode(null) : lang, accumulator.toString()); 211 214 break; 212 215 case "description": 213 /* TODO: don't ignore lang attribute */ 214 entry.setDescription(accumulator.toString()); 216 entry.setDescription(lang, accumulator.toString()); 215 217 break; 216 218 case "id": -
trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java
r7509 r8091 123 123 } 124 124 125 /** 126 * Check if a new language is better than a previous existing. Can be used in classes where 127 * multiple user supplied language marked strings appear and the best one is searched. Following 128 * priorities: current language, english, any other 129 * 130 * @param oldLanguage the language code of the existing string 131 * @param newLanguage the language code of the new string 132 * @return true if new one is better 133 * @since 8091 134 */ 135 public static boolean isBetterLanguage(String oldLanguage, String newLanguage) { 136 if (oldLanguage == null) 137 return true; 138 String want = getJOSMLocaleCode(); 139 return want.equals(newLanguage) || (!want.equals(oldLanguage) && newLanguage.startsWith("en")); 140 } 141 142 /** 143 * Replies the language prefix for use in XML elements (with a dot appended). 144 * 145 * @return the XML language prefix 146 * @see #getJOSMLocaleCode() 147 */ 125 148 public static String getLanguageCodeXML() { 126 149 return getJOSMLocaleCode()+"."; 127 150 } 128 151 152 /** 153 * Replies the language prefix for use in manifests (with an underscore appended). 154 * 155 * @return the manifest language prefix 156 * @see #getJOSMLocaleCode() 157 */ 129 158 public static String getLanguageCodeManifest() { 130 159 return getJOSMLocaleCode()+"_";
Note:
See TracChangeset
for help on using the changeset viewer.