Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved translator admin panel.

  • Loading branch information...
commit 7210d272d4a6c7d8d85d3022e6d50218234c10aa 1 parent 74b1548
Shane Mingins authored
View
29 lib/controllers/translations_controller.rb
@@ -14,11 +14,17 @@ def index
end
end
- # GET /untranslated
- # GET /untranslated.xml
- def untranslated
+ # GET /translations
+ # GET /translations.xml
+ def translations
@locale ||= Locale.default_locale
- @translations = @locale.translations.untranslated
+ @translation_option = TranslationOption.find(params[:translation_option])
+
+ if @translation_option == TranslationOption.translated
+ @translations = @locale.translations.translated
+ else
+ @translations = @locale.translations.untranslated
+ end
respond_to do |format|
format.html # index.html.erb
@@ -26,14 +32,22 @@ def untranslated
end
end
- # GET /untranslated_assets
- # GET /untranslated_assets.xml
- def untranslated_assets
+ # GET /asset_translations
+ # GET /asset_translations.xml
+ def asset_translations
@locale ||= Locale.default_locale
+ @translation_option = TranslationOption.find(params[:translation_option])
+
@asset_translations = I18n.asset_translations
@untranslated_assets = I18n.untranslated_assets(@locale.code)
@percentage_translated = ( (@asset_translations.size - @untranslated_assets.size).to_f / @asset_translations.size.to_f * 100).round
+ if @translation_option == TranslationOption.translated
+ @asset_translations = @asset_translations.reject{|e| @untranslated_assets.include?(e)}
+ else
+ @asset_translations = @untranslated_assets
+ end
+
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @untranslated_assets }
@@ -88,6 +102,7 @@ def create
# PUT /translations/1.xml
def update
@translation = @locale.translations.find(params[:id])
+ @first_time_translating = @translation.value.nil?
respond_to do |format|
if @translation.update_attributes(params[:translation])
View
1  lib/i18n_backend_database.rb
@@ -1,5 +1,6 @@
require File.dirname(__FILE__) + '/models/locale'
require File.dirname(__FILE__) + '/models/translation'
+require File.dirname(__FILE__) + '/models/translation_option'
require File.dirname(__FILE__) + '/routing'
require File.dirname(__FILE__) + '/controllers/locales_controller'
require File.dirname(__FILE__) + '/controllers/translations_controller'
View
26 lib/models/translation_option.rb
@@ -0,0 +1,26 @@
+class TranslationOption
+
+ attr_accessor :code, :description
+ cattr_accessor :translated, :untranslated
+
+ def initialize(code, description)
+ @code, @description = code, description
+ end
+
+ def self.all
+ [untranslated, translated]
+ end
+
+ def self.translated
+ @@translated ||= TranslationOption.new('translated', 'Translated')
+ end
+
+ def self.untranslated
+ @@untranslated ||= TranslationOption.new('untranslated', 'Untranslated')
+ end
+
+ def self.find(code)
+ all.detect{|option| option.code == code} || untranslated
+ end
+
+end
View
4 lib/views/layouts/translations.html.erb
@@ -10,7 +10,9 @@
<%= javascript_include_tag 'jsProgressBarHandler.js' %>
</head>
<body>
-
+ <p>
+ <%= link_to 'Textual Translations', translations_url %> &middot; <%= link_to 'Asset Translations', asset_translations_url %>
+ </p>
<body class="content">
<div class="content">
<%= yield %>
View
28 lib/views/translations/asset_translations.html.erb
@@ -0,0 +1,28 @@
+<% form_tag asset_translations_url do -%>
+<%= select_tag :locale_id, options_from_collection_for_select(Locale.all, :code, :name, @locale.code) -%>
+<%= select_tag :translation_option, options_from_collection_for_select(TranslationOption.all, :code, :description, @translation_option.code) -%>
+<%= submit_tag 'Go' %>
+<% end -%>
+
+<script type="text/javascript">
+ Event.observe(window, 'load', function() {
+ myJsProgressBarHandler = new JS_BRAMUS.jsProgressBar($('translate_progress'), 0);
+ }, false);
+</script>
+
+<p>
+ Asset Translation progress: <span class="progressBar" id="translate_progress"><%= @percentage_translated %></span>
+</p>
+
+<h2><%= @translation_option.description %>: <%= @locale.name %></h2>
+
+<% if @asset_translations.empty? -%>
+ <h3>No records for this criteria.</h3>
+<% end -%>
+
+<% for asset in @asset_translations %>
+<p>
+ <%= image_tag(asset, :size => "50x50") %>
+ <%= link_to(asset, image_path(asset)) %>
+</p>
+<% end %>
View
34 lib/views/translations/translations.html.erb
@@ -0,0 +1,34 @@
+<% form_tag translations_url do -%>
+<%= select_tag :locale_id, options_from_collection_for_select(Locale.all, :code, :name, @locale.code) -%>
+<%= select_tag :translation_option, options_from_collection_for_select(TranslationOption.all, :code, :description, @translation_option.code) -%>
+<%= submit_tag 'Go' %>
+<% end -%>
+
+<script type="text/javascript">
+ Event.observe(window, 'load', function() {
+ myJsProgressBarHandler = new JS_BRAMUS.jsProgressBar($('translate_progress'), 0);
+ }, false);
+</script>
+
+<p>
+ Textual Translation progress: <span class="progressBar" id="translate_progress"><%= @locale.percentage_translated %></span>
+</p>
+
+<h2><%= @translation_option.description %>: <%= @locale.name %></h2>
+
+<% if @translations.empty? -%>
+ <h3>No records for this criteria.</h3>
+<% end -%>
+
+<% for translation in @translations %>
+ <div id="<%= "translation_#{translation.class}_#{translation.id}" %>">
+ <% remote_form_for([@locale, translation]) do |f| %>
+ <p><%=h translation.default_locale_value %></p>
+ <p>
+ <%= f.text_field :value %>
+ <%= f.submit "Update" %>
+ </p>
+ <% end %>
+ <hr/>
+ </div>
+<% end %>
View
30 lib/views/translations/untranslated.html.erb
@@ -1,30 +0,0 @@
-<p>
- <%= "Select locale" %>
- <% for locale in Locale.all %>
- <%= link_to locale.code, url_for(:locale_id => locale.code) %> &middot;
- <% end %>
-</p>
-
-<h1>Untranslated: <%= @locale.code %></h1>
- <script type="text/javascript">
- Event.observe(window, 'load', function() {
- myJsProgressBarHandler = new JS_BRAMUS.jsProgressBar($('translate_progress'), 0);
- }, false);
- </script>
-
-<span class="progressBar" id="translate_progress"><%= @locale.percentage_translated %></span>
-
-
-<% for translation in @translations %>
- <div id="<%= "translation_#{translation.class}_#{translation.id}" %>">
- <% remote_form_for([@locale, translation]) do |f| %>
- <p><%=h translation.default_locale_value %></p>
- <p><%=h translation.value %></p>
- <p>
- <%= f.text_field :value %>
- <%= f.submit "Update" %>
- </p>
- <% end %>
- <hr/>
- </div>
-<% end %>
View
22 lib/views/translations/untranslated_assets.html.erb
@@ -1,22 +0,0 @@
-<p>
- <%= "Select locale" %>
- <% for locale in Locale.all %>
- <%= link_to locale.code, url_for(:locale_id => locale.code) %> &middot;
- <% end %>
-</p>
-
-<h1>Untranslated: <%= @locale.code %></h1>
- <script type="text/javascript">
- Event.observe(window, 'load', function() {
- myJsProgressBarHandler = new JS_BRAMUS.jsProgressBar($('translate_progress'), 0);
- }, false);
- </script>
-
-<span class="progressBar" id="translate_progress"><%= @percentage_translated %></span>
-
-<% for asset in @untranslated_assets %>
-<p>
- <%= image_tag(asset, :size => "50x50") %>
- <%= link_to(asset, image_path(asset)) %>
-</p>
-<% end %>
View
12 lib/views/translations/update.rjs
@@ -1,5 +1,7 @@
-# update the percentage
-page.call 'myJsProgressBarHandler.setPercentage', @locale.percentage_translated, true
-
-# remove the translation div
-page.remove("translation_#{@translation.class}_#{@translation.id}")
+# update the percentage and remove the translated record if translated for first time otherwise highlight change
+if @first_time_translating
+ page.call 'myJsProgressBarHandler.setPercentage', @locale.percentage_translated, true
+ page.remove("translation_#{@translation.class}_#{@translation.id}")
+else
+ page.visual_effect :highlight, "translation_#{@translation.class}_#{@translation.id}"
+end
View
4 routes.rb
@@ -1,3 +1,3 @@
map.resources :locales, :has_many => :translations
-map.untranslated '/untranslated', :controller => 'translations', :action => 'untranslated'
-map.untranslated_assets '/untranslated_assets', :controller => 'translations', :action => 'untranslated_assets'
+map.translations '/translations', :controller => 'translations', :action => 'translations'
+map.asset_translations '/asset_translations', :controller => 'translations', :action => 'asset_translations'
View
3  spec/controllers/translations_controller_spec.rb
@@ -12,6 +12,9 @@ def mock_locale(stubs={})
end
def mock_translation(stubs={})
+ stubs = {
+ :value => nil
+ }.merge(stubs)
@mock_translation ||= mock_model(Translation, stubs)
end
Please sign in to comment.
Something went wrong with that request. Please try again.