Skip to content

Commit

Permalink
Add i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
davec committed Jun 29, 2010
1 parent adbf0df commit f26f800
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/polls_controller.rb
Expand Up @@ -4,7 +4,7 @@ class Admin::PollsController < Admin::ResourceController
def clear_responses
if @poll = Poll.find(params[:id])
@poll.clear_responses
flash[:notice] = "Poll '#{@poll.title}' responses cleared."
flash[:notice] = t('polls_controller.responses_cleared', :poll => @poll.title)
end
redirect_to :action => :index
end
Expand Down
12 changes: 6 additions & 6 deletions app/views/admin/polls/_form.html.erb
Expand Up @@ -3,22 +3,22 @@
<div class="form-area">
<div id="poll_form_area">
<p class="title">
<label for="poll_title">Title</label>
<label for="poll_title"><%= t('polls_form.label.title') %></label>
<%= f.text_field :title %>
</p>
<p class="title">
<label for="poll_start_date">Start Date</label>
<label for="poll_start_date"><%= t('polls_form.label.start_date') %></label>
<%= f.text_field :start_date, :size => 15 %>
</p>
<p class="title">
<label for="poll_options" id="options-title">Options</label>
<label for="poll_options" id="options-title"><%= t('polls_form.label.options') %></label>
<div id="options">
<%- if first_new_form -%>
<p class="option"><input type="text" name="poll[option_attributes][][title]" size="30" /></p>
<%- end -%>
<%= render :partial => 'option', :collection => @poll.options %>
</div>
<p id="add-option"><%= link_to_function("Add Poll Option", "add_option('options');") %></p>
<p id="add-option"><%= link_to_function(t('polls_form.label.add_option'), "add_option('options');") %></p>
</p>
</div>
</div>
Expand All @@ -28,7 +28,7 @@
<%- end -%>
<p class="buttons">
<%= save_model_button(@poll) %>
or
<%= link_to('Cancel', admin_polls_url) %>
<%= t('or') %>
<%= link_to(t('cancel'), admin_polls_url) %>
</p>
<%- end -%>
2 changes: 1 addition & 1 deletion app/views/admin/polls/_option.html.erb
Expand Up @@ -6,7 +6,7 @@
<%= f.hidden_field :id, :index => option_id, :name => "#{field_base_name}[id]" %>
<%= f.hidden_field :should_destroy, :index => option_id, :name => "#{field_base_name}[should_destroy]", :class => 'should_destroy' %>
<%- unless object.should_destroy? -%>
<%= link_to_function "Delete", "delete_option(#{option_id}, 'options')", { :class => 'delete' } %>
<%= link_to_function t('remove'), "delete_option(#{option_id}, 'options')", { :class => 'delete' } %>
<%= f.text_field :title, :index => option_id, :name => "#{field_base_name}[title]", :size => 30 %>
<%- end -%>
</p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/polls/edit.html.erb
Expand Up @@ -4,6 +4,6 @@
content_for :page_scripts do %>
Event.addBehavior({ '#poll_start_date': DateSelector });
<% end %>
<h1>Edit Poll</h1>
<h1><%= t('polls_action.edit') %></h1>

<%= render :partial => 'form' %>
27 changes: 12 additions & 15 deletions app/views/admin/polls/index.html.erb
@@ -1,27 +1,23 @@
<% include_stylesheet 'admin/polls' %>

<h1>Polls</h1>
<h1><%= t('polls_index.title') %></h1>

<p>
Click on a poll name below to edit it, or click <code>Remove</code> to delete it.
If a poll has responses, click the responses value to toggle the view of the results.
Poll responses can be cleared by clicking <code>Clear responses</code>.
</p>
<p><%= t('polls_index.instructions') %></p>

<table id="polls" class="index">
<thead>
<tr>
<th class="title">Title</th>
<th class="date">Start Date</th>
<th class="responses">Responses</th>
<th class="modify" colspan="2">Modify</th>
<th class="title"><%= t('polls_index.column.title') %></th>
<th class="date"><%= t('polls_index.column.start_date') %></th>
<th class="responses"><%= t('polls_index.column.responses') %></th>
<th class="modify" colspan="2"><%= t('modify') %></th>
</tr>
</thead>
<tbody>
<%- if @polls.empty? -%>
<tr>
<td class="note" colspan="5">
You have not created any polls. Click <code>New Poll</code> below to get started.
<%= t('polls_index.empty') %>
</td>
</tr>
<%- else -%>
Expand All @@ -45,18 +41,19 @@
<td class="reset">
<%# Don't display Clear Responses link if there aren't any responses to clear -%>
<%- unless poll.options.find(:all, :conditions => ["response_count >= 1"]).empty? -%>
<%= link_to(image('polls/reset', :alt => 'Clear responses'), clear_responses_admin_poll_url(poll), :method => :post, :confirm => "Really clear poll responses?") %>
<%# link_to(image('polls/reset', :alt => t('polls_index.reset')), clear_responses_admin_poll_url(poll), :method => :post, :confirm => t('polls_index.reset_confirm')) %>
<%= link_to(t('polls_index.reset'), clear_responses_admin_poll_url(poll), :method => :post, :confirm => t('polls_index.reset_confirm')) %>
<%- end -%>
</td>
<td class="remove">
<%= link_to(image('remove', :alt => 'Remove poll'), admin_poll_url(poll), :method => :delete, :confirm => "Really delete this poll?") %>
<%= link_to(t('remove'), admin_poll_url(poll), :method => :delete, :confirm => t('polls_index.delete_confirm')) %>
</td>
</tr>
<%- if poll.response_count > 0 -%>
<tr>
<td colspan="5">
<div id="poll_<%= poll.id %>_results" class="results" style="display: none;">
<strong>Results</strong>
<strong><%= t('poll_index.results') %></strong>
<table>
<% poll.options.sort{|a,b| b.response_count <=> a.response_count}.each do |option| %>
<tr>
Expand All @@ -75,5 +72,5 @@
</table>

