Diary entries pretty much i18n'd. Additional test that checks there are no missing translation strings, need more like it.

This commit is contained in:
Shaun McDonald 2009-05-27 17:19:59 +00:00
parent ae70ea2858
commit b377927a64
7 changed files with 45 additions and 13 deletions

View file

@ -115,7 +115,11 @@ class DiaryEntryController < ApplicationController
if user
@entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
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]

View 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 />

View 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() {

View 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>

View 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>

View 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}}"

View 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