Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes for 3.1.x

1. Removed 'protected' in TranslateController, as actions must be
public.
2. Bind routes to specific HTTP method.
  • Loading branch information...
commit 4f62e748b475e62d0367ef76496e43dd34165fa1 1 parent 9a15b32
@romanbsd authored
Showing with 23 additions and 28 deletions.
  1. +19 −24 app/controllers/translate_controller.rb
  2. +4 −4 config/routes.rb
View
43 app/controllers/translate_controller.rb
@@ -1,20 +1,13 @@
class TranslateController < ActionController::Base
# It seems users with active_record_store may get a "no :secret given" error if we don't disable csrf protection,
skip_before_filter :verify_authenticity_token
-
-# password = `hostname`.chomp
-# Rails.logger.info("The translation password is #{password}")
-# http_basic_authenticate_with :name => "translate", :password => password
- protected
-
-
- prepend_view_path(File.join(File.dirname(__FILE__), "..", "views"))
layout 'translate'
before_filter :init_translations
before_filter :set_locale
-
+
+ # GET /translate
def index
initialize_keys
filter_by_key_pattern
@@ -24,9 +17,10 @@ def index
paginate_keys
@total_entries = @keys.size
end
-
+
+ # POST /translate
def translate
- processed_parameters = process_array_parameters(params[:key])
+ processed_parameters = process_array_parameters(params[:key])
I18n.backend.store_translations(@to_locale, Translate::Keys.to_deep_hash(processed_parameters))
Translate::Storage.new(@to_locale).write_to_file
Translate::Log.new(@from_locale, @to_locale, params[:key].keys).write_to_file
@@ -35,20 +29,21 @@ def translate
redirect_to params.slice(:filter, :sort_by, :key_type, :key_pattern, :text_type, :text_pattern).merge({:action => :index})
end
+ # GET /translate/reload
def reload
Translate::Keys.files = nil
redirect_to :action => 'index'
end
-
+
private
def initialize_keys
@files = Translate::Keys.files
- @keys = (@files.keys.map(&:to_s) + Translate::Keys.new.i18n_keys(@from_locale)).uniq
+ @keys = (@files.keys.map(&:to_s) + Translate::Keys.new.i18n_keys(@from_locale)).uniq
@keys.reject! do |key|
from_text = lookup(@from_locale, key)
# When translating from one language to another, make sure there is a text to translate from.
# The only supported formats are String and Array. We don't support other formats
- (@from_locale != @to_locale && !from_text.present?) || (from_text.present? && !from_text.is_a?(String) && !from_text.is_a?(Array))
+ (@from_locale != @to_locale && !from_text.present?) || (from_text.present? && !from_text.is_a?(String) && !from_text.is_a?(Array))
end
end
@@ -56,7 +51,7 @@ def lookup(locale, key)
I18n.backend.send(:lookup, locale, key)
end
helper_method :lookup
-
+
def filter_by_translated_or_changed
params[:filter] ||= 'all'
return if params[:filter] == 'all'
@@ -73,7 +68,7 @@ def filter_by_translated_or_changed
end
end
end
-
+
def filter_by_key_pattern
return if params[:key_pattern].blank?
@keys.reject! do |key|
@@ -121,7 +116,7 @@ def sort_keys
raise "Unknown sort_by '#{params[:sort_by]}'"
end
end
-
+
def paginate_keys
params[:page] ||= 1
@paginated_keys = @keys[offset, per_page]
@@ -130,24 +125,24 @@ def paginate_keys
def offset
(params[:page].to_i - 1) * per_page
end
-
+
def per_page
50
end
helper_method :per_page
-
+
def init_translations
- I18n.backend.send(:init_translations) unless I18n.backend.initialized?
+ I18n.backend.send(:init_translations) unless I18n.backend.initialized?
end
def force_init_translations
I18n.backend.send(:init_translations)
end
-
+
def default_locale
I18n.default_locale
end
-
+
def set_locale
session[:from_locale] ||= default_locale
session[:to_locale] ||= :en
@@ -156,7 +151,7 @@ def set_locale
@from_locale = session[:from_locale].to_sym
@to_locale = session[:to_locale].to_sym
end
-
+
def old_from_text(key)
return @old_from_text[key] if @old_from_text && @old_from_text[key]
@old_from_text = {}
@@ -166,7 +161,7 @@ def old_from_text(key)
@old_from_text[key] = text
end
helper_method :old_from_text
-
+
def log_hash
@log_hash ||= Translate::Log.new(@from_locale, @to_locale, {}).read
end
View
8 config/routes.rb
@@ -1,5 +1,5 @@
Rails.application.routes.draw do
- match 'translate' => 'translate#index', :as => :translate_list
- match 'translate/translate' => 'translate#translate', :as => :translate
- match 'translate/reload' => 'translate#reload', :as => :translate_reload
-end
+ get 'translate' => 'translate#index', :as => :translate_list
+ post 'translate' => 'translate#translate', :as => :translate
+ get 'translate/reload' => 'translate#reload', :as => :translate_reload
+end
Please sign in to comment.
Something went wrong with that request. Please try again.