Merge pull request #6 from apmon/jsroute

Make more of the javascript routing functions internationalizable
This commit is contained in:
Richard Fairhurst 2014-02-03 09:35:44 -08:00
commit 04e2d35834
9 changed files with 94 additions and 30 deletions

View file

@ -349,7 +349,7 @@ $(document).ready(function () {
});
OSM.routing = OSM.Routing(map,'OSM.routing',$('.query_wrapper.routing'));
OSM.routing.chooseEngine('Car (OSRM)');
OSM.routing.chooseEngine('javascripts.directions.engines.osrm_car');
$(".get_directions").on("click",function(e) {
e.preventDefault();

View file

@ -14,24 +14,7 @@
*** add YOURS engine
*/
var TURN_INSTRUCTIONS=["",
"Continue on ", // 1
"Slight right onto ", // 2
"Turn right onto ", // 3
"Sharp right onto ", // 4
"U-turn along ", // 5
"Sharp left onto ", // 6
"Turn left onto ", // 7
"Slight left onto ", // 8
"(via point) ", // 9
"Follow ", // 10
"At roundabout take ", // 11
"Leave roundabout - ", // 12
"Stay on roundabout - ", // 13
"Start at end of ", // 14
"Reach destination", // 15
"Go against one-way on ", // 16
"End of one-way on "] // 17
var TURN_INSTRUCTIONS=[]
var ROUTING_POLYLINE={
color: '#03f',
@ -48,6 +31,25 @@ OSM.RoutingEngines={
OSM.Routing=function(map,name,jqSearch) {
var r={};
TURN_INSTRUCTIONS=["",
I18n.t('javascripts.directions.instructions.continue_on'), // 1
I18n.t('javascripts.directions.instructions.slight_right'), // 2
I18n.t('javascripts.directions.instructions.turn_right'), // 3
I18n.t('javascripts.directions.instructions.sharp_right'), // 4
I18n.t('javascripts.directions.instructions.uturn'), // 5
I18n.t('javascripts.directions.instructions.sharp_left'), // 6
I18n.t('javascripts.directions.instructions.turn_left'), // 7
I18n.t('javascripts.directions.instructions.slight_left'), // 8
I18n.t('javascripts.directions.instructions.via_point'), // 9
I18n.t('javascripts.directions.instructions.follow'), // 10
I18n.t('javascripts.directions.instructions.roundabout'), // 11
I18n.t('javascripts.directions.instructions.leave_roundabout'), // 12
I18n.t('javascripts.directions.instructions.stay_roundabout'), // 13
I18n.t('javascripts.directions.instructions.start'), // 14
I18n.t('javascripts.directions.instructions.destination'), // 15
I18n.t('javascripts.directions.instructions.against_oneway'), // 16
I18n.t('javascripts.directions.instructions.end_oneway')] // 17
r.map=map; // Leaflet map
r.name=name; // global variable name of this instance (needed for JSONP)
r.jqSearch=jqSearch; // JQuery object for search panel
@ -184,7 +186,7 @@ OSM.Routing=function(map,name,jqSearch) {
// Create base table
$("#content").removeClass("overlay-sidebar");
$('#sidebar_content').empty();
var html='<h2><a class="geolink" href="#" onclick="$(~.close_directions~).click();return false;"><span class="icon close"></span></a>Directions</h2>'.replace(/~/g,"'");
var html='<h2><a class="geolink" href="#" onclick="$(~.close_directions~).click();return false;"><span class="icon close"></span></a>' + I18n.t('javascripts.directions.directions') + '</h2>'.replace(/~/g,"'");
html+="<table id='turnbyturn' />";
$('#sidebar_content').html(html);
// Add each row
@ -242,7 +244,7 @@ OSM.Routing=function(map,name,jqSearch) {
};
r['gotRoute'+num]=function(data) { r.awaitingRoute=false; list[num].gotRoute(r,data); };
}
select.append("<option value='"+i+"'>"+list[i].name+"</option>");
select.append("<option value='"+i+"'>"+I18n.t(list[i].name)+"</option>");
}
r.engines=list;
r.chosenEngine=list[0]; // default to first engine

View file

@ -4,7 +4,7 @@
// http://cloudmade.com/documentation/routing
OSM.RoutingEngines.list.push({
name: 'Foot (CloudMade)',
name: "javascripts.directions.engines.cloudmade_foot",
draggable: false,
CM_SPRITE_MAP: {
"C": 1,
@ -25,7 +25,8 @@ OSM.RoutingEngines.list.push({
}
url+=p.join(',');
url+="/foot.js";
this.requestJSONP(url+"?callback=");
url+="?lang=" + I18n.currentLocale();
this.requestJSONP(url+"&callback=");
},
gotRoute: function(router,data) {
router.setPolyline(data.route_geometry);

View file

@ -1,11 +1,11 @@
// GraphHopper bicycle engine
OSM.RoutingEngines.list.push({
name: 'Bicycle (GraphHopper)',
name: "javascripts.directions.engines.graphhopper_bike",
draggable: true,
_hints: {},
getRoute: function(isFinal, points) {
var url = "http://graphhopper.com/routing/api/route?vehicle=bike&locale=en";
var url = "http://graphhopper.com/routing/api/route?vehicle=bike&locale=" + I18n.currentLocale();
for (var i = 0; i < points.length; i++) {
var pair = points[i].join(',');
url += "&point=" + pair;

View file

@ -6,7 +6,7 @@
// *** needs to give credit
OSM.RoutingEngines.list.push({
name: 'Bicycle (MapQuest Open)',
name: "javascripts.directions.engines.mapquest_bike",
draggable: false,
_hints: {},
MQ_SPRITE_MAP: {
@ -36,6 +36,7 @@ OSM.RoutingEngines.list.push({
url+="&from="+from.join(',');
url+="&to="+to.join(',');
url+="&routeType=bicycle";
//url+="&locale=" + I18n.currentLocale(); //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n only provides language, e.g. "de"
url+="&manMaps=false";
url+="&shapeFormat=raw&generalize=0";
this.requestJSONP(url+"&callback=");

View file

@ -3,7 +3,7 @@
// *** need to clear hints at some point
OSM.RoutingEngines.list.push({
name: 'Car (OSRM)',
name: "javascripts.directions.engines.osrm_car",
draggable: true,
_hints: {},
getRoute: function(isFinal,points) {
@ -34,7 +34,7 @@ OSM.RoutingEngines.list.push({
var instText="<b>"+(i+1)+".</b> ";
instText+=TURN_INSTRUCTIONS[instCodes[0]];
if (instCodes[1]) { instText+="exit "+instCodes[1]+" "; }
if (instCodes[0]!=15) { instText+=s[1] ? "<b>"+s[1]+"</b>" : "(unnamed)"; }
if (instCodes[0]!=15) { instText+=s[1] ? "<b>"+s[1]+"</b>" : I18n.t('javascripts.directions.instructions.unnamed'); }
steps.push([line[s[3]], s[0].split('-')[0], instText, s[2]]);
}
if (steps.length) router.setItinerary({ steps: steps });

View file

@ -16,9 +16,9 @@
<div class='query_wrapper routing'>
<%= image_tag "marker-green.png", :class => 'routing_marker', :id => 'marker_from', :draggable => 'true' %>
<%= text_field_tag "route_from", params[:from], :placeholder => "From", :onchange=>"OSM.routing.geocode('route_from',event)" %>
<%= text_field_tag "route_from", params[:from], :placeholder => t('site.search.from'), :onchange=>"OSM.routing.geocode('route_from',event)" %>
<%= image_tag "marker-red.png" , :class => 'routing_marker', :id => 'marker_to' , :draggable => 'true' %>
<%= text_field_tag "route_to" , params[:to] , :placeholder => "To" , :onchange=>"OSM.routing.geocode('route_to' ,event)" %>
<%= text_field_tag "route_to" , params[:to] , :placeholder => t('site.search.to') , :onchange=>"OSM.routing.geocode('route_to' ,event)" %>
<select class='routing_engines' name='routing_engines' onchange="OSM.routing.selectEngine(event)"></select>
</div>

View file

@ -929,6 +929,32 @@ de:
javascripts:
close: Schließen
edit_help: Wähle eine höhere Zoomstufe und verschiebe die Karte an einen Ort, den du bearbeiten möchtest, und klicke hier.
directions:
directions: "Fahranweisungen: "
engines:
graphhopper_bike: "Fahrrad (GraphHopper)"
mapquest_bike: "Fahrrad (MapQuest)"
osrm_car: "Auto (OSRM)"
cloudmade_foot: "Fuss (Cloudmade)"
instructions:
continue_on: "Weiter auf "
slight_right: "Rechts halten auf "
turn_right: "Rechts abbiegen auf "
sharp_right: "Hart rechts auf "
uturn: "U-turn along "
sharp_left: "Hart links auf "
turn_left: "Links abbiegen auf "
slight_left: "Links halten auf "
via_point: "(via point) "
follow: "Folge "
roundabout: "Im Kreisverkehr nehme "
leave_roundabout: "Verlasse den Kreisverkehr - "
stay_roundabout: "Stay on roundabout - "
start: "Start at end of "
destination: "Ziel erreicht"
against_oneway: "Go against one-way on "
end_oneway: "Ende der Einbahnstrasse "
unnamed: "(unbekannt)"
key:
title: Legende
tooltip: Legende
@ -1467,6 +1493,12 @@ de:
preview: Vorschau
search:
search: Suchen
get_directions: "Route berechnen"
get_directions_title: "Routenberechnung zwischen zwei Orten"
close_directions: "Schliessen der Route"
close_directions_title: "Schliessen des Routenmenus"
from: "Von"
to: "Nach"
submit_text: Los
where_am_i: Wo bin ich?
where_am_i_title: Die momentane Position mit der Suchmaschine anzeigen

View file

@ -1328,6 +1328,8 @@ en:
get_directions_title: "Find directions between two points"
close_directions: "Close directions"
close_directions_title: "Close the directions panel"
from: "From"
to: "To"
where_am_i: "Where am I?"
where_am_i_title: Describe the current location using the search engine
submit_text: "Go"
@ -2116,6 +2118,32 @@ en:
comment_and_resolve: Comment & Resolve
comment: Comment
edit_help: Move the map and zoom in on a location you want to edit, then click here.
directions:
engines:
graphhopper_bike: "Bicycle (GraphHopper)"
mapquest_bike: "Bicycle (MapQuest)"
osrm_car: "Car (OSRM)"
cloudmade_foot: "Foot (Cloudmade)"
directions: "Directions"
instructions:
continue_on: "Continue on "
slight_right: "Slight right onto "
turn_right: "Turn right onto "
sharp_right: "Sharp right onto "
uturn: "U-turn along "
sharp_left: "Sharp left onto "
turn_left: "Turn leeeeft onto "
slight_left: "Slight left onto "
via_point: "(via point) "
follow: "Follow "
roundabout: "At roundabout take "
leave_roundabout: "Leave roundabout - "
stay_roundabout: "Stay on roundabout - "
start: "Start at end of "
destination: "Reach destination"
against_oneway: "Go against one-way on "
end_oneway: "End of one-way on "
unnamed: "(unnamed)"
redaction:
edit:
description: "Description"