Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-06-03 17:19:26 +02:00
commit e5406df58e
5 changed files with 66 additions and 40 deletions

View file

@ -271,9 +271,9 @@ public class BinaryMapAddressReaderAdapter {
break; break;
case OsmandOdb.CityIndex.ATTRIBUTEVALUES_FIELD_NUMBER: case OsmandOdb.CityIndex.ATTRIBUTEVALUES_FIELD_NUMBER:
String nm = codedIS.readString(); String nm = codedIS.readString();
if(additionalTags != null && additionalTags.size() > 0) { if (additionalTags != null && additionalTags.size() > 0) {
String tg = additionalTags.pollFirst(); String tg = additionalTags.pollFirst();
if(tg.startsWith("name:")) { if (tg.startsWith("name:")) {
c.setName(tg.substring("name:".length()), nm); c.setName(tg.substring("name:".length()), nm);
} }
} }

View file

@ -131,8 +131,6 @@ public class Amenity extends MapObject {
public void setAdditionalInfo(String tag, String value) { public void setAdditionalInfo(String tag, String value) {
if ("name".equals(tag)) { if ("name".equals(tag)) {
setName(value); setName(value);
} else if ("name:en".equals(tag)) {
setEnName(value);
} else if (tag.startsWith("name:")) { } else if (tag.startsWith("name:")) {
setName(tag.substring("name:".length()), value); setName(tag.substring("name:".length()), value);
} else { } else {

View file

@ -22,6 +22,10 @@ public abstract class MapObject implements Comparable<MapObject> {
protected String name = null; protected String name = null;
protected String enName = null; protected String enName = null;
/**
* Looks like: {ru=Москва, dz=མོསིཀོ...} and does not contain values of OSM tags "name" and "name:en",
* see {@link name} and {@link enName} respectively.
*/
protected Map<String, String> names = null; protected Map<String, String> names = null;
protected LatLon location = null; protected LatLon location = null;
protected int fileOffset = 0; protected int fileOffset = 0;
@ -40,8 +44,8 @@ public abstract class MapObject implements Comparable<MapObject> {
} }
public String getName() { public String getName() {
if (this.name != null) { if (name != null) {
return this.name; return name;
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@ -51,11 +55,16 @@ public abstract class MapObject implements Comparable<MapObject> {
} }
public void setName(String lang, String name) { public void setName(String lang, String name) {
if (names == null) { if (Algorithms.isEmpty(lang)) {
names = new HashMap<String, String>(); setName(name);
} else if (lang.equals("en")) {
setEnName(name);
} else {
if (names == null) {
names = new HashMap<String, String>();
}
names.put(lang, name);
} }
names.put(lang, name);
} }
public Map<String, String> getNamesMap(boolean includeEn) { public Map<String, String> getNamesMap(boolean includeEn) {
@ -84,37 +93,45 @@ public abstract class MapObject implements Comparable<MapObject> {
return l; return l;
} }
public void copyNames(MapObject s) { public void copyNames(String otherName, String otherEnName, Map<String, String> otherNames, boolean overwrite) {
if (Algorithms.isEmpty(name)) { if (!Algorithms.isEmpty(otherName) && (overwrite || Algorithms.isEmpty(name))) {
name = s.name; name = otherName;
} }
if (Algorithms.isEmpty(enName)) { if (!Algorithms.isEmpty(otherEnName) && (overwrite || Algorithms.isEmpty(enName))) {
enName = s.enName; enName = otherEnName;
}
if (!Algorithms.isEmpty(otherNames)) {
if (otherNames.containsKey("name:en")) {
enName = otherNames.get("name:en");
} else if (otherNames.containsKey("en")) {
enName = otherNames.get("en");
}
for (Entry<String, String> e : otherNames.entrySet()) {
String key = e.getKey();
if (key.startsWith("name:")) {
key = key.substring("name:".length());
}
if (names == null) {
names = new HashMap<String, String>();
}
if (overwrite || Algorithms.isEmpty(names.get(key))) {
names.put(key, e.getValue());
}
}
} }
copyNames(s.names);
} }
public void copyNames(Map<String, String> snames) { public void copyNames(String otherName, String otherEnName, Map<String, String> otherNames) {
if (Algorithms.isEmpty(snames)) { copyNames(otherName, otherEnName, otherNames, false);
return; }
}
if (snames.containsKey("name:en")) { public void copyNames(MapObject s, boolean copyName, boolean copyEnName, boolean overwrite) {
enName = snames.get("name:en"); copyNames((copyName ? s.name : null), (copyEnName ? s.enName : null), s.names, overwrite);
} else if (snames.containsKey("en")) { }
enName = snames.get("en");
} public void copyNames(MapObject s) {
for (Entry<String, String> e : snames.entrySet()) { copyNames(s, true, true, false);
String key = e.getKey();
if (key.startsWith("name:")) {
key = key.substring("name:".length());
}
if (names == null) {
names = new HashMap<String, String>();
}
if (Algorithms.isEmpty(names.get(key))) {
names.put(key, e.getValue());
}
}
} }
public String getName(String lang) { public String getName(String lang) {

View file

@ -172,7 +172,17 @@ public abstract class Entity implements Serializable {
} }
return tags.get(key); return tags.get(key);
} }
public Map<String, String> getNameTags() {
Map<String, String> result = new LinkedHashMap<String, String>();
for (Map.Entry<String, String> e : tags.entrySet()) {
if (e.getKey().startsWith("name:")) {
result.put(e.getKey(), e.getValue());
}
}
return result;
}
public int getVersion() { public int getVersion() {
return version; return version;
} }
@ -274,4 +284,5 @@ public abstract class Entity implements Serializable {
} }
return tags; return tags;
} }
} }

View file

@ -31,8 +31,8 @@ public class EntityParser {
if (mo.getEnName(false).length() == 0) { if (mo.getEnName(false).length() == 0) {
mo.setEnName(tags.get(OSMTagKey.NAME_EN.getValue())); mo.setEnName(tags.get(OSMTagKey.NAME_EN.getValue()));
} }
for(String ts : tags.keySet()) { for (String ts : tags.keySet()) {
if(ts.startsWith("name:") && !ts.equals(OSMTagKey.NAME_EN.getValue())) { if (ts.startsWith("name:") && !ts.equals(OSMTagKey.NAME_EN.getValue())) {
mo.setName(ts.substring(("name:").length()), tags.get(ts)); mo.setName(ts.substring(("name:").length()), tags.get(ts));
} }
} }