Add localization to road section, navigation, TTS, etc (using configure map setting -> locale)

This commit is contained in:
Victor Shcherb 2015-06-16 00:47:01 +02:00
parent 635170def2
commit 3e0f95b2d8
6 changed files with 49 additions and 11 deletions

View file

@ -61,6 +61,27 @@ public class RouteDataObject {
return null; return null;
} }
public String getName(String lang){
if(names != null ) {
if(Algorithms.isEmpty(lang)) {
return names.get(region.nameTypeRule);
}
int[] kt = names.keys();
for(int i = 0 ; i < kt.length; i++) {
int k = kt[i];
if(region.routeEncodingRules.size() > k) {
if(("name:"+lang).equals(region.routeEncodingRules.get(k).getTag())) {
return names.get(k);
}
}
}
return names.get(region.nameTypeRule);
}
return null;
}
public TIntObjectHashMap<String> getNames() { public TIntObjectHashMap<String> getNames() {
return names; return names;
} }
@ -76,8 +97,21 @@ public class RouteDataObject {
return null; return null;
} }
public String getDestinationName(){ public String getDestinationName(String lang){
if(names != null) { if(names != null) {
if(Algorithms.isEmpty(lang)) {
return names.get(region.destinationTypeRule);
}
int[] kt = names.keys();
for(int i = 0 ; i < kt.length; i++) {
int k = kt[i];
if(region.routeEncodingRules.size() > k) {
if(("destination:"+lang).equals(region.routeEncodingRules.get(k).getTag())) {
return names.get(k);
}
}
}
return names.get(region.destinationTypeRule); return names.get(region.destinationTypeRule);
} }
return null; return null;

View file

@ -96,7 +96,8 @@ public class AvoidSpecificRoads {
protected String getText(RouteDataObject obj) { protected String getText(RouteDataObject obj) {
return RoutingHelper.formatStreetName(obj.getName(), obj.getRef(), obj.getDestinationName()); return RoutingHelper.formatStreetName(obj.getName(app.getSettings().MAP_PREFERRED_LOCALE.get()),
obj.getRef(), obj.getDestinationName(app.getSettings().MAP_PREFERRED_LOCALE.get()));
} }
public void showDialog(final MapActivity mapActivity) { public void showDialog(final MapActivity mapActivity) {

View file

@ -10,6 +10,7 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.router.RouteSegmentResult; import net.osmand.router.RouteSegmentResult;
import net.osmand.router.TurnType; import net.osmand.router.TurnType;
@ -85,7 +86,7 @@ public class RouteCalculationResult {
} }
public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates, public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates,
Context ctx, boolean leftSide, float routingTime, List<LocationPoint> waypoints) { OsmandApplication ctx, boolean leftSide, float routingTime, List<LocationPoint> waypoints) {
this.routingTime = routingTime; this.routingTime = routingTime;
if(waypoints != null) { if(waypoints != null) {
this.locationPoints.addAll(waypoints); this.locationPoints.addAll(waypoints);
@ -207,7 +208,7 @@ public class RouteCalculationResult {
* PREPARATION * PREPARATION
*/ */
private static List<RouteSegmentResult> convertVectorResult(List<RouteDirectionInfo> directions, List<Location> locations, List<RouteSegmentResult> list, private static List<RouteSegmentResult> convertVectorResult(List<RouteDirectionInfo> directions, List<Location> locations, List<RouteSegmentResult> list,
List<AlarmInfo> alarms, Context ctx) { List<AlarmInfo> alarms, OsmandApplication ctx) {
float prevDirectionTime = 0; float prevDirectionTime = 0;
float prevDirectionDistance = 0; float prevDirectionDistance = 0;
List<RouteSegmentResult> segmentsToPopulate = new ArrayList<RouteSegmentResult>(); List<RouteSegmentResult> segmentsToPopulate = new ArrayList<RouteSegmentResult>();
@ -254,8 +255,8 @@ public class RouteCalculationResult {
} }
RouteSegmentResult next = list.get(lind); RouteSegmentResult next = list.get(lind);
info.setRef(next.getObject().getRef()); info.setRef(next.getObject().getRef());
info.setStreetName(next.getObject().getName()); info.setStreetName(next.getObject().getName(ctx.getSettings().MAP_PREFERRED_LOCALE.get()));
info.setDestinationName(next.getObject().getDestinationName()); info.setDestinationName(next.getObject().getDestinationName(ctx.getSettings().MAP_PREFERRED_LOCALE.get()));
} }
String description = toString(turn, ctx) + " " + RoutingHelper.formatStreetName(info.getStreetName(), String description = toString(turn, ctx) + " " + RoutingHelper.formatStreetName(info.getStreetName(),

View file

@ -693,9 +693,9 @@ public class RoutingHelper {
} }
RouteSegmentResult rs = getCurrentSegmentResult(); RouteSegmentResult rs = getCurrentSegmentResult();
if(rs != null) { if(rs != null) {
String nm = rs.getObject().getName(); String nm = rs.getObject().getName(settings.MAP_PREFERRED_LOCALE.get());
String rf = rs.getObject().getRef(); String rf = rs.getObject().getRef();
String dn = rs.getObject().getDestinationName(); String dn = rs.getObject().getDestinationName(settings.MAP_PREFERRED_LOCALE.get());
return formatStreetName(nm, rf, dn); return formatStreetName(nm, rf, dn);
} }
return null; return null;

View file

@ -555,10 +555,11 @@ public class VoiceRouter {
getTermString(getSpeakablePointName(i.getDestinationName())) }); getTermString(getSpeakablePointName(i.getDestinationName())) });
Term current = empty; Term current = empty;
if (currentSegment != null) { if (currentSegment != null) {
RouteDataObject obj = currentSegment.getObject(); RouteDataObject obj = currentSegment.getObject();
current = new Struct(new Term[] { getTermString(getSpeakablePointName(obj.getRef())), current = new Struct(new Term[] { getTermString(getSpeakablePointName(obj.getRef())),
getTermString(getSpeakablePointName(obj.getName())), getTermString(getSpeakablePointName(obj.getName(settings.MAP_PREFERRED_LOCALE.get()))),
getTermString(getSpeakablePointName(obj.getDestinationName())) }); getTermString(getSpeakablePointName(obj.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()))) });
} }
Struct voice = new Struct("voice", next, current ); Struct voice = new Struct("voice", next, current );
return voice; return voice;

View file

@ -258,7 +258,8 @@ public class MapInfoWidgetsFactory {
settings.SHOW_STREET_NAME.get()) { settings.SHOW_STREET_NAME.get()) {
RouteDataObject rt = locationProvider.getLastKnownRouteSegment(); RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
if(rt != null) { if(rt != null) {
text = RoutingHelper.formatStreetName(rt.getName(), rt.getRef(), rt.getDestinationName()); text = RoutingHelper.formatStreetName(rt.getName(settings.MAP_PREFERRED_LOCALE.get()),
rt.getRef(), rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()));
} }
if(text == null) { if(text == null) {
text = ""; text = "";