Some of our JavaScript files have UI messages but we don't want to

make them dynamic.

So I'm creating a globally scoped JavaScript array called rails_i18n
which holds some of these messages. It's loaded in <head> before any
of the JavaScript files so it should always be available.
This commit is contained in:
Ævar Arnfjörð Bjarmason 2009-10-02 20:19:28 +00:00
parent d0f2288797
commit b0e1560875
3 changed files with 11 additions and 2 deletions

View file

@ -1,6 +1,12 @@
<!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">
/* 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')) %>';
</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! -->

View file

@ -429,8 +429,10 @@ 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

View file

@ -1,3 +1,4 @@
/* /*
* Called as the user scrolls/zooms around to aniplate hrefs of the * Called as the user scrolls/zooms around to aniplate hrefs of the
* view tab and various other links * view tab and various other links
@ -61,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("zoom in to edit map");'; node.href = 'javascript:alert(rails_i18n["layouts.edit_zoom_alert"]);';
node.style.fontStyle = 'italic'; node.style.fontStyle = 'italic';
} }
} }
@ -86,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("zoom in to see editing history");'; node.href = 'javascript:alert(rails_i18n["layouts.history_zoom_alert"]);';
node.style.fontStyle = 'italic'; node.style.fontStyle = 'italic';
} }
} }