From: Tom Hughes Date: Fri, 2 Oct 2009 23:33:17 +0000 (+0000) Subject: Move javascript translations to a separate key based on the path to X-Git-Tag: live~6615 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/596ab82461c6662cbfbe027c16e332d75a1e3c2e?hp=52126dc3c1ff197d2e73b7876768c0c0677ff94d;ds=sidebyside 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. --- diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b28ab7c1a..010737245 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -10,4 +10,32 @@ module ApplicationHelper def atom_link_to(*args) return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" }); end + + def javascript_strings + js = "" + + js << "\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 diff --git a/app/views/layouts/site.html.erb b/app/views/layouts/site.html.erb index 46a3d9d11..1e4e56e6a 100644 --- a/app/views/layouts/site.html.erb +++ b/app/views/layouts/site.html.erb @@ -1,18 +1,7 @@ - + <%= javascript_strings %> <%= javascript_include_tag 'prototype' %> <%= javascript_include_tag 'site' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index fb433d8af..bf1b58857 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -429,10 +429,8 @@ en: view_tooltip: View maps edit: Edit edit_tooltip: Edit maps - edit_zoom_alert: You must zoom in to edit the map history: History history_tooltip: Changeset history - history_zoom_alert: You must zoom in to see the editing history export: Export export_tooltip: Export map data gps_traces: GPS Traces @@ -614,14 +612,6 @@ en: delete: deleted: "Message deleted" site: - layers: - base: - mapnik: Mapnik - osmarender: Osmarender - cycle_map: Cycle Map - noname: NoName - overlays: - maplint: Maplint index: 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." @@ -1008,3 +998,15 @@ en: remove_friend: success: "{{name}} was removed from 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 diff --git a/public/javascripts/map.js b/public/javascripts/map.js index 1afd3eef9..8ae2349ea 100644 --- a/public/javascripts/map.js +++ b/public/javascripts/map.js @@ -36,26 +36,26 @@ function createMap(divName, options) { 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, wrapDateLine: true }); 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, wrapDateLine: true }); 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, wrapDateLine: true }); map.addLayer(cyclemap); 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://b.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); - 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, wrapDateLine: true }); diff --git a/public/javascripts/site.js b/public/javascripts/site.js index 17b2f0668..9dbb2a640 100644 --- a/public/javascripts/site.js +++ b/public/javascripts/site.js @@ -62,7 +62,7 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,objtype,obj node.href = setArgs("/edit", args); node.style.fontStyle = 'normal'; } 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'; } } @@ -87,7 +87,7 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,objtype,obj node.href = setArgs("/history", args); node.style.fontStyle = 'normal'; } 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'; } }