interpret 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ class Interpret::MissingTranslationsController < Interpret::BaseController
2
+ def index
3
+ unless I18n.locale == I18n.default_locale
4
+ res = ActiveRecord::Base.connection.execute("select t.value, t.key from
5
+ translations t where
6
+ t.locale ='#{I18n.default_locale}'
7
+ and (select count(*) from
8
+ translations t2 where
9
+ t2.key = t.key and
10
+ t2.locale ='#{I18n.locale}') =
11
+ 0")
12
+ @missing_translations = res.map{|x| {:ref_value => YAML.load(x["value"]), :key => x["key"]}}
13
+ end
14
+ end
15
+ end
@@ -1,9 +1,17 @@
1
1
  class Interpret::SearchController < Interpret::BaseController
2
-
3
- def perform
4
- t = Interpret::Translation.arel_table
5
- search_key = params[:key].split(" ").map{|x| "%#{CGI.escape(x)}%"}
6
- search_value = params[:value].split(" ").map{|x| "%#{CGI.escape(x)}%"}
7
- @translations = Interpret::Translation.locale(I18n.locale).where(t[:key].matches_all(search_key).or(t[:value].matches_all(search_value)) )
2
+ def index
3
+ if request.post?
4
+ opts = {}
5
+ opts[:key] = params[:key] if params[:key].present?
6
+ opts[:value] = params[:value] if params[:value].present?
7
+ redirect_to interpret_search_url(opts)
8
+ else
9
+ if params[:key].present? || params[:value].present?
10
+ t = Interpret::Translation.arel_table
11
+ search_key = params[:key].present? ? params[:key].split(" ").map{|x| "%#{CGI.escape(x)}%"} : []
12
+ search_value = params[:value].present? ? params[:value].split(" ").map{|x| "%#{CGI.escape(x)}%"} : []
13
+ @translations = Interpret::Translation.locale(I18n.locale).where(t[:key].matches_all(search_key).or(t[:value].matches_all(search_value)) )
14
+ end
15
+ end
8
16
  end
9
17
  end
@@ -55,27 +55,15 @@ class Interpret::TranslationsController < Interpret::BaseController
55
55
  end
56
56
  end
57
57
 
58
- def new
59
- @reference = Interpret::Translation.find(params[:translation_id])
60
- if @reference.locale === I18n.locale.to_s
61
- redirect_to interpret_root_path
62
- return
63
- end
64
- @translation = Interpret::Translation.new :locale => I18n.locale, :key => @reference.key
65
- end
66
-
67
58
  def create
68
- @reference = Interpret::Translation.find(params[:translation_id])
69
- if @reference.locale == I18n.locale.to_s
70
- redirect_to interpret_root_path
71
- return
72
- end
73
- @translation = Interpret::Translation.new params[:interpret_translation].merge(:locale => I18n.locale, :key => @reference.key)
59
+ @translation = Interpret::Translation.new params[:interpret_translation]
74
60
 
75
61
  if @translation.save
76
- redirect_to interpret_root_path(:locale => I18n.locale), :notice => "New translation created"
62
+ flash[:notice] = "New translation created for #{@translation.key}"
63
+ redirect_to request.env["HTTP_REFERER"]
77
64
  else
78
- render :action => :new
65
+ flash[:alert] = "Error when creating a new translation"
66
+ redirect_to request.env["HTTP_REFERER"]
79
67
  end
80
68
  end
81
69
 
@@ -20,6 +20,9 @@ module Interpret
20
20
  def expire_cache(key)
21
21
  end
22
22
 
23
+ def expire_cache_all
24
+ end
25
+
23
26
  private
24
27
  def run_expiration(record)
25
28
  Interpret.backend.reload! if Interpret.backend
@@ -2,7 +2,7 @@ module Interpret
2
2
 
3
3
  class Translation < I18n::Backend::ActiveRecord::Translation
4
4
  default_scope order('locale ASC')
5
- validates_presence_of :value
5
+ validates_uniqueness_of :key, :scope => :locale
6
6
 
7
7
  class << self
8
8
  # Generates a hash representing the tree structure of the translations
@@ -32,7 +32,7 @@ module Interpret
32
32
  translations.each do |e|
33
33
  LazyHash.add(res, "#{e.locale}.#{e.key}", e.value)
34
34
  end
35
- if res.keys.size != 1
35
+ if res.any? && res.keys.size != 1
36
36
  raise IndexError, "Generated hash must have only one root key. Your translation data in database may be corrupted."
37
37
  end
38
38
  res
@@ -58,7 +58,7 @@ module Interpret
58
58
  records.each do |x|
59
59
  if tr = locale(lang).find_by_key(x.key)
60
60
  tr.value = x.value
61
- tr.save!
61
+ tr.save(:validate => false)
62
62
  end
63
63
  end
64
64
  end
@@ -80,7 +80,7 @@ module Interpret
80
80
 
81
81
  # TODO: Replace with activerecord-import bulk inserts
82
82
  transaction do
83
- records.each {|x| x.save!}
83
+ records.each {|x| x.save(:validate => false)}
84
84
  end
85
85
  end
86
86
 
@@ -196,7 +196,8 @@ module Interpret
196
196
  trans = locale(lang).find_by_key(key)
197
197
  if trans.nil?
198
198
  if value = get_value_from_hash(@languages[lang], key)
199
- create! :locale => lang, :key => key, :value => value
199
+ foo = new( :locale => lang, :key => key, :value => value )
200
+ foo.save(:validate => false)
200
201
  Interpret.logger.info "New key created [#{key}] for language [#{lang}]"
201
202
  end
202
203
  end
@@ -212,7 +213,8 @@ module Interpret
212
213
  end
213
214
 
214
215
  def create_new_translation(missing_key, main_value)
215
- create! :locale => I18n.default_locale, :key => missing_key, :value => main_value
216
+ foo = new(:locale => I18n.default_locale, :key => missing_key, :value => main_value)
217
+ foo.save(:validate => false)
216
218
  Interpret.logger.info "New key created [#{missing_key}] for language [#{I18n.default_locale}]"
217
219
 
218
220
  check_in_other_langs(missing_key)
@@ -0,0 +1,33 @@
1
+ <% if I18n.locale == I18n.default_locale %>
2
+ <p>There can't be missing translations for the main language</p>
3
+ <% elsif @missing_translations.empty? %>
4
+ <p>There are no missing translations</p>
5
+ <% else %>
6
+ <p>There are <%= @missing_translations.size %> missing translations in [<%= I18n.locale %>]. You can
7
+ create them below and you can see the translation key and also the original
8
+ content in the reference language [ <%= I18n.default_locale %> ]
9
+ </p>
10
+ <table>
11
+ <thead>
12
+ <tr class="header">
13
+ <th>Key</th>
14
+ <th>Value in [ <%= I18n.default_locale %> ]</th>
15
+ <th>Your translation to [ <%= I18n.locale %> ]</th>
16
+ </tr>
17
+ </thead>
18
+ <% @missing_translations.each do |trans| %>
19
+ <tr>
20
+ <td><%= trans[:key] %></td>
21
+ <td><%= trans[:ref_value] %></td>
22
+ <td>
23
+ <%= form_for Interpret::Translation.new, :url => interpret_translations_path do |f| %>
24
+ <%= f.hidden_field "locale", :value => I18n.locale %>
25
+ <%= f.hidden_field "key", :value => trans[:key] %>
26
+ <%= f.text_area :value, :rows => 4, :cols => 60 %>
27
+ <%= submit_tag "Create" %>
28
+ <% end %>
29
+ </td>
30
+ </tr>
31
+ <% end %>
32
+ </table>
33
+ <% end %>
@@ -0,0 +1,32 @@
1
+ <% interpret_title "Interpret - Search" %>
2
+
3
+ <div id="header">
4
+ <h1>Search translations</h1>
5
+ </div>
6
+
7
+ <div id="search">
8
+ <p>Enter a search term for the key and/or the value of the translation</p>
9
+
10
+ <%= form_tag interpret_search_path do %>
11
+ <%= label_tag "key", "Key value" %>
12
+ <br />
13
+ <%= text_field_tag "key" %>
14
+ <br />
15
+
16
+ <%= label_tag "value", "Translation text" %>
17
+ <br />
18
+ <%= text_field_tag "value" %>
19
+ <br />
20
+
21
+ <%= submit_tag "SEARCH" %>
22
+
23
+ <% end %>
24
+
25
+ <% content_for :sidebar do %>
26
+ <h2>Search</h2>
27
+ <p>
28
+ You can use this search feature to look into all the translations. Can be filtered by language, key and phrase.
29
+ </p>
30
+ <% end %>
31
+ </div>
32
+
@@ -18,7 +18,7 @@
18
18
  <%= @translations.size %> results found.
19
19
  </p>
20
20
  <div id="side_search">
21
- <%= form_tag interpret_search_for_path do %>
21
+ <%= form_tag interpret_search_path do %>
22
22
  <%= label_tag "key", "Key value" %>
23
23
  <br />
24
24
  <%= text_field_tag "key", params[:key] %>
@@ -1,31 +1,5 @@
1
- <% interpret_title "Interpret - Search" %>
2
-
3
- <div id="header">
4
- <h1>Search translations</h1>
5
- </div>
6
-
7
- <div id="search">
8
- <p>Enter a search term for the key and/or the value of the translation</p>
9
-
10
- <%= form_tag interpret_search_for_path do %>
11
- <%= label_tag "key", "Key value" %>
12
- <br />
13
- <%= text_field_tag "key" %>
14
- <br />
15
-
16
- <%= label_tag "value", "Translation text" %>
17
- <br />
18
- <%= text_field_tag "value" %>
19
- <br />
20
-
21
- <%= submit_tag "SEARCH" %>
22
-
23
- <% end %>
24
-
25
- <% content_for :sidebar do %>
26
- <h2>Search</h2>
27
- <p>
28
- You can use this search feature to look into all the translations. Can be filtered by language, key and phrase.
29
- </p>
30
- <% end %>
31
- </div>
1
+ <% unless @translations %>
2
+ <%= render "blank_search" %>
3
+ <% else %>
4
+ <%= render "filled_search" %>
5
+ <% end %>
@@ -2,6 +2,7 @@
2
2
  <thead>
3
3
  <tr class="header">
4
4
  <% if @references %>
5
+ <th>Key</th>
5
6
  <th>Master translation [<%= I18n.default_locale %>]</th>
6
7
  <% else %>
7
8
  <th>Key</th>
@@ -39,6 +40,7 @@
39
40
  <% @references.each do |x| %>
40
41
  <% trans = @translations.detect{|y| y.key == x.key} %>
41
42
  <tr<%= " id='translation_#{trans.id}'" if trans %><%= " class='protected'" if x.protected %>>
43
+ <td style='width:5%'><%= x.key %></td>
42
44
  <td style='width:50%'><%= x.value %></td>
43
45
  <td style='width:50%'>
44
46
  <% if trans %>
@@ -48,7 +50,7 @@
48
50
  :activator => "#translation_#{trans.id}",
49
51
  :sanitize => false %>
50
52
  <% else %>
51
- <%= link_to "[Create missing translation]", new_interpret_translation_translation_path(x) %>
53
+ <%= link_to "Create this missing translation", interpret_missing_translations_path %>
52
54
  <% end %>
53
55
  </td>
54
56
  </tr>
@@ -10,7 +10,8 @@
10
10
  <% unless @interpret_user && !@interpret_admin %>
11
11
  <%= interpret_section_link_to "Tools", interpret_tools_path %> |
12
12
  <% end %>
13
- <%= interpret_section_link_to "Search", interpret_search_path %>
13
+ <%= interpret_section_link_to "Search", interpret_search_path %> |
14
+ <%= interpret_section_link_to "Missing translations", interpret_missing_translations_path %>
14
15
  <hr />
15
16
  </div>
16
17
  <div class="menu grid_4">
@@ -18,6 +19,7 @@
18
19
  <% Interpret::Translation.available_locales.each do |locale| %>
19
20
  <% opts = {:locale => locale} %>
20
21
  <% opts[:key] = params[:key] if params[:key] %>
22
+ <% opts[:value] = params[:value] if params[:value] %>
21
23
  <%= link_to locale, opts %>
22
24
  <% end %>
23
25
  <hr />
data/config/routes.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
  scope Interpret.scope do
3
3
  namespace :interpret do
4
- resources :translations, :only => [:edit, :update] do
5
- resources :translations, :only => [:new, :create]
6
-
4
+ resources :translations, :only => [:edit, :update, :create] do
7
5
  collection do
8
6
  get :live_edit
9
7
  end
@@ -19,7 +17,7 @@ Rails.application.routes.draw do
19
17
  end
20
18
 
21
19
  match "search", :to => "search#index"
22
- match "search_for", :to => "search#perform"
20
+ resources :missing_translations
23
21
 
24
22
  root :to => "translations#index"
25
23
  end
@@ -1,3 +1,3 @@
1
1
  module Interpret
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -2,12 +2,12 @@ namespace :interpret do
2
2
  desc 'Copy all the translations from config/locales/*.yml into DB backend'
3
3
  task :dump => :environment do
4
4
  Interpret::Translation.dump
5
- eval(Interpret.sweeper.classify).instance.send(:run_expiration) if Interpret.sweeper
5
+ eval(Interpret.sweeper.classify).instance.send(:expire_cache_all) if Interpret.sweeper
6
6
  end
7
7
 
8
8
  desc 'Synchronize the keys used in db backend with the ones on *.yml files'
9
9
  task :update => :environment do
10
10
  Interpret::Translation.update
11
- eval(Interpret.sweeper.classify).instance.send(:run_expiration) if Interpret.sweeper
11
+ eval(Interpret.sweeper.classify).instance.send(:expire_cache_all) if Interpret.sweeper
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interpret
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 5
10
- version: 0.1.5
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roger Campos
@@ -15,13 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-03 00:00:00 +02:00
19
- default_executable:
18
+ date: 2011-10-07 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: rails
23
22
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
27
26
  - - ~>
@@ -33,11 +32,11 @@ dependencies:
33
32
  - 3
34
33
  version: 3.0.3
35
34
  type: :runtime
36
- version_requirements: *id001
35
+ requirement: *id001
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: i18n
39
38
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
42
  - - ~>
@@ -49,11 +48,11 @@ dependencies:
49
48
  - 0
50
49
  version: 0.5.0
51
50
  type: :runtime
52
- version_requirements: *id002
51
+ requirement: *id002
53
52
  - !ruby/object:Gem::Dependency
54
53
  name: i18n-active_record
55
54
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
56
  none: false
58
57
  requirements:
59
58
  - - ">="
@@ -63,11 +62,11 @@ dependencies:
63
62
  - 0
64
63
  version: "0"
65
64
  type: :runtime
66
- version_requirements: *id003
65
+ requirement: *id003
67
66
  - !ruby/object:Gem::Dependency
68
67
  name: ya2yaml
69
68
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
70
  none: false
72
71
  requirements:
73
72
  - - ">="
@@ -79,11 +78,11 @@ dependencies:
79
78
  - 0
80
79
  version: 0.30.0
81
80
  type: :runtime
82
- version_requirements: *id004
81
+ requirement: *id004
83
82
  - !ruby/object:Gem::Dependency
84
83
  name: best_in_place
85
84
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
87
86
  none: false
88
87
  requirements:
89
88
  - - ">="
@@ -95,11 +94,11 @@ dependencies:
95
94
  - 7
96
95
  version: 0.1.7
97
96
  type: :runtime
98
- version_requirements: *id005
97
+ requirement: *id005
99
98
  - !ruby/object:Gem::Dependency
100
99
  name: lazyhash
101
100
  prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
103
102
  none: false
104
103
  requirements:
105
104
  - - ">="
@@ -111,11 +110,11 @@ dependencies:
111
110
  - 1
112
111
  version: 0.1.1
113
112
  type: :runtime
114
- version_requirements: *id006
113
+ requirement: *id006
115
114
  - !ruby/object:Gem::Dependency
116
115
  name: rspec-rails
117
116
  prerelease: false
118
- requirement: &id007 !ruby/object:Gem::Requirement
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
119
118
  none: false
120
119
  requirements:
121
120
  - - ~>
@@ -126,7 +125,7 @@ dependencies:
126
125
  - 5
127
126
  version: "2.5"
128
127
  type: :development
129
- version_requirements: *id007
128
+ requirement: *id007
130
129
  description: Manage your app translations with an i18n active_record backend
131
130
  email:
132
131
  - roger@itnig.net
@@ -142,13 +141,16 @@ files:
142
141
  - README.md
143
142
  - Rakefile
144
143
  - app/controllers/interpret/base_controller.rb
144
+ - app/controllers/interpret/missing_translations_controller.rb
145
145
  - app/controllers/interpret/search_controller.rb
146
146
  - app/controllers/interpret/tools_controller.rb
147
147
  - app/controllers/interpret/translations_controller.rb
148
148
  - app/models/interpret/expiration_observer.rb
149
149
  - app/models/interpret/translation.rb
150
+ - app/views/interpret/missing_translations/index.html.erb
151
+ - app/views/interpret/search/_blank_search.html.erb
152
+ - app/views/interpret/search/_filled_search.html.erb
150
153
  - app/views/interpret/search/index.html.erb
151
- - app/views/interpret/search/perform.html.erb
152
154
  - app/views/interpret/tools/index.html.erb
153
155
  - app/views/interpret/translations/_listing.html.erb
154
156
  - app/views/interpret/translations/index.html.erb
@@ -261,7 +263,6 @@ files:
261
263
  - test_app/public/stylesheets/private.css
262
264
  - test_app/script/rails
263
265
  - test_app/vendor/plugins/.gitkeep
264
- has_rdoc: true
265
266
  homepage: https://github.com/rogercampos/interpret
266
267
  licenses: []
267
268
 
@@ -291,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
292
  requirements: []
292
293
 
293
294
  rubyforge_project: interpret
294
- rubygems_version: 1.3.7
295
+ rubygems_version: 1.8.6
295
296
  signing_key:
296
297
  specification_version: 3
297
298
  summary: Manage your app translations with an i18n active_record backend