Move javascript translations to a separate key based on the path to
the javascript file that uses them and amend the layout to automatically find and output all javascript strings.
This commit is contained in:
parent
52126dc3c1
commit
596ab82461
5 changed files with 48 additions and 29 deletions
|
@ -10,4 +10,32 @@ module ApplicationHelper
|
||||||
def atom_link_to(*args)
|
def atom_link_to(*args)
|
||||||
return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
|
return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def javascript_strings
|
||||||
|
js = ""
|
||||||
|
|
||||||
|
js << "<script type='text/javascript'>\n"
|
||||||
|
js << "rails_i18n = new Array();\n"
|
||||||
|
js << javascript_strings_for_key("javascripts")
|
||||||
|
js << "</script>\n"
|
||||||
|
|
||||||
|
return js
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def javascript_strings_for_key(key)
|
||||||
|
js = ""
|
||||||
|
value = t(key)
|
||||||
|
|
||||||
|
if value.is_a?(String)
|
||||||
|
js << "rails_i18n['#{key}'] = '" << escape_javascript(value) << "';\n"
|
||||||
|
else
|
||||||
|
value.each_key do |k|
|
||||||
|
js << javascript_strings_for_key("#{key}.#{k}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return js
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,7 @@
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= I18n.locale %>" lang="<%= I18n.locale %>" dir="<%= t'html.dir' %>">
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= I18n.locale %>" lang="<%= I18n.locale %>" dir="<%= t'html.dir' %>">
|
||||||
<head>
|
<head>
|
||||||
<script type="text/javascript">
|
<%= javascript_strings %>
|
||||||
/* This is a hack so we don't have to dynamically generate some of our JavaScript files */
|
|
||||||
var rails_i18n = new Array();
|
|
||||||
rails_i18n["layouts.edit_zoom_alert"] = '<%= escape_javascript(t('layouts.edit_zoom_alert')) %>';
|
|
||||||
rails_i18n["layouts.history_zoom_alert"] = '<%= escape_javascript(t('layouts.history_zoom_alert')) %>';
|
|
||||||
// Layer switcher
|
|
||||||
rails_i18n["site.layers.base.mapnik"] = '<%= escape_javascript(t('site.layers.base.mapnik')) %>';
|
|
||||||
rails_i18n["site.layers.base.osmarender"] = '<%= escape_javascript(t('site.layers.base.osmarender')) %>';
|
|
||||||
rails_i18n["site.layers.base.cycle_map"] = '<%= escape_javascript(t('site.layers.base.cycle_map')) %>';
|
|
||||||
rails_i18n["site.layers.base.noname"] = '<%= escape_javascript(t('site.layers.base.noname')) %>';
|
|
||||||
rails_i18n["site.layers.overlays.maplint"] = '<%= escape_javascript(t('site.layers.overlays.maplint')) %>';
|
|
||||||
</script>
|
|
||||||
<%= javascript_include_tag 'prototype' %>
|
<%= javascript_include_tag 'prototype' %>
|
||||||
<%= javascript_include_tag 'site' %>
|
<%= javascript_include_tag 'site' %>
|
||||||
<!--[if lt IE 7]><%= javascript_include_tag 'pngfix' %><![endif]--> <!-- thanks, microsoft! -->
|
<!--[if lt IE 7]><%= javascript_include_tag 'pngfix' %><![endif]--> <!-- thanks, microsoft! -->
|
||||||
|
|
|
@ -429,10 +429,8 @@ en:
|
||||||
view_tooltip: View maps
|
view_tooltip: View maps
|
||||||
edit: Edit
|
edit: Edit
|
||||||
edit_tooltip: Edit maps
|
edit_tooltip: Edit maps
|
||||||
edit_zoom_alert: You must zoom in to edit the map
|
|
||||||
history: History
|
history: History
|
||||||
history_tooltip: Changeset history
|
history_tooltip: Changeset history
|
||||||
history_zoom_alert: You must zoom in to see the editing history
|
|
||||||
export: Export
|
export: Export
|
||||||
export_tooltip: Export map data
|
export_tooltip: Export map data
|
||||||
gps_traces: GPS Traces
|
gps_traces: GPS Traces
|
||||||
|
@ -614,14 +612,6 @@ en:
|
||||||
delete:
|
delete:
|
||||||
deleted: "Message deleted"
|
deleted: "Message deleted"
|
||||||
site:
|
site:
|
||||||
layers:
|
|
||||||
base:
|
|
||||||
mapnik: Mapnik
|
|
||||||
osmarender: Osmarender
|
|
||||||
cycle_map: Cycle Map
|
|
||||||
noname: NoName
|
|
||||||
overlays:
|
|
||||||
maplint: Maplint
|
|
||||||
index:
|
index:
|
||||||
js_1: "You are either using a browser that doesn't support JavaScript, or you have disabled JavaScript."
|
js_1: "You are either using a browser that doesn't support JavaScript, or you have disabled JavaScript."
|
||||||
js_2: "OpenStreetMap uses JavaScript for its slippy map."
|
js_2: "OpenStreetMap uses JavaScript for its slippy map."
|
||||||
|
@ -1008,3 +998,15 @@ en:
|
||||||
remove_friend:
|
remove_friend:
|
||||||
success: "{{name}} was removed from your friends."
|
success: "{{name}} was removed from your friends."
|
||||||
not_a_friend: "{{name}} is not one of your friends."
|
not_a_friend: "{{name}} is not one of your friends."
|
||||||
|
javascripts:
|
||||||
|
map:
|
||||||
|
base:
|
||||||
|
mapnik: Mapnik
|
||||||
|
osmarender: Osmarender
|
||||||
|
cycle_map: Cycle Map
|
||||||
|
noname: NoName
|
||||||
|
overlays:
|
||||||
|
maplint: Maplint
|
||||||
|
site:
|
||||||
|
edit_zoom_alert: You must zoom in to edit the map
|
||||||
|
history_zoom_alert: You must zoom in to see the editing history
|
||||||
|
|
|
@ -36,26 +36,26 @@ function createMap(divName, options) {
|
||||||
displayProjection: new OpenLayers.Projection("EPSG:4326")
|
displayProjection: new OpenLayers.Projection("EPSG:4326")
|
||||||
});
|
});
|
||||||
|
|
||||||
var mapnik = new OpenLayers.Layer.OSM.Mapnik(rails_i18n["site.layers.base.mapnik"], {
|
var mapnik = new OpenLayers.Layer.OSM.Mapnik(rails_i18n["javascripts.map.base.mapnik"], {
|
||||||
displayOutsideMaxExtent: true,
|
displayOutsideMaxExtent: true,
|
||||||
wrapDateLine: true
|
wrapDateLine: true
|
||||||
});
|
});
|
||||||
map.addLayer(mapnik);
|
map.addLayer(mapnik);
|
||||||
|
|
||||||
var osmarender = new OpenLayers.Layer.OSM.Osmarender(rails_i18n["site.layers.base.osmarender"], {
|
var osmarender = new OpenLayers.Layer.OSM.Osmarender(rails_i18n["javascripts.map.base.osmarender"], {
|
||||||
displayOutsideMaxExtent: true,
|
displayOutsideMaxExtent: true,
|
||||||
wrapDateLine: true
|
wrapDateLine: true
|
||||||
});
|
});
|
||||||
map.addLayer(osmarender);
|
map.addLayer(osmarender);
|
||||||
|
|
||||||
var cyclemap = new OpenLayers.Layer.OSM.CycleMap(rails_i18n["site.layers.base.cycle_map"], {
|
var cyclemap = new OpenLayers.Layer.OSM.CycleMap(rails_i18n["javascripts.map.base.cycle_map"], {
|
||||||
displayOutsideMaxExtent: true,
|
displayOutsideMaxExtent: true,
|
||||||
wrapDateLine: true
|
wrapDateLine: true
|
||||||
});
|
});
|
||||||
map.addLayer(cyclemap);
|
map.addLayer(cyclemap);
|
||||||
|
|
||||||
var nonamekey = nonamekeys[document.domain];
|
var nonamekey = nonamekeys[document.domain];
|
||||||
var noname = new OpenLayers.Layer.OSM(rails_i18n["site.layers.base.noname"], [
|
var noname = new OpenLayers.Layer.OSM(rails_i18n["javascripts.map.base.noname"], [
|
||||||
"http://a.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png",
|
"http://a.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png",
|
||||||
"http://b.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png",
|
"http://b.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png",
|
||||||
"http://c.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png"
|
"http://c.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png"
|
||||||
|
@ -66,7 +66,7 @@ function createMap(divName, options) {
|
||||||
});
|
});
|
||||||
map.addLayer(noname);
|
map.addLayer(noname);
|
||||||
|
|
||||||
var maplint = new OpenLayers.Layer.OSM.Maplint(rails_i18n["site.layers.overlays.maplint"], {
|
var maplint = new OpenLayers.Layer.OSM.Maplint(rails_i18n["javascripts.map.overlays.maplint"], {
|
||||||
displayOutsideMaxExtent: true,
|
displayOutsideMaxExtent: true,
|
||||||
wrapDateLine: true
|
wrapDateLine: true
|
||||||
});
|
});
|
||||||
|
|
|
@ -62,7 +62,7 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,objtype,obj
|
||||||
node.href = setArgs("/edit", args);
|
node.href = setArgs("/edit", args);
|
||||||
node.style.fontStyle = 'normal';
|
node.style.fontStyle = 'normal';
|
||||||
} else {
|
} else {
|
||||||
node.href = 'javascript:alert(rails_i18n["layouts.edit_zoom_alert"]);';
|
node.href = 'javascript:alert(rails_i18n["javascripts.site.edit_zoom_alert"]);';
|
||||||
node.style.fontStyle = 'italic';
|
node.style.fontStyle = 'italic';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,objtype,obj
|
||||||
node.href = setArgs("/history", args);
|
node.href = setArgs("/history", args);
|
||||||
node.style.fontStyle = 'normal';
|
node.style.fontStyle = 'normal';
|
||||||
} else {
|
} else {
|
||||||
node.href = 'javascript:alert(rails_i18n["layouts.history_zoom_alert"]);';
|
node.href = 'javascript:alert(rails_i18n["javascripts.site.history_zoom_alert"]);';
|
||||||
node.style.fontStyle = 'italic';
|
node.style.fontStyle = 'italic';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue