lit 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +17 -0
  3. data/Rakefile +1 -4
  4. data/app/controllers/lit/api/v1/base_controller.rb +5 -5
  5. data/app/controllers/lit/api/v1/locales_controller.rb +2 -2
  6. data/app/controllers/lit/api/v1/localization_keys_controller.rb +2 -3
  7. data/app/controllers/lit/api/v1/localizations_controller.rb +2 -2
  8. data/app/controllers/lit/application_controller.rb +12 -11
  9. data/app/controllers/lit/dashboard_controller.rb +1 -1
  10. data/app/controllers/lit/incomming_localizations_controller.rb +13 -6
  11. data/app/controllers/lit/locales_controller.rb +5 -5
  12. data/app/controllers/lit/localization_keys_controller.rb +57 -57
  13. data/app/controllers/lit/localizations_controller.rb +16 -15
  14. data/app/controllers/lit/sources_controller.rb +13 -12
  15. data/app/helpers/lit/application_helper.rb +0 -1
  16. data/app/helpers/lit/localizations_helper.rb +1 -1
  17. data/app/models/lit/incomming_localization.rb +29 -26
  18. data/app/models/lit/locale.rb +21 -11
  19. data/app/models/lit/localization.rb +27 -26
  20. data/app/models/lit/localization_key.rb +19 -20
  21. data/app/models/lit/localization_version.rb +1 -1
  22. data/app/models/lit/source.rb +51 -47
  23. data/app/views/lit/incomming_localizations/accept.js.erb +2 -0
  24. data/app/views/lit/incomming_localizations/destroy.js.erb +1 -0
  25. data/app/views/lit/incomming_localizations/index.html.erb +5 -5
  26. data/app/views/lit/localization_keys/index.html.erb +1 -1
  27. data/app/views/lit/localizations/_form.html.erb +1 -1
  28. data/app/views/lit/localizations/_previous_versions_rows.html.erb +2 -2
  29. data/app/views/lit/sources/index.html.erb +4 -1
  30. data/lib/generators/lit/install_generator.rb +16 -16
  31. data/lib/lit.rb +13 -8
  32. data/lib/lit/adapters/hash_storage.rb +1 -1
  33. data/lib/lit/adapters/redis_storage.rb +30 -22
  34. data/lib/lit/cache.rb +128 -125
  35. data/lib/lit/engine.rb +1 -2
  36. data/lib/lit/i18n_backend.rb +59 -12
  37. data/lib/lit/loader.rb +1 -2
  38. data/lib/lit/railtie.rb +5 -5
  39. data/lib/lit/version.rb +1 -1
  40. data/lib/tasks/lit_tasks.rake +3 -3
  41. metadata +38 -32
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7da8c1d5b37a875b54f3640e3767b5101a9aaf15
4
+ data.tar.gz: b14573576174aa805d17189bd1c2b9e9419d0d71
5
+ SHA512:
6
+ metadata.gz: 170e2b67f08b84f893b5a0f1ce7c94122aaa39798835ab6cc1fe754e236785946f02d3d293dedc47dce0b325165aba039376e2ee69f32fdd67e09c59f91f0a01
7
+ data.tar.gz: eb22474f0ec620b6d1ed2219da048b01231ea2bbd2c541c405d86099e1d1faa6b4b6c5ffa9647b22c81dedad19e8564bfa20b4e3415467e141ec337f17917b9d
data/README.md CHANGED
@@ -30,6 +30,18 @@ Once you call `I18n.t()` function from your views, *Lit* is asked whether it has
30
30
 
