translate-rails3 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -1,20 +1,13 @@
1
1
  class TranslateController < ActionController::Base
2
2
  # It seems users with active_record_store may get a "no :secret given" error if we don't disable csrf protection,
3
3
  skip_before_filter :verify_authenticity_token
4
-
5
- # password = `hostname`.chomp
6
- # Rails.logger.info("The translation password is #{password}")
7
- # http_basic_authenticate_with :name => "translate", :password => password
8
4
 
9
- protected
10
-
11
-
12
- prepend_view_path(File.join(File.dirname(__FILE__), "..", "views"))
13
5
  layout 'translate'
14
6
 
15
7
  before_filter :init_translations
16
8
  before_filter :set_locale
17
-
9
+
10
+ # GET /translate
18
11
  def index
19
12
  initialize_keys
20
13
  filter_by_key_pattern
@@ -24,9 +17,10 @@ class TranslateController < ActionController::Base
24
17
  paginate_keys
25
18
  @total_entries = @keys.size
26
19
  end
27
-
20
+
21
+ # POST /translate
28
22
  def translate
29
- processed_parameters = process_array_parameters(params[:key])
23
+ processed_parameters = process_array_parameters(params[:key])
30
24
  I18n.backend.store_translations(@to_locale, Translate::Keys.to_deep_hash(processed_parameters))
31
25
  Translate::Storage.new(@to_locale).write_to_file
32
26
  Translate::Log.new(@from_locale, @to_locale, params[:key].keys).write_to_file
@@ -35,20 +29,21 @@ class TranslateController < ActionController::Base
35
29
  redirect_to params.slice(:filter, :sort_by, :key_type, :key_pattern, :text_type, :text_pattern).merge({:action => :index})
36
30
  end
37
31
 
32
+ # GET /translate/reload
38
33
  def reload
39
34
  Translate::Keys.files = nil
40
35
  redirect_to :action => 'index'
41
36
  end
42
-
37
+
43
38
  private
44
39
  def initialize_keys
45
40
  @files = Translate::Keys.files
46
- @keys = (@files.keys.map(&:to_s) + Translate::Keys.new.i18n_keys(@from_locale)).uniq
41
+ @keys = (@files.keys.map(&:to_s) + Translate::Keys.new.i18n_keys(@from_locale)).uniq
47
42
  @keys.reject! do |key|
48
43
  from_text = lookup(@from_locale, key)
49
44
  # When translating from one language to another, make sure there is a text to translate from.
50
45
  # The only supported formats are String and Array. We don't support other formats
51
- (@from_locale != @to_locale && !from_text.present?) || (from_text.present? && !from_text.is_a?(String) && !from_text.is_a?(Array))
46
+ (@from_locale != @to_locale && !from_text.present?) || (from_text.present? && !from_text.is_a?(String) && !from_text.is_a?(Array))
52
47
  end
53
48
  end
54
49
 
@@ -56,7 +51,7 @@ class TranslateController < ActionController::Base
56
51
  I18n.backend.send(:lookup, locale, key)
57
52
  end
58
53
  helper_method :lookup
59
-
54
+
60
55
  def filter_by_translated_or_changed
61
56
  params[:filter] ||= 'all'
62
57
  return if params[:filter] == 'all'
@@ -73,7 +68,7 @@ class TranslateController < ActionController::Base
73
68
  end
74
69
  end
75
70
  end
76
-
71
+
77
72
  def filter_by_key_pattern
78
73
  return if params[:key_pattern].blank?
79
74
  @keys.reject! do |key|
@@ -121,7 +116,7 @@ class TranslateController < ActionController::Base
121
116
  raise "Unknown sort_by '#{params[:sort_by]}'"
122
117
  end
123
118
  end
124
-
119
+
125
120
  def paginate_keys
126
121
  params[:page] ||= 1
127
122
  @paginated_keys = @keys[offset, per_page]
@@ -130,24 +125,24 @@ class TranslateController < ActionController::Base
130
125
  def offset
131
126
  (params[:page].to_i - 1) * per_page
132
127
  end
133
-
128
+
134
129
  def per_page
135
130
  50
136
131
  end
137
132
  helper_method :per_page
138
-
133
+
139
134
  def init_translations
140
- I18n.backend.send(:init_translations) unless I18n.backend.initialized?
135
+ I18n.backend.send(:init_translations) unless I18n.backend.initialized?
141
136
  end
142
137
 
143
138
  def force_init_translations
144
139
  I18n.backend.send(:init_translations)
145
140
  end
146
-
141
+
147
142
  def default_locale
148
143
  I18n.default_locale
149
144
  end
150
-
145
+
151
146
  def set_locale
152
147
  session[:from_locale] ||= default_locale
153
148
  session[:to_locale] ||= :en
@@ -156,7 +151,7 @@ class TranslateController < ActionController::Base
156
151
  @from_locale = session[:from_locale].to_sym
157
152
  @to_locale = session[:to_locale].to_sym
158
153
  end
159
-
154
+
160
155
  def old_from_text(key)
161
156
  return @old_from_text[key] if @old_from_text && @old_from_text[key]
162
157
  @old_from_text = {}
@@ -166,7 +161,7 @@ class TranslateController < ActionController::Base
166
161
  @old_from_text[key] = text
167
162
  end
168
163
  helper_method :old_from_text
169
-
164
+
170
165
  def log_hash
171
166
  @log_hash ||= Translate::Log.new(@from_locale, @to_locale, {}).read
172
167
  end
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  Rails.application.routes.draw do
2
- match 'translate' => 'translate#index', :as => :translate_list
3
- match 'translate/translate' => 'translate#translate', :as => :translate
4
- match 'translate/reload' => 'translate#reload', :as => :translate_reload
5
- end
2
+ get 'translate' => 'translate#index', :as => :translate_list
3
+ post 'translate' => 'translate#translate', :as => :translate
4
+ get 'translate/reload' => 'translate#reload', :as => :translate_reload
5
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "translate-rails3"
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Marklund", "Milan Novota", "Roman Shterenzon"]
12
- s.date = "2012-01-16"
12
+ s.date = "2012-01-22"
13
13
  s.description = "This plugin provides a web interface for translating Rails I18n texts\n(requires Rails 3.0 or higher) from one locale to another.\nThe plugin has been tested only with the simple I18n backend that ships\nwith Rails.\nI18n texts are read from and written to YAML files under config/locales.\n\nThis gem is a fork of the original https://github.com/mynewsdesk/translate\nand also includes work from this fork: https://github.com/milann/translate\n"
14
14
  s.email = "romanbsd@yahoo.com"
15
15
  s.extra_rdoc_files = [
@@ -52,7 +52,7 @@ Gem::Specification.new do |s|
52
52
  ]
53
53
  s.homepage = "https://github.com/romanbsd/translate"
54
54
  s.require_paths = ["lib"]
55
- s.rubygems_version = "1.8.11"
55
+ s.rubygems_version = "1.8.15"
56
56
  s.summary = "Newsdesk translate plugin for Rails 3"
57
57
 
58
58
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: translate-rails3
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.2
5
+ version: 0.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Peter Marklund
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2012-01-16 00:00:00 Z
15
+ date: 2012-01-22 00:00:00 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: ya2yaml
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  requirements: []
100
100
 
101
101
  rubyforge_project:
102
- rubygems_version: 1.8.11
102
+ rubygems_version: 1.8.15
103
103
  signing_key:
104
104
  specification_version: 3
105
105
  summary: Newsdesk translate plugin for Rails 3