lit 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -2,8 +2,7 @@ module Lit
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace Lit
4
4
 
5
-
6
- initializer "lit.assets.precompile" do |app|
5
+ initializer 'lit.assets.precompile' do |app|
7
6
  app.config.assets.precompile += %w(lit/application.css lit/application.js)
8
7
  end
9
8
  end
@@ -8,10 +8,11 @@ module Lit
8
8
 
9
9
  def initialize(cache)
10
10
  @cache = cache
11
+ @available_locales_cache = nil
11
12
  end
12
13
 
13
14
  def translate(locale, key, options = {})
14
- content = super(locale, key, options.merge(:fallback => true))
15
+ content = super(locale, key, options.merge(fallback: Lit.fallback))
15
16
  if Lit.all_translations_are_html_safe && content.respond_to?(:html_safe)
16
17
  content.html_safe
17
18
  else
@@ -20,12 +21,18 @@ module Lit
20
21
  end
21
22
 
22
23
  def available_locales
24
+ return @available_locales_cache unless @available_locales_cache.nil?
23
25
  locales = ::Rails.configuration.i18n.available_locales
24
- if locales and !locales.empty?
25
- locales
26
+ if locales && !locales.empty?
27
+ @available_locales_cache = locales.map(&:to_sym)
26
28
  else
27
- Lit::Locale.ordered.visible.map{|l| l.locale.to_sym }
29
+ @available_locales_cache = Lit::Locale.ordered.visible.map { |l| l.locale.to_sym }
28
30
  end
31
+ @available_locales_cache
32
+ end
33
+
34
+ def reset_available_locales_cache
35
+ @available_locales_cache = nil
29
36
  end
30
37
 
31
38
  # Stores the given translations.
@@ -34,16 +41,14 @@ module Lit
34
41
  # @param [Hash] data nested key-value pairs to be added as blurbs
35
42
  def store_translations(locale, data, options = {})
36
43
  super
37
- locales = ::Rails.configuration.i18n.available_locales
38
- if !locales || locales.map(&:to_s).include?(locale.to_s)
39
- store_item(locale, data)
40
- end
44
+ store_item(locale, data) if store_items? && valid_locale?(locale)
41
45
  end
42
46
 
43
-
44
47
  private
45
48
 
46
49
  def lookup(locale, key, scope = [], options = {})
50
+ init_translations unless initialized?
51
+
47
52
  parts = I18n.normalize_keys(locale, key, scope, options[:separator])
48
53
  key_with_locale = parts.join('.')
49
54
 
@@ -51,7 +56,7 @@ module Lit
51
56
  content = @cache[key_with_locale] || super
52
57
  return content if parts.size <= 1
53
58
 
54
- unless @cache.has_key?(key_with_locale)
59
+ if should_cache?(key_with_locale)
55
60
  new_content = @cache.init_key_with_value(key_with_locale, content)
56
61
  content = new_content if content.nil? # Content can change when Lit.humanize is true for example
57
62
 
@@ -90,10 +95,52 @@ module Lit
90
95
  end
91
96
  end
92
97
 
93
- def load_translations(*filenames)
98
+ def load_translations_to_cache
99
+ (@translations || {}).each do |locale, data|
100
+ store_item(locale, data) if valid_locale?(locale)
101
+ end
102
+ end
103
+
104
+ def init_translations
105
+ # Load all translations from *.yml, *.rb files to @translations variable.
106
+ # We don't want to store translations in lit cache just yet. We'll do it
107
+ # with `load_translations_to_cache` when all translations form yml (rb)
108
+ # files will be loaded.
109
+ without_store_items { load_translations }
110
+ # load translations from database to cache
94
111
  @cache.load_all_translations
95
- super
112
+ # load translations from @translations to cache
113
+ load_translations_to_cache
114
+ @initialized = true
115
+ end
116
+
117
+ def without_store_items
118
+ @store_items = false
119
+ yield
120
+ ensure
121
+ @store_items = true
122
+ end
123
+
124
+ def store_items?
125
+ @store_items.nil? || @store_items
126
+ end
127
+
128
+ def valid_locale?(locale)
129
+ locales = ::Rails.configuration.i18n.available_locales
130
+ !locales || locales.map(&:to_s).include?(locale.to_s)
96
131
  end
97
132
 
133
+ def is_ignored_key(key_without_locale)
134
+ Lit.ignored_keys.any?{ |k| key_without_locale.start_with?(k) }
135
+ end
136
+
137
+ def should_cache?(key_with_locale)
138
+ return false if @cache.has_key?(key_with_locale)
139
+
140
+ _, key_without_locale = ::Lit::Cache.split_key(key_with_locale)
141
+ return false if is_ignored_key(key_without_locale)
142
+
143
+ true
144
+ end
98
145
  end
99
146
  end
@@ -8,10 +8,9 @@ module Lit
8
8
  attr_accessor :logger
9
9
  def initialize
10
10
  self.logger ||= Logger.new($stdout)
11
- self.logger.info "initializing Lit"
11
+ self.logger.info 'initializing Lit'
12
12
  self.cache ||= Cache.new
13
13
  I18n.backend = I18nBackend.new(self.cache)
14
14
  end
15
-
16
15
  end
17
16
  end
@@ -1,12 +1,12 @@
1
1
  module Lit
2
2
  class Railtie < ::Rails::Railtie
3
3
  ## INITIALIZE IN config/initialize if you want to use redis!!!
4
- initializer :initialize_lit_rails, :after => :before_initialize do
5
- #Lit::Rails.initialize
4
+ initializer :initialize_lit_rails, after: :before_initialize do
5
+ # Lit::Rails.initialize
6
6
  end
7
7
 
8
- #rake_tasks do
9
- #load "tasks/lit_tasks.rake"
10
- #end
8
+ # rake_tasks do
9
+ # load "tasks/lit_tasks.rake"
10
+ # end
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module Lit
2
- VERSION = "0.2.4"
2
+ VERSION = '0.2.5'
3
3
  end
@@ -1,8 +1,8 @@
1
1
  namespace :lit do
2
- desc "Exports translated strings from lit to config/locales/lit.yml file."
3
- task :export => :environment do
2
+ desc 'Exports translated strings from lit to config/locales/lit.yml file.'
3
+ task export: :environment do
4
4
  if yml = Lit.init.cache.export
5
- PATH = "config/locales/lit.yml"
5
+ PATH = 'config/locales/lit.yml'
6
6
  File.new("#{Rails.root}/#{PATH}", 'w').write(yml)
7
7
  puts "Successfully exported #{PATH}."
8
8
  end
metadata CHANGED
@@ -1,89 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
5
- prerelease:
4
+ version: 0.2.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Maciej Litwiniuk
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-08-15 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>'
17
+ - - ">"
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.1.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>'
24
+ - - ">"
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: i18n
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.0
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: jquery-rails
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - ">="
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :runtime
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - ">="
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  - !ruby/object:Gem::Dependency
47
56
  name: pg
48
57
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
58
  requirements:
51
- - - ! '>='
59
+ - - ">="
52
60
  - !ruby/object:Gem::Version
53
61
  version: '0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
65
  requirements:
59
- - - ! '>='
66
+ - - ">="
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  - !ruby/object:Gem::Dependency
63
70
  name: devise
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
- - - ! '>='
73
+ - - ">="
68
74
  - !ruby/object:Gem::Version
69
75
  version: '0'
70
76
  type: :development
71
77
  prerelease: false
72
78
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
79
  requirements:
75
- - - ! '>='
80
+ - - ">="
76
81
  - !ruby/object:Gem::Version
77
82
  version: '0'
78
- description: ! 'Translate your apps with pleasure (sort of...) and for free. It''s
79
- simple i18n web interface, build on top of twitter bootstrap, that one may find
80
- helpful in translating app by non-technicals. '
83
+ description: 'Translate your apps with pleasure (sort of...) and for free. It''s simple
84
+ i18n web interface, build on top of twitter bootstrap, that one may find helpful
85
+ in translating app by non-technicals. '
81
86
  email:
82
87
  - maciej@litwiniuk.net
83
88
  executables: []
84
89
  extensions: []
85
90
  extra_rdoc_files: []
86
91
  files:
92
+ - MIT-LICENSE
93
+ - README.md
94
+ - Rakefile
87
95
  - app/assets/images/lit/famfamfam_flags/ad.png
88
96
  - app/assets/images/lit/famfamfam_flags/ae.png
89
97
  - app/assets/images/lit/famfamfam_flags/af.png
@@ -375,6 +383,8 @@ files:
375
383
  - app/views/layouts/lit/_navigation.html.erb
376
384
  - app/views/layouts/lit/application.html.erb
377
385
  - app/views/lit/dashboard/index.html.erb
386
+ - app/views/lit/incomming_localizations/accept.js.erb
387
+ - app/views/lit/incomming_localizations/destroy.js.erb
378
388
  - app/views/lit/incomming_localizations/index.html.erb
379
389
  - app/views/lit/locales/_hide_link.html.erb
380
390
  - app/views/lit/locales/hide.js.erb
@@ -404,6 +414,7 @@ files:
404
414
  - db/migrate/20130924151910_create_lit_incomming_localizations.rb
405
415
  - lib/generators/lit/install/templates/initializer.rb
406
416
  - lib/generators/lit/install_generator.rb
417
+ - lib/lit.rb
407
418
  - lib/lit/adapters/hash_storage.rb
408
419
  - lib/lit/adapters/redis_storage.rb
409
420
  - lib/lit/cache.rb
@@ -413,34 +424,29 @@ files:
413
424
  - lib/lit/rails.rb
414
425
  - lib/lit/railtie.rb
415
426
  - lib/lit/version.rb
416
- - lib/lit.rb
417
427
  - lib/tasks/lit_tasks.rake
418
- - MIT-LICENSE
419
- - Rakefile
420
- - README.md
421
428
  homepage: https://github.com/prograils/lit
422
429
  licenses:
423
430
  - MIT
431
+ metadata: {}
424
432
  post_install_message:
425
433
  rdoc_options: []
426
434
  require_paths:
427
435
  - lib
428
436
  required_ruby_version: !ruby/object:Gem::Requirement
429
- none: false
430
437
  requirements:
431
- - - ! '>='
438
+ - - ">="
432
439
  - !ruby/object:Gem::Version
433
440
  version: '0'
434
441
  required_rubygems_version: !ruby/object:Gem::Requirement
435
- none: false
436
442
  requirements:
437
- - - ! '>='
443
+ - - ">="
438
444
  - !ruby/object:Gem::Version
439
445
  version: '0'
440
446
  requirements: []
441
447
  rubyforge_project:
442
- rubygems_version: 1.8.23.2
448
+ rubygems_version: 2.4.5.1
443
449
  signing_key:
444
- specification_version: 3
450
+ specification_version: 4
445
451
  summary: Database powered i18n backend with web gui
446
452
  test_files: []