Improve the data browser translation logic.
authorTom Hughes <tom@compton.nu>
Sat, 6 Jun 2009 15:46:41 +0000 (15:46 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 6 Jun 2009 15:46:41 +0000 (15:46 +0000)
app/views/browse/start.rjs
config/locales/en.yml

index 9c885870b81516cc02306f45bc3ce1d87730e1d5..c5247066e7e6143c5dcda7053c03652fca1a2e97 100644 (file)
@@ -249,19 +249,15 @@ page << <<EOJ
       browseObjectList.appendChild(heading);
 
       var list = document.createElement("ul");
-      // Pull in 118n names for node/way/relation
-      var typeTranslations = new Array();
-      typeTranslations['node']     = "#{I18n.t('browse.start_rjs.object_list.type.node')}"
-      typeTranslations['way']      = "#{I18n.t('browse.start_rjs.object_list.type.way')}"
-      typeTranslations['relation'] = "#{I18n.t('browse.start_rjs.object_list.type.relation')}"
 
       for (var i = 0; i < this.features.length; i++) {
         var feature = this.features[i]; 
             
         // Type, for linking
         var type = featureType(feature);
+        var typeName = featureTypeName(feature);
         var li = document.createElement("li");
-        li.appendChild(document.createTextNode(typeTranslations[type] + " "));
+        li.appendChild(document.createTextNode(typeName + " "));
             
         // Link, for viewing in the tab
         var link = document.createElement("a");
@@ -461,28 +457,32 @@ page << <<EOJ
       return "way";
     }
   }
-  
+
+  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 {
-      // Pull in 118n names for node/way
-      var featureNameSelectTypeTranslations = new Array();
-      featureNameSelectTypeTranslations['node'] = "#{I18n.t('browse.start_rjs.object_list.selected.type.node')}"
-      featureNameSelectTypeTranslations['way']  = "#{I18n.t('browse.start_rjs.object_list.selected.type.way')}"
-      return featureNameSelectTypeTranslations[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 {
-      // Pull in 118n names for node/way
-      var featureNameHistoryTypeTranslations = new Array();
-      featureNameHistoryTypeTranslations['node'] = "#{I18n.t('browse.start_rjs.object_list.history.type.node')}"
-      featureNameHistoryTypeTranslations['way']  = "#{I18n.t('browse.start_rjs.object_list.history.type.way')}"
-      return featureNameHistoryTypeTranslations[featureType(feature)] + " " + feature.osm_id;
+    } 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;
     }
   }
 
@@ -496,9 +496,5 @@ page << <<EOJ
     $("browse_status").style.display = "none";
   }
 
-  function ucFirst(str) {
-    return str.substr(0,1).toUpperCase() + str.substr(1,str.length);
-  }
-
   startBrowse();
 EOJ
index 1a84d046c186efe7f780efaded8bf6a8dde5613c..c2aaf469a9a8875da1a771b2e2c114ecf69a8849 100644 (file)
@@ -168,7 +168,7 @@ en:
         type:
           node: "Node"
           way: "Way"
-          relation: "Relation"
+          # There's no 'relation' type because it isn't represented in OpenLayers
         api: "Retrieve this are from the API"
         details: "Details"
         selected: