Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle updated translations in the UI

  • Loading branch information...
commit e44048dcdda35161468c8030d9cc9b11d6a036c0 1 parent 8b823a9
@lifo lifo authored
View
9 app/controllers/tolk/locales_controller.rb
@@ -1,7 +1,7 @@
module Tolk
class LocalesController < ApplicationController
- before_filter :find_locale, :only => [:show, :all, :update]
- before_filter :ensure_no_primary_locale, :only => [:all, :update, :show]
+ before_filter :find_locale, :only => [:show, :all, :update, :updated]
+ before_filter :ensure_no_primary_locale, :only => [:all, :update, :show, :updated]
def index
@locales = Tolk::Locale.secondary_locales
@@ -24,6 +24,11 @@ def all
@phrases = @locale.phrases_with_translation(params[:page])
end
+ def updated
+ @phrases = @locale.phrases_with_updated_translation(params[:page])
+ render :all
+ end
+
def create
Tolk::Locale.create!(params[:tolk_locale])
redirect_to :action => :index
View
6 app/models/tolk/locale.rb
@@ -11,7 +11,7 @@ class Locale < ActiveRecord::Base
}
has_many :phrases, :through => :translations, :class_name => 'Tolk::Phrase'
- has_many :translations, :include => :phrase, :class_name => 'Tolk::Translation'
+ has_many :translations, :class_name => 'Tolk::Translation'
accepts_nested_attributes_for :translations, :reject_if => proc { |attributes| attributes['text'].blank? }
cattr_accessor :locales_config_path
@@ -51,6 +51,10 @@ def dump_all(to = self.locales_config_path)
end
end
+ def has_updated_translations?
+ translations.count(:conditions => {:'tolk_translations.primary_updated' => true}) > 0
+ end
+
def phrases_with_translation(page = nil)
find_phrases_with_translations(page, :'tolk_translations.primary_updated' => false)
end
View
28 app/views/tolk/locales/all.html.erb
@@ -2,9 +2,11 @@
<% end %>
<h3 class="switch">Completed translations <span>(<%= link_to 'See phrases missing translation', @locale %>)</span></h3>
-<%# show when there are updated phrases for this locale %>
- <span class="notice">Some phrases have changed. <%= link_to "Update translations" %>.</span>
-<%# end %>
+
+<% if @locale.has_updated_translations? %>
+ <span class="notice">Some phrases have changed. <%= link_to "Update translations", updated_tolk_locale_path(@locale) %>.</span>
+<% end %>
+
<div class="translations">
<% if @phrases.any? %>
<% form_for @locale do |locale_form| %>
@@ -16,14 +18,20 @@
<% @phrases.each do |phrase| %>
<tr>
<td class="phrase">
- <div class="updated">
- <span class="key">Updated</span>
- <%=h phrase.translations.primary.text -%>
- </div>
- <div class="original">
- <span class="key">Original</span>
+
+ <% if action_name == 'updated' %>
+ <div class="updated">
+ <span class="key">Updated</span>
+ <%=h phrase.translations.primary.text -%>
+ </div>
+ <div class="original">
+ <span class="key">Original</span>
+ <%=h phrase.translations.primary.previous_text -%>
+ </div>
+ <% else %>
<%=h phrase.translations.primary.text -%>
- </div>
+ <% end %>
+
<span class="key"><%= phrase.key %></span>
</td>
View
8 app/views/tolk/locales/show.html.erb
@@ -2,9 +2,11 @@
<% end %>
<h3 class="switch">Phrases missing translation <span>(<%= link_to 'See completed translations', all_tolk_locale_path(@locale) %>)</span></h3>
-<%# show when there are updated phrases for this locale %>
- <span class="notice">Some phrases have changed. <%= link_to "Update translations" %>.</span>
-<%# end %>
+
+<% if @locale.has_updated_translations? %>
+ <span class="notice">Some phrases have changed. <%= link_to "Update translations", updated_tolk_locale_path(@locale) %>.</span>
+<% end %>
+
<div class="translations">
<% if @phrases.any? %>
<% form_for @locale do |locale_form| %>
View
2  config/routes.rb
@@ -1,6 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.namespace('tolk') do |tolk|
tolk.root :controller => 'locales'
- tolk.resources :locales, :member => {:all => :get}
+ tolk.resources :locales, :member => {:all => :get, :updated => :get}
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.