31
31
  To optimize translation key lookup, *Lit* can use different cache engines. For production with many workers `redis` is suggested, for local development `hash` will be fine (`hash` is stored in memory, so if you have many workers and will update translation value in backend, only one worker will have proper translation in it's cache - db will be updated anyway).
32
32
 
33
+ Keys ending with `_html` have auto wysiwyg support.
34
+
35
+ You can also export translations using rake task
36
+ ```bash
37
+ $ rake lit:export
38
+ ```
39
+ You may also give it extra env variables to limit the export results.
40
+ ```bash
41
+ $ LOCALES=en,de rake lit:export
42
+ ```
43
+
44
+
33
45
  ### Installation
34
46
 
35
47
  1. Add `lit` gem to your `Gemfile`
@@ -37,6 +49,8 @@ To optimize translation key lookup, *Lit* can use different cache engines. For p
37
49
  gem 'lit'
38
50
  ```
39
51
 
52
+ For Ruby < 1.9 use `gem 'lit', '= 0.2.4'`, as next versions introduced new ruby hash syntax.
53
+
40
54
  2. run `bundle install`
41
55
 
42
56
  3. run installation generator `bundle exec rails g lit:install`
@@ -65,6 +79,9 @@ You may want to take a look at generated initializer in `config/initializers/lit
65
79
  * Integration with ActiveAdmin
66
80
  * Support for Proc defaults (like in `I18n.t('not_exising_keys', default: lambda{|_, options| 'text'})` )
67
81
 
82
+ ### Testing
83
+
84
+ For local testing [wwtd](https://github.com/grosser/wwtd) gem comes into play, run tests via: `wwtd --local`. Run migrations using command `RAILS_ENV=test bundle exec rake db:migrate`.
68
85
 
69
86
  ### License
70
87
 
data/Rakefile CHANGED
@@ -13,7 +13,6 @@ rescue LoadError
13
13
  RDoc::Task = Rake::RDocTask
14
14
  end
15
15
 
16
-
17
16
  RDoc::Task.new(:rdoc) do |rdoc|
18
17
  rdoc.rdoc_dir = 'rdoc'
19
18
  rdoc.title = 'Lit'
@@ -22,7 +21,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
22
21
  rdoc.rdoc_files.include('lib/**/*.rb')
23
22
  end
24
23
 
25
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
26
25
  load 'rails/tasks/engine.rake'
27
26
 
28
27
  Bundler::GemHelper.install_tasks
@@ -36,5 +35,3 @@ Rake::TestTask.new(:test) do |t|
36
35
  t.pattern = 'test/**/*_test.rb'
37
36
  t.verbose = false
38
37
  end
39
-
40
-
@@ -6,13 +6,13 @@ module Lit
6
6
  respond_to :json
7
7
  before_filter :authenticate_requests!
8
8
 
9
-
10
9
  private
11
- def authenticate_requests!
12
- authenticate_or_request_with_http_token do |token, options|
13
- Lit.api_key == token
14
- end
10
+
11
+ def authenticate_requests!
12
+ authenticate_or_request_with_http_token do |token, _options|
13
+ Lit.api_key == token
15
14
  end
15
+ end
16
16
  end
17
17
  end
18
18
  end
@@ -1,4 +1,4 @@
1
- require_dependency "lit/api/v1/base_controller"
1
+ require_dependency 'lit/api/v1/base_controller'
2
2
 
3
3
  module Lit
4
4
  module Api
@@ -6,7 +6,7 @@ module Lit
6
6
  class LocalesController < Api::V1::BaseController
7
7
  def index
8
8
  @locales = Locale.all
9
- render :json=>@locales.as_json(:root=>false, :only=>[:id, :locale])
9
+ render json: @locales.as_json(root: false, only: [:id, :locale])
10
10
  end
11
11
  end
12
12
  end
@@ -1,4 +1,4 @@
1
- require_dependency "lit/api/v1/base_controller"
1
+ require_dependency 'lit/api/v1/base_controller'
2
2
 
3
3
  module Lit
4
4
  class Api::V1::LocalizationKeysController < Api::V1::BaseController
@@ -9,8 +9,7 @@ module Lit
9
9
  else
10
10
  @localization_keys = @localization_keys.all
11
11
  end
12
- render :json=>@localization_keys.as_json(:root=>false, :only=>[:id, :localization_key])
12
+ render json: @localization_keys.as_json(root: false, only: [:id, :localization_key])
13
13
  end
14
14
  end
15
15
  end
16
-
@@ -7,12 +7,12 @@ module Lit
7
7
  else
8
8
  @localizations = @localizations.all
9
9
  end
10
- render :json=>@localizations.as_json(:root=>false, :only=>[:id, :localization_key_id, :locale_id], :methods=>[:value, :localization_key_str, :locale_str])
10
+ render json: @localizations.as_json(root: false, only: [:id, :localization_key_id, :locale_id], methods: [:value, :localization_key_str, :locale_str])
11
11
  end
12
12
 
13
13
  def last_change
14
14
  @localization = Localization.order('updated_at DESC').first
15
- render :json=>@localization.as_json(:root=>false, :only=>[], :methods=>[:last_change])
15
+ render json: @localization.as_json(root: false, only: [], methods: [:last_change])
16
16
  end
17
17
  end
18
18
  end
@@ -5,18 +5,19 @@ module Lit
5
5
  after_filter :restore_hits_counter
6
6
 
7
7
  private
8
- def authenticate
9
- if Lit.authentication_function.present?
10
- send(Lit.authentication_function)
11
- end
12
- end
13
8
 
14
- def stop_hits_counter
15
- Lit.init.cache.stop_hits_counter
16
- end
9
+ def authenticate
10
+ return unless Lit.authentication_function.present?
17
11
 
18
- def restore_hits_counter
19
- Lit.init.cache.restore_hits_counter
20
- end
12
+ send(Lit.authentication_function)
13
+ end
14
+
15
+ def stop_hits_counter
16
+ Lit.init.cache.stop_hits_counter
17
+ end
18
+
19
+ def restore_hits_counter
20
+ Lit.init.cache.restore_hits_counter
21
+ end
21
22
  end
22
23
  end
@@ -1,4 +1,4 @@
1
- require_dependency "lit/application_controller"
1
+ require_dependency 'lit/application_controller'
2
2
 
3
3
  module Lit
4
4
  class DashboardController < ::Lit::ApplicationController
@@ -1,4 +1,4 @@
1
- require_dependency "lit/application_controller"
1
+ require_dependency 'lit/application_controller'
2
2
 
3
3
  module Lit
4
4
  class IncommingLocalizationsController < ApplicationController
@@ -12,7 +12,10 @@ module Lit
12
12
  @incomming_localization = @source.incomming_localizations.find(params[:id].to_i)
13
13
  @incomming_localization.accept
14
14
  Lit.init.cache.refresh_key @incomming_localization.full_key
15
- redirect_to :back
15
+ respond_to do |format|
16
+ format.html { redirect_to :back }
17
+ format.js
18
+ end
16
19
  end
17
20
 
18
21
  def accept_all
@@ -31,12 +34,16 @@ module Lit
31
34
  def destroy
32
35
  @incomming_localization = @source.incomming_localizations.find(params[:id].to_i)
33
36
  @incomming_localization.destroy
34
- redirect_to source_incomming_localizations_path(@source)
37
+ respond_to do |format|
38
+ format.html { redirect_to source_incomming_localizations_path(@source) }
39
+ format.js
40
+ end
35
41
  end
36
42
 
37
43
  private
38
- def find_source
39
- @source = Source.find(params[:source_id].to_i)
40
- end
44
+
45
+ def find_source
46
+ @source = Source.find(params[:source_id].to_i)
47
+ end
41
48
  end
42
49
  end
@@ -1,27 +1,27 @@
1
- require_dependency "lit/application_controller"
1
+ require_dependency 'lit/application_controller'
2
2
 
3
3
  module Lit
4
4
  class LocalesController < ApplicationController
5
5
  def index
6
6
  @locales = Locale.ordered.all
7
-
7
+
8
8
  respond_to do |format|
9
9
  format.html # index.html.erb
10
10
  format.json { render json: @locales }
11
11
  end
12
12
  end
13
-
13
+
14
14
  def hide
15
15
  @locale = Locale.find(params[:id])
16
16
  @locale.is_hidden = !@locale.is_hidden?
17
17
  @locale.save
18
18
  respond_to :js
19
19
  end
20
-
20
+
21
21
  def destroy
22
22
  @locale = Locale.find(params[:id])
23
23
  @locale.destroy
24
-
24
+
25
25
  respond_to do |format|
26
26
  format.html { redirect_to locales_url }
27
27
  format.json { head :no_content }
@@ -1,19 +1,19 @@
1
1
  module Lit
2
2
  class LocalizationKeysController < ::Lit::ApplicationController
3
- before_filter :get_localization_scope, :except=>[:destroy]
3
+ before_filter :get_localization_scope, except: [:destroy]
4
4
 
5
5
  def index
6
6
  get_localization_keys
7
7
  end
8
8
 
9
9
  def starred
10
- @scope = @scope.where(:is_starred=>true)
10
+ @scope = @scope.where(is_starred: true)
11
11
 
12
- if @scope.respond_to?(:page)
13
- @scope = @scope.page(params[:page])
12
+ if defined?(Kaminari) and @scope.respond_to?(Kaminari.config.page_method_name)
13
+ @scope = @scope.send(Kaminari.config.page_method_name, params[:page])
14
14
  end
15
15
  get_localization_keys
16
- render :action=>:index
16
+ render action: :index
17
17
  end
18
18
 
19
19
  def star
@@ -33,72 +33,72 @@ module Lit
33
33
  end
34
34
 
35
35
  private
36
- def get_localization_scope
37
- @search_options = params.slice(*valid_keys)
38
- @search_options[:include_completed] = '1' if @search_options.empty?
39
- @scope = LocalizationKey.uniq.preload(:localizations => :locale).search(@search_options)
40
- end
41
36
 
42
- def get_localization_keys
43
- key_parts = @search_options[:key_prefix].to_s.split('.').length
44
- @prefixes = @scope.reorder(nil).uniq.pluck(:localization_key).map{|lk| lk.split('.').shift(key_parts+1).join('.') }.uniq.sort
45
- if @search_options[:key_prefix].present?
46
- parts = @search_options[:key_prefix].split('.')
47
- @parent_prefix = parts[0,parts.length-1].join('.')
48
- end
49
- if @scope.respond_to?(:page)
50
- @localization_keys = @scope.page(params[:page])
51
- else
52
- @localization_keys = @scope.all
53
- end
54
- end
37
+ def get_localization_scope
38
+ @search_options = params.slice(*valid_keys)
39
+ @search_options[:include_completed] = '1' if @search_options.empty?
40
+ @scope = LocalizationKey.uniq.preload(localizations: :locale).search(@search_options)
41
+ end
55
42
 
56
- def valid_keys
57
- %w( key include_completed key_prefix order )
43
+ def get_localization_keys
44
+ key_parts = @search_options[:key_prefix].to_s.split('.').length
45
+ @prefixes = @scope.reorder(nil).uniq.pluck(:localization_key).map { |lk| lk.split('.').shift(key_parts + 1).join('.') }.uniq.sort
46
+ if @search_options[:key_prefix].present?
47
+ parts = @search_options[:key_prefix].split('.')
48
+ @parent_prefix = parts[0, parts.length - 1].join('.')
49
+ end
50
+ if defined?(Kaminari) and @scope.respond_to?(Kaminari.config.page_method_name)
51
+ @localization_keys = @scope.send(Kaminari.config.page_method_name, params[:page])
52
+ else
53
+ @localization_keys = @scope.all
58
54
  end
55
+ end
59
56
 
60
- def grouped_localizations
61
- @_grouped_localizations ||= begin
62
- {}.tap do |hash|
63
- @localization_keys.each do |lk|
64
- hash[lk] = {}
65
- lk.localizations.each do |l|
66
- hash[lk][l.locale.locale.to_sym] = l
67
- end
57
+ def valid_keys
58
+ %w( key include_completed key_prefix order )
59
+ end
60
+
61
+ def grouped_localizations
62
+ @_grouped_localizations ||= begin
63
+ {}.tap do |hash|
64
+ @localization_keys.each do |lk|
65
+ hash[lk] = {}
66
+ lk.localizations.each do |l|
67
+ hash[lk][l.locale.locale.to_sym] = l
68
68
  end
69
69
  end
70
70
  end
71
71
  end
72
+ end
72
73
 
73
- def localization_for(locale, localization_key)
74
- @_localization_for ||= {}
75
- key = [locale, localization_key]
76
- ret = @_localization_for[key]
77
- if ret == false
78
- nil
79
- elsif ret.nil?
80
- ret = grouped_localizations[localization_key][locale]
81
- unless ret
82
- Lit.init.cache.refresh_key("#{locale}.#{localization_key.localization_key}")
83
- ret = localization_key.localizations.where(:locale_id=>Lit.init.cache.find_locale(locale).id).first
84
- end
85
- @_localization_for[key] = ret ? ret : false
86
- else
87
- ret
74
+ def localization_for(locale, localization_key)
75
+ @_localization_for ||= {}
76
+ key = [locale, localization_key]
77
+ ret = @_localization_for[key]
78
+ if ret == false
79
+ nil
80
+ elsif ret.nil?
81
+ ret = grouped_localizations[localization_key][locale]
82
+ unless ret
83
+ Lit.init.cache.refresh_key("#{locale}.#{localization_key.localization_key}")
84
+ ret = localization_key.localizations.where(locale_id: Lit.init.cache.find_locale(locale).id).first
88
85
  end
89
-
86
+ @_localization_for[key] = ret ? ret : false
87
+ else
88
+ ret
90
89
  end
90
+ end
91
91
 
92
- helper_method :localization_for
92
+ helper_method :localization_for
93
93
 
94
- def has_versions?(localization)
95
- @_versions ||= begin
96
- ids = grouped_localizations.values.map(&:values).flatten.map(&:id)
97
- Lit::Localization.where(:id => ids).joins(:versions).group("#{Lit::Localization.quoted_table_name}.id").count
98
- end
99
- @_versions[localization.id].to_i > 0
94
+ def has_versions?(localization)
95
+ @_versions ||= begin
96
+ ids = grouped_localizations.values.map(&:values).flatten.map(&:id)
97
+ Lit::Localization.where(id: ids).joins(:versions).group("#{Lit::Localization.quoted_table_name}.id").count
100
98
  end
99
+ @_versions[localization.id].to_i > 0
100
+ end
101
101
 
102
- helper_method :has_versions?
102
+ helper_method :has_versions?
103
103
  end
104
104
  end
@@ -22,25 +22,26 @@ module Lit
22
22
  end
23
23
 
24
24
  private
25
- def find_localization_key
26
- @localization_key = Lit::LocalizationKey.find(params[:localization_key_id])
27
- end
28
25
 
29
- def find_localization
30
- @localization = @localization_key.localizations.find(params[:id])
31
- end
26
+ def find_localization_key
27
+ @localization_key = Lit::LocalizationKey.find(params[:localization_key_id])
28
+ end
32
29
 
33
- def clear_params
34
- if defined?(::ActionController::StrongParameters)
35
- # allow translated_value to be an array
36
- if @localization.value.is_a?(Array)
37
- params.require(:localization).permit(:locale_id, :translated_value => [])
38
- else
39
- params.require(:localization).permit(:locale_id, :translated_value)
40
- end
30
+ def find_localization
31
+ @localization = @localization_key.localizations.find(params[:id])
32
+ end
33
+
34
+ def clear_params
35
+ if defined?(::ActionController::StrongParameters)
36
+ # allow translated_value to be an array
37
+ if @localization.value.is_a?(Array)
38
+ params.require(:localization).permit(:locale_id, translated_value: [])
41
39
  else
42
- params[:localization].is_a?(Hash) ? params[:localization].slice(:translated_value, :locale_id) : {}
40
+ params.require(:localization).permit(:locale_id, :translated_value)
43
41
  end
42
+ else
43
+ params[:localization].is_a?(Hash) ? params[:localization].slice(:translated_value, :locale_id) : {}
44
44
  end
45
+ end
45
46
  end
46
47
  end
@@ -1,4 +1,4 @@
1
- require_dependency "lit/application_controller"
1
+ require_dependency 'lit/application_controller'
2
2
 
3
3
  module Lit
4
4
  class SourcesController < ApplicationController
@@ -27,24 +27,24 @@ module Lit
27
27
  def touch
28
28
  @source = Source.find(params[:id])
29
29
  @source.touch_last_updated_at!
30
- redirect_to request.env["HTTP_REFERER"].present? ? :back : @source
30
+ redirect_to request.env['HTTP_REFERER'].present? ? :back : @source
31
31
  end
32
32
 
33
33
  def create
34
34
  @source = Source.new(clear_params)
35
35
  if @source.save
36
- redirect_to @source, :notice => 'Source was successfully created.'
36
+ redirect_to @source, notice: 'Source was successfully created.'
37
37
  else
38
- render :action => "new"
38
+ render action: 'new'
39
39
  end
40
40
  end
41
41
 
42
42
  def update
43
43
  @source = Source.find(params[:id])
44
44
  if @source.update_attributes(clear_params)
45
- redirect_to @source, :notice => 'Source was successfully updated.'
45
+ redirect_to @source, notice: 'Source was successfully updated.'
46
46
  else
47
- render :action => "edit"
47
+ render action: 'edit'
48
48
  end
49
49
  end
50
50
 
@@ -55,12 +55,13 @@ module Lit
55
55
  end
56
56
 
57
57
  private
58
- def clear_params
59
- if defined?(::ActionController::StrongParameters)
60
- params.require(:source).permit(:identifier, :url, :api_key)
61
- else
62
- params[:source]
63
- end
58
+
59
+ def clear_params
60
+ if defined?(::ActionController::StrongParameters)
61
+ params.require(:source).permit(:identifier, :url, :api_key)
62
+ else
63
+ params[:source]
64
64
  end
65
+ end
65
66
  end
66
67
  end