]> git.openstreetmap.org Git - rails.git/commitdiff
Diary entries pretty much i18n'd. Additional test that checks there are no missing...
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Wed, 27 May 2009 17:19:59 +0000 (17:19 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Wed, 27 May 2009 17:19:59 +0000 (17:19 +0000)
app/controllers/diary_entry_controller.rb
app/views/diary_entry/_diary_comment.rhtml
app/views/diary_entry/edit.rhtml
app/views/diary_entry/no_such_entry.rhtml
app/views/diary_entry/no_such_user.rhtml
config/locales/en.yml
test/functional/diary_entry_controller_test.rb

index 9fad57c02522b44227ad4759c08e4418e2bbbfc3..9bbadb29dfbee1f48409e7bbe5cf1b08359fa87e 100644 (file)
@@ -115,7 +115,11 @@ class DiaryEntryController < ApplicationController
 
     if user
       @entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
-      @title = "Users' diaries | #{params[:display_name]}"
+      if @entry
+        @title = "Users' diaries | #{params[:display_name]}"
+      else
+        render :action => 'no_such_entry', :status => :not_found
+      end
     else
       @not_found_user = params[:display_name]
 
index 2aca51f545c89d2f4adc1b4aedf5d9e32e4fd6b7..45cce0b25326f32dd7a6fb1877ac6c5ea344d964 100644 (file)
@@ -1,3 +1,3 @@
-<h4 id="comment<%= diary_comment.id %>">Comment from <%= link_to h(diary_comment.user.display_name), :controller => 'user', :action => 'view', :display_name => diary_comment.user.display_name %>  at <%= diary_comment.created_at %></h4>
+<h4 id="comment<%= diary_comment.id %>"><%= t('diary_entry.comment_from', :link_user => (link_to h(diary_comment.user.display_name), :controller => 'user', :action => 'view', :display_name => diary_comment.user.display_name), :comment_created_at => l(diary_comment.created_at)) %></h4>
 <%= htmlize(diary_comment.body) %>
 <hr />
index 615d4b69ba32732782d87c286c13ed7e5bf1ba04..a08f7182e4f6db138e7f9fe5394e5d776ae0e559 100644 (file)
@@ -5,30 +5,30 @@
 <% form_for :diary_entry do |f| %>
   <table>
     <tr valign="top">
-      <td class="fieldName">Subject:</td>
+      <td class="fieldName"><%= t 'diary_entry.edit.subject' -%></td>
       <td><%= f.text_field :title, :size => 60 %></td>
     </tr>
     <tr valign="top">
-      <td class="fieldName">Body:</td>
+      <td class="fieldName"><%= t 'diary_entry.edit.body' -%></td>
       <td><%= f.text_area :body, :cols => 80 %></td>
     </tr>
     <tr valign="top">
-      <td class="fieldName">Language:</td>
+      <td class="fieldName"><%= t 'diary_entry.edit.language' -%></td>
       <td><%= f.collection_select :language, Language.find(:all), :code, :name %></td>
     </tr>
     <tr valign="top">
-      <td class="fieldName">Location:</td>
+      <td class="fieldName"><%= t 'diary_entry.edit.location' -%></td>
       <td>
         <div id="map" style="border: 1px solid black; position: relative; width : 90%; height : 400px; display: none;"></div>
-        <span class="location">Latitude: <%= f.text_field :latitude, :size => 20, :id => "latitude" %> Longitude: <%= f.text_field :longitude, :size => 20, :id => "longitude" %></span>
-        <a href="javascript:openMap()" id="usemap">use map</a>
+        <span class="location"><%= t 'diary_entry.edit.latitude' -%> <%= f.text_field :latitude, :size => 20, :id => "latitude" %> <%= t 'diary_entry.edit.longitude' -%> <%= f.text_field :longitude, :size => 20, :id => "longitude" %></span>
+        <a href="javascript:openMap()" id="usemap"><%= t 'diary_entry.edit.use_map_link' -%></a>
         <br/><br/>
       </td>
     </tr>
     <tr>
       <td></td>
       <td>
-         <%= submit_tag 'Save' %>
+         <%= submit_tag t 'diary_entry.edit.save_button' %>
          <%# TODO: button should say 'publish' or 'save changes' depending on new/edit state %>
       </td>
     </tr>
@@ -76,7 +76,7 @@
       removeMarkerFromMap(marker);
     }
 
-    marker = addMarkerToMap(lonlat, null, "Diary entry location");
+    marker = addMarkerToMap(lonlat, null, "<%= t 'diary_entry.edit.marker_text' -%>");
   }
 
   function openMap() {
index 1ebcf269c832febcf56afa5773b196d53a6fc959..eef0e47d2d73b284b5343cd107ea7ca0f364035a 100644 (file)
@@ -1,2 +1,2 @@
-<h2>No entry with the id: <%= h(params[:id]) %></h2>
-<p>Sorry, there is no diary entry or comment with the id <%=h params[:id] -%>, or no id was given. Please check your spelling, or maybe the link you clicked is wrong.</p>
+<h2><%= t 'diary_entry.no_such_entry.heading', :id => h(params[:id]) %></h2>
+<p><%= t 'diary_entry.no_such_entry.body', :id => h(params[:id]) %></p>
index 7820b4847c6d260a232005a0eda5bcda52a2a930..02f6a4df205dd79771a8adc9559f169929acbe0f 100644 (file)
@@ -1,2 +1,2 @@
 <h2><%= h(@not_found_user) %></h2>
-<p>Sorry, there is no user with the name <%= @not_found_user -%>. Please check your spelling, or maybe the link you clicked is wrong.</p>
+<p><%= t 'diary_entry.no_such_user.body', :user => @not_found_user %></p>
index d174ba087f30c024d5f2793a204948ed885fdea3..15b25c4d66d3786d7c9a9b50d8d87980babf643c 100644 (file)
@@ -11,6 +11,21 @@ en:
       recent_entries: "Recent diary entries: "
       older_entries: Older Entries
       newer_entries: Newer Entries
+    edit:
+      subject: "Subject:"
+      body: "Body:"
+      language: "Language:"
+      location: "Location:"
+      latitude: "Latitude:"
+      longitude: "Longitude:"
+      use_map_link: "use map"
+      save_button: "Save"
+      marker_text: Diary entry location
+    no_such_entry:
+      heading: "No entry with the id: {{id}}"
+      body: "Sorry, there is no diary entry or comment with the id {{id}}. Please check your spelling, or maybe the link you clicked is wrong."
+    no_such_user:
+      body: "Sorry, there is no user with the name {{user}}. Please check your spelling, or maybe the link you clicked is wrong."
     posted_by: "Posted by {{link_user}} at {{created}} in {{language}}"
     comment_link: Comment on this entry
     reply_link: Reply to this entry
@@ -18,3 +33,4 @@ en:
       one: 1 comment
       other: "{{count}} comments"
     edit_link: Edit this entry
+    comment_from: "Comment from {{link_user}}  at {{comment_created_at}}"
index 3bbf8ae0a357c1870368037e5302d7a12daf9b54..41db4436f5c2e9916bdc8b35b149defa0310fd3b 100644 (file)
@@ -145,6 +145,16 @@ class DiaryEntryControllerTest < ActionController::TestCase
     
   end
   
+  def test_edit_diary_entry_i18n
+    I18n.available_locales.each do |locale|
+      set_locale locale
+      
+      get(:edit, {:id => diary_entries(:normal_user_entry_1).id}, {'user' => users(:normal_user).id})
+      assert_response :success
+      assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry"
+    end
+  end
+  
   def test_create_diary_entry
     #post :new
   end
@@ -162,11 +172,13 @@ class DiaryEntryControllerTest < ActionController::TestCase
       get :list
       assert_response :success, "Should be able to list the diary entries in #{locale}"
       assert_template 'list', "Should use the list template in #{locale}"
+      assert_select "span[class=translation_missing]", false, "Missing translation in list of diary entries"
     
       # Now try to find a specific user's diary entry
       get :list, {:display_name => users(:normal_user).display_name}
       assert_response :success, "Should be able to list the diary entries for a user in #{locale}"
       assert_template 'list', "Should use the list template for a user in #{locale}"
+      assert_select "span[class=translation_missing]", false, "Missing translation in list of diary entries for user"
     end
   end