From 3e0f95b2d8946408044f8e6e9de154a41d324bb7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 16 Jun 2015 00:47:01 +0200 Subject: [PATCH] Add localization to road section, navigation, TTS, etc (using configure map setting -> locale) --- .../net/osmand/binary/RouteDataObject.java | 36 ++++++++++++++++++- .../plus/helpers/AvoidSpecificRoads.java | 3 +- .../plus/routing/RouteCalculationResult.java | 9 ++--- .../osmand/plus/routing/RoutingHelper.java | 4 +-- .../net/osmand/plus/routing/VoiceRouter.java | 5 +-- .../mapwidgets/MapInfoWidgetsFactory.java | 3 +- 6 files changed, 49 insertions(+), 11 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java index b7c0034813..2ceb60d3e0 100644 --- a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java @@ -61,6 +61,27 @@ public class RouteDataObject { 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 getNames() { return names; } @@ -76,8 +97,21 @@ public class RouteDataObject { return null; } - public String getDestinationName(){ + public String getDestinationName(String lang){ 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 null; diff --git a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java index e45b45165c..f6f2efc84d 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java +++ b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java @@ -96,7 +96,8 @@ public class AvoidSpecificRoads { 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) { diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 9371f8b120..c65233ed42 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -10,6 +10,7 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.router.RouteSegmentResult; import net.osmand.router.TurnType; @@ -85,7 +86,7 @@ public class RouteCalculationResult { } public RouteCalculationResult(List list, Location start, LatLon end, List intermediates, - Context ctx, boolean leftSide, float routingTime, List waypoints) { + OsmandApplication ctx, boolean leftSide, float routingTime, List waypoints) { this.routingTime = routingTime; if(waypoints != null) { this.locationPoints.addAll(waypoints); @@ -207,7 +208,7 @@ public class RouteCalculationResult { * PREPARATION */ private static List convertVectorResult(List directions, List locations, List list, - List alarms, Context ctx) { + List alarms, OsmandApplication ctx) { float prevDirectionTime = 0; float prevDirectionDistance = 0; List segmentsToPopulate = new ArrayList(); @@ -254,8 +255,8 @@ public class RouteCalculationResult { } RouteSegmentResult next = list.get(lind); info.setRef(next.getObject().getRef()); - info.setStreetName(next.getObject().getName()); - info.setDestinationName(next.getObject().getDestinationName()); + info.setStreetName(next.getObject().getName(ctx.getSettings().MAP_PREFERRED_LOCALE.get())); + info.setDestinationName(next.getObject().getDestinationName(ctx.getSettings().MAP_PREFERRED_LOCALE.get())); } String description = toString(turn, ctx) + " " + RoutingHelper.formatStreetName(info.getStreetName(), diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index bb306c3bf4..a51d96235c 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -693,9 +693,9 @@ public class RoutingHelper { } RouteSegmentResult rs = getCurrentSegmentResult(); if(rs != null) { - String nm = rs.getObject().getName(); + String nm = rs.getObject().getName(settings.MAP_PREFERRED_LOCALE.get()); 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 null; diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index a643636ac6..726475ee09 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -555,10 +555,11 @@ public class VoiceRouter { getTermString(getSpeakablePointName(i.getDestinationName())) }); Term current = empty; if (currentSegment != null) { + RouteDataObject obj = currentSegment.getObject(); current = new Struct(new Term[] { getTermString(getSpeakablePointName(obj.getRef())), - getTermString(getSpeakablePointName(obj.getName())), - getTermString(getSpeakablePointName(obj.getDestinationName())) }); + getTermString(getSpeakablePointName(obj.getName(settings.MAP_PREFERRED_LOCALE.get()))), + getTermString(getSpeakablePointName(obj.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()))) }); } Struct voice = new Struct("voice", next, current ); return voice; diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index ac3601e8f8..1670c536f4 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -258,7 +258,8 @@ public class MapInfoWidgetsFactory { settings.SHOW_STREET_NAME.get()) { RouteDataObject rt = locationProvider.getLastKnownRouteSegment(); 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) { text = "";