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 ce7ad28b75
commit 12582d8e80
6 changed files with 49 additions and 11 deletions

View file

@ -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<String> 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;

View file

@ -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) {

View file

@ -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<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;
if(waypoints != null) {
this.locationPoints.addAll(waypoints);
@ -207,7 +208,7 @@ public class RouteCalculationResult {
* PREPARATION
*/
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 prevDirectionDistance = 0;
List<RouteSegmentResult> segmentsToPopulate = new ArrayList<RouteSegmentResult>();
@ -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(),

View file

@ -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;

View file

@ -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;

View file

@ -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 = "";