var div = document.createElement("div");
var p = document.createElement("p");
- p.appendChild(document.createTextNode("#{I18n.t('browse.start_rjs.loaded_an_area')} " + browseFeatureList.length + " #{I18n.t('browse.start_rjs.browsers')}"));
+ p.appendChild(document.createTextNode(i18n_js("#{I18n.t('browse.start_rjs.loaded_an_area_with_num_features', :num_features => '{{num_features}}')}", { num_features: browseFeatureList.length })));
div.appendChild(p);
var input = document.createElement("input");
var projected = bounds.clone().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
var size = projected.getWidth() * projected.getHeight();
- if (size > 0.25) {
- setStatus("#{I18n.t('browse.start_rjs.unable_to_load')} " + size + " #{I18n.t('must_be_smaller')}");
+ if (size > #{APP_CONFIG['max_request_area']}) {
+ setStatus(i18n_js("#{I18n.t('browse.start_rjs.unable_to_load_size', :bbox_size => '{{bbox_size}}', :max_bbox_size => APP_CONFIG['max_request_area'])}", { bbox_size: size }));
} else {
loadGML("/api/#{API_VERSION}/map?bbox=" + projected.toBBOX());
}
var heading = document.createElement("p");
heading.className = "browse_heading";
- heading.appendChild(document.createTextNode("Object list"));
+ heading.appendChild(document.createTextNode("#{I18n.t('browse.start_rjs.object_list.heading')}"));
browseObjectList.appendChild(heading);
var list = document.createElement("ul");
// Type, for linking
var type = featureType(feature);
- var typeName = ucFirst(type);
+ var typeName = featureTypeName(feature);
var li = document.createElement("li");
li.appendChild(document.createTextNode(typeName + " "));
var link = document.createElement("a");
link.href = this.url;
- link.appendChild(document.createTextNode("API"));
+ link.appendChild(document.createTextNode("#{I18n.t('browse.start_rjs.object_list.api')}"));
browseObjectList.appendChild(link);
$("browse_content").innerHTML = "";
var link = document.createElement("a");
link.href = "#";
link.onclick = loadObjectList;
- link.appendChild(document.createTextNode("Display object list"));
+ link.appendChild(document.createTextNode("#{I18n.t('browse.start_rjs.object_list.back')}"));
div.appendChild(link);
var table = document.createElement("table");
table.appendChild(tr);
var heading = document.createElement("td");
- heading.appendChild(document.createTextNode(featureName(feature)));
+ heading.appendChild(document.createTextNode(featureNameSelect(feature)));
tr.appendChild(heading);
var td = document.createElement("td");
var type = featureType(feature);
var link = document.createElement("a");
link.href = "/browse/" + type + "/" + feature.osm_id;
- link.appendChild(document.createTextNode("Details"));
+ link.appendChild(document.createTextNode("#{I18n.t('browse.start_rjs.object_list.details')}"));
td.appendChild(link);
var div = document.createElement("div");
table.appendChild(tr);
var heading = document.createElement("td");
- heading.appendChild(document.createTextNode("#{I18n.t('browse.start_rjs.history_for')} " + featureName(this.feature)));
+ heading.appendChild(document.createTextNode("#{I18n.t('browse.start_rjs.history_for')} " + featureNameHistory(this.feature)));
tr.appendChild(heading);
var td = document.createElement("td");
return "way";
}
}
-
- function featureName(feature) {
+
+ function featureTypeName(feature) {
+ if (featureType(feature) == "node") {
+ return "#{I18n.t('browse.start_rjs.object_list.type.node')}";
+ } else if (featureType(feature) == "way") {
+ return "#{I18n.t('browse.start_rjs.object_list.type.way')}";
+ }
+ }
+
+ function featureNameSelect(feature) {
if (feature.attributes.name) {
return feature.attributes.name;
- } else {
- return ucFirst(featureType(feature)) + " " + feature.osm_id;
+ } else if (featureType(feature) == "node") {
+ return "#{I18n.t('browse.start_rjs.object_list.selected.type.node')} " + feature.osm_id;
+ } else if (featureType(feature) == "way") {
+ return "#{I18n.t('browse.start_rjs.object_list.selected.type.way')} " + feature.osm_id;
+ }
+ }
+
+ function featureNameHistory(feature) {
+ if (feature.attributes.name) {
+ return feature.attributes.name;
+ } else if (featureType(feature) == "node") {
+ return "#{I18n.t('browse.start_rjs.object_list.history.type.node')} " + feature.osm_id;
+ } else if (featureType(feature) == "way") {
+ return "#{I18n.t('browse.start_rjs.object_list.history.type.way')} " + feature.osm_id;
}
}
+ /*
+ This is a hack so that we can interpolate JavaScript variables in
+ translation strings from Ruby, doing the string replacement
+ client-side instead of on the server.
+ */
+ function i18n_js(string, keys) {
+ for (var key in keys) {
+ var re_key = '\{\{' + key + '\}\}';
+ var re = new RegExp(re_key, "g");
+
+ string = string.replace(re, keys[key]);
+ }
+
+ return string;
+ }
+
function setStatus(status) {
$("browse_status").innerHTML = status;
$("browse_status").style.display = "block";
$("browse_status").style.display = "none";
}
- function ucFirst(str) {
- return str.substr(0,1).toUpperCase() + str.substr(1,str.length);
- }
-
startBrowse();
EOJ