<p>
<%= link_to(image('polls/new-poll', :alt => 'New Poll'), new_admin_poll_url) %>
<%= link_to(image('polls/new-poll', :alt => t('polls_action.new')), new_admin_poll_url) %>
</p>
2 changes: 1 addition & 1 deletion app/views/admin/polls/new.html.erb
Expand Up @@ -4,6 +4,6 @@
content_for :page_scripts do %>
Event.addBehavior({ '#poll_start_date': DateSelector });
<% end %>
<h1>New Poll</h1>
<h1><%= t('polls_action.new') %></h1>

<%= render :partial => 'form' %>
25 changes: 25 additions & 0 deletions config/locales/en.yml
@@ -0,0 +1,25 @@
---
en:
polls_action:
edit: 'Edit Poll'
new: 'New Poll'
polls_form:
label:
title: 'Title'
start_date: 'Start Date'
options: 'Options'
add_option: 'Add Poll Option'
polls_index:
title: 'Polls'
instructions: 'Click on a poll name below to edit it, or click <code>Remove</code> to delete it. If a poll has responses, click the responses value to toggle the view of the results. Poll responses can be cleared by clicking <code>Clear responses</code>.'
column:
title: 'Title'
start_date: 'Start Date'
responses: 'Responses'
empty: 'You have not created any polls. Click <code>New Poll</code> below to get started.'
reset: 'Clear responses'
reset_confirm: 'Really clear poll responses?'
delete_confirm: 'Really delete this poll?'
results: 'Results'
polls_controller:
responses_cleared: 'Responses for poll "{{poll}}" have been cleared.'
32 changes: 29 additions & 3 deletions lib/tasks/polls_extension_tasks.rake
Expand Up @@ -7,8 +7,10 @@ namespace :radiant do
require 'radiant/extension_migrator'
if ENV["VERSION"]
PollsExtension.migrator.migrate(ENV["VERSION"].to_i)
Rake::Task['db:schema:dump'].invoke
else
PollsExtension.migrator.migrate
Rake::Task['db:schema:dump'].invoke
end
end

Expand All @@ -19,10 +21,34 @@ namespace :radiant do
path = file.sub(PollsExtension.root, '')
directory = File.dirname(path)
puts "Copying #{path}..."
mkdir_p RAILS_ROOT + directory
cp file, RAILS_ROOT + path
mkdir_p RAILS_ROOT + directory, :verbose => false
cp file, RAILS_ROOT + path, :verbose => false
end

unless PollsExtension.starts_with? RAILS_ROOT # don't need to copy vendored tasks
puts "Copying rake tasks from PollsExtension"
local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
mkdir_p local_tasks_path, :verbose => false
Dir[File.join PollsExtension.root, %w(lib tasks *.rake)].each do |file|
cp file, local_tasks_path, :verbose => false
end
end

desc "Syncs all available translations for this ext to the English ext master"
task :sync => :environment do
# The main translation root, basically where English is kept
language_root = PollsExtension.get_translation_keys(language_root)

Dir["#{language_root}/*.yml"].each do |filename|
next if filename.match('_available_tags')
basename = File.basename(filename, '.yml')
puts "Syncing #{basename}"
(comments, other) = TranslationSupport.read_file(filename, basename)
words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
TranslationSupport.write_file(filename, basename, comments, other)
end
end

end

end
Expand Down
Binary file added public/images/admin/polls/recycle.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/images/admin/polls/reset.png
Binary file not shown.
11 changes: 11 additions & 0 deletions public/stylesheets/admin/polls.css
Expand Up @@ -6,6 +6,17 @@
padding-right: 2em;
text-align: right;
}
#content #polls.index .reset {
padding-left: 0;
width: 140px;
}
#content #polls.index .reset a {
background: url("../../images/admin/polls/recycle.png") no-repeat scroll 4px 0 transparent;
color: black;
font-size: 80%;
padding: 0 0 0 20px;
text-decoration: none;
}
#content #polls.index th.modify {
text-align: center;
}
Expand Down

0 comments on commit f26f800

Please sign in to comment.