fast_gettext 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fast_gettext/cache.rb +42 -0
  3. data/lib/fast_gettext/storage.rb +28 -55
  4. data/lib/fast_gettext/version.rb +1 -1
  5. metadata +105 -73
  6. data/.gitignore +0 -2
  7. data/.travis.yml +0 -17
  8. data/Appraisals +0 -8
  9. data/CHANGELOG +0 -8
  10. data/Gemfile +0 -10
  11. data/Gemfile.lock +0 -52
  12. data/Rakefile +0 -25
  13. data/Readme.md +0 -261
  14. data/benchmark/base.rb +0 -46
  15. data/benchmark/baseline.rb +0 -5
  16. data/benchmark/fast_gettext.rb +0 -18
  17. data/benchmark/i18n_simple.rb +0 -8
  18. data/benchmark/ideal.rb +0 -24
  19. data/benchmark/locale/de.yml +0 -126
  20. data/benchmark/locale/de/LC_MESSAGES/large.mo +0 -0
  21. data/benchmark/misc/threadsave.rb +0 -21
  22. data/benchmark/namespace/fast_gettext.rb +0 -15
  23. data/benchmark/namespace/original.rb +0 -14
  24. data/benchmark/original.rb +0 -22
  25. data/examples/db/migration.rb +0 -22
  26. data/examples/missing_translation_logger.rb +0 -13
  27. data/fast_gettext.gemspec +0 -12
  28. data/gemfiles/rails23.gemfile +0 -14
  29. data/gemfiles/rails23.gemfile.lock +0 -56
  30. data/gemfiles/rails32.gemfile +0 -14
  31. data/gemfiles/rails32.gemfile.lock +0 -112
  32. data/gemfiles/rails40.gemfile +0 -15
  33. data/gemfiles/rails40.gemfile.lock +0 -110
  34. data/spec/aa_unconfigued_spec.rb +0 -21
  35. data/spec/cases/fake_load_path/iconv.rb +0 -2
  36. data/spec/cases/iconv_fallback.rb +0 -22
  37. data/spec/cases/interpolate_i18n_after_fast_gettext.rb +0 -7
  38. data/spec/cases/interpolate_i18n_before_fast_gettext.rb +0 -9
  39. data/spec/cases/safe_mode_can_handle_locales.rb +0 -5
  40. data/spec/fast_gettext/mo_file_spec.rb +0 -35
  41. data/spec/fast_gettext/po_file_spec.rb +0 -35
  42. data/spec/fast_gettext/storage_spec.rb +0 -386
  43. data/spec/fast_gettext/translation_repository/base_spec.rb +0 -24
  44. data/spec/fast_gettext/translation_repository/chain_spec.rb +0 -98
  45. data/spec/fast_gettext/translation_repository/db_spec.rb +0 -114
  46. data/spec/fast_gettext/translation_repository/logger_spec.rb +0 -40
  47. data/spec/fast_gettext/translation_repository/mo_spec.rb +0 -58
  48. data/spec/fast_gettext/translation_repository/po_spec.rb +0 -65
  49. data/spec/fast_gettext/translation_repository/yaml_spec.rb +0 -84
  50. data/spec/fast_gettext/translation_repository_spec.rb +0 -33
  51. data/spec/fast_gettext/translation_spec.rb +0 -363
  52. data/spec/fast_gettext/vendor/iconv_spec.rb +0 -7
  53. data/spec/fast_gettext/vendor/string_spec.rb +0 -101
  54. data/spec/fast_gettext_spec.rb +0 -51
  55. data/spec/fuzzy_locale/de/test.po +0 -22
  56. data/spec/locale/de/LC_MESSAGES/test.mo +0 -0
  57. data/spec/locale/de/LC_MESSAGES/test2.mo +0 -0
  58. data/spec/locale/de/test.po +0 -74
  59. data/spec/locale/de/test2.po +0 -64
  60. data/spec/locale/en/LC_MESSAGES/plural_test.mo +0 -0
  61. data/spec/locale/en/LC_MESSAGES/test.mo +0 -0
  62. data/spec/locale/en/plural_test.po +0 -20
  63. data/spec/locale/en/test.po +0 -59
  64. data/spec/locale/gsw_CH/LC_MESSAGES/test.mo +0 -0
  65. data/spec/locale/gsw_CH/test.po +0 -61
  66. data/spec/locale/yaml/de.yml +0 -25
  67. data/spec/locale/yaml/de2.yml +0 -25
  68. data/spec/locale/yaml/en.yml +0 -21
  69. data/spec/locale/yaml/notfound.yml +0 -2
  70. data/spec/obsolete_locale/de/test.po +0 -21
  71. data/spec/spec_helper.rb +0 -42
  72. data/spec/support/be_accessible_matcher.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c64b65d333ec41fdb6f8800ebdaaf90ae47f00f
4
- data.tar.gz: ba624c3b0b8e272dd9c592e450230c880f3a68bc
3
+ metadata.gz: 9d48793768d16644c39ec7da70a50c30571ccbf8
4
+ data.tar.gz: 942aded77246f1df2d26d9b19ab5a790d92de577
5
5
  SHA512:
6
- metadata.gz: 1497386c209b21fc06f92eac9d0839981b828f4d1318646ea5fd9e975ba7702e123633200ac9696671f81faf9571428cf88c9ffea2fee3dc5dfdb19eded9ba9b
7
- data.tar.gz: 00a88e10cb2a44d65d15413dbd9010d3e531392be5b668af336bd0c2413c23b6f00ff9b4eb1cbd1ebe2d7d2e6fb12e1d91bd87007061025fd67fdf8173f22639
6
+ metadata.gz: 47fc218deca6269b8455e268267e9d737a731107096e2ce8616ef03608aaf0fcb0e8ab4b75eae5b83c59f26c91c16096c1a7ca4ffe59de8ad219633ec8e7a0fc
7
+ data.tar.gz: 2c426523021a29ef41cac4ffebb10913e11f3b9f7819919352fc938ba2dc1234e6db0a7b256b4930b62dab4519a8db645dbe8211e78b89b2ee2a6da6588e410f
@@ -0,0 +1,42 @@
1
+ module FastGettext
2
+ class Cache
3
+ def initialize
4
+ @store = {}
5
+ reload!
6
+ end
7
+
8
+ def fetch(key)
9
+ translation = @current[key]
10
+ if translation.nil? # uncached
11
+ @current[key] = yield || false # TODO get rid of this false hack and cache :missing
12
+ else
13
+ translation
14
+ end
15
+ end
16
+
17
+ # TODO only used for tests, maybe if-else around it ...
18
+ def []=(key, value)
19
+ @current[key] = value
20
+ end
21
+
22
+ # key performance gain:
23
+ # - no need to lookup locale on each translation
24
+ # - no need to lookup text_domain on each translation
25
+ # - super-simple hash lookup
26
+ def switch_to(text_domain, locale)
27
+ @store[text_domain] ||= {}
28
+ @store[text_domain][locale] ||= {}
29
+ @store[text_domain][locale][""] = false # ignore gettext meta key when translating
30
+ @current = @store[text_domain][locale]
31
+ end
32
+
33
+ def delete(key)
34
+ @current.delete(key)
35
+ end
36
+
37
+ def reload!
38
+ @current = {}
39
+ @current[""] = false
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,5 @@
1
+ require 'fast_gettext/cache'
2
+
1
3
  module FastGettext
2
4
  # Responsibility:
3
5
  # - store data threadsave
@@ -13,7 +15,7 @@ module FastGettext
13
15
  [:available_locales, :_locale, :text_domain, :pluralisation_rule].each do |method_name|
14
16
  key = "fast_gettext_#{method_name}".to_sym
15
17
  define_method "#{method_name}=" do |value|
16
- update_current_cache if Thread.current[key] != Thread.current[key]=value
18
+ switch_cache if Thread.current[key] != Thread.current[key]=value
17
19
  end
18
20
  end
19
21
 
@@ -29,50 +31,41 @@ module FastGettext
29
31
  locales.map{|s|s.to_s}
30
32
  end
31
33
 
32
- # == cattr_accessor :default_available_locales
33
- @@default_available_locales = nil
34
- def default_available_locales=(avail_locales)
35
- @@default_available_locales = avail_locales
36
- update_current_cache
37
- end
34
+ # cattr_accessor with defaults
35
+ [
36
+ [:default_available_locales, "nil"],
37
+ [:default_text_domain, "nil"],
38
+ [:cache_class, "FastGettext::Cache"]
39
+ ].each do |name, default|
40
+ eval <<-Ruby
41
+ @@#{name} = #{default}
42
+ def #{name}=(value)
43
+ @@#{name} = value
44
+ switch_cache
45
+ end
38
46
 
39
- def default_available_locales
40
- @@default_available_locales
47
+ def #{name}
48
+ @@#{name}
49
+ end
50
+ Ruby
41
51
  end
42
52
 
43
-
44
53
  def text_domain
45
54
  Thread.current[:fast_gettext_text_domain] || default_text_domain
46
55
  end
47
56
 
48
- # == cattr_accessor :default_text_domain
49
- @@default_text_domain = nil
50
- def default_text_domain=(domain)
51
- @@default_text_domain = domain
52
- update_current_cache
53
- end
54
-
55
- def default_text_domain
56
- @@default_text_domain
57
- end
58
-
59
-
60
57
  # if overwritten by user( FastGettext.pluralisation_rule = xxx) use it,
61
58
  # otherwise fall back to repo or to default lambda
62
59
  def pluralisation_rule
63
60
  Thread.current[:fast_gettext_pluralisation_rule] || current_repository.pluralisation_rule || lambda{|i| i!=1}
64
61
  end
65
62
 
66
- def current_cache
67
- Thread.current[:fast_gettext_current_cache] || {}
68
- end
69
-
70
- def current_cache=(cache)
71
- Thread.current[:fast_gettext_current_cache] = cache
63
+ def cache
64
+ Thread.current[:fast_gettext_cache] ||= cache_class.new
72
65
  end
73
66
 
74
67
  def reload!
75
- self.current_cache = {}
68
+ cache.reload!
76
69
  translation_repositories.values.each(&:reload)
77
70
  end
78
71
 
@@ -82,13 +75,6 @@ module FastGettext
82
75
  @@translation_repositories
83
76
  end
84
77
 
85
- # used to speedup simple translations, does not work for pluralisation
86
- # caches[text_domain][locale][key]=translation
87
- @@caches={}
88
- def caches
89
- @@caches
90
- end
91
-
92
78
  def current_repository
93
79
  translation_repositories[text_domain] || raise(NoTextDomainConfigured)
94
80
  end
@@ -98,26 +84,16 @@ module FastGettext
98
84
  end
99
85
 
100
86
  def cached_find(key)
101
- translation = current_cache[key]
102
- if translation.nil? # uncached
103
- current_cache[key] = current_repository[key] || false
104
- else
105
- translation
106
- end
87
+ cache.fetch(key) { current_repository[key] }
107
88
  end
108
89
 
109
90
  def cached_plural_find(*keys)
110
91
  key = '||||' + keys * '||||'
111
- translation = current_cache[key]
112
- if translation.nil? # uncached
113
- current_cache[key] = current_repository.plural(*keys) || false
114
- else
115
- translation
116
- end
92
+ cache.fetch(key) { current_repository.plural(*keys) }
117
93
  end
118
94
 
119
95
  def expire_cache_for(key)
120
- current_cache.delete(key)
96
+ cache.delete(key)
121
97
  end
122
98
 
123
99
  def locale
@@ -140,7 +116,7 @@ module FastGettext
140
116
  @@default_locale = nil
141
117
  def default_locale=(new_locale)
142
118
  @@default_locale = best_locale_in(new_locale)
143
- update_current_cache
119
+ switch_cache
144
120
  end
145
121
 
146
122
  def default_locale
@@ -196,11 +172,8 @@ module FastGettext
196
172
  locale.sub(/^([a-zA-Z]{2,3})[-_]([a-zA-Z]{2,3})$/){$1.downcase+'_'+$2.upcase}
197
173
  end
198
174
 
199
- def update_current_cache
200
- caches[text_domain] ||= {}
201
- caches[text_domain][locale] ||= {}
202
- caches[text_domain][locale][""] = false #ignore gettext meta key when translating
203
- self.current_cache = caches[text_domain][locale]
175
+ def switch_cache
176
+ cache.switch_to(text_domain, locale)
204
177
  end
205
178
  end
206
179
  end
@@ -1,3 +1,3 @@
1
1
  module FastGettext
2
- VERSION = Version = '0.8.1'
2
+ VERSION = Version = '0.9.0'
3
3
  end
metadata CHANGED
@@ -1,50 +1,121 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_gettext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-27 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: i18n
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bump
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: wwtd
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
13
111
  description:
14
112
  email: michael@grosser.it
15
113
  executables: []
16
114
  extensions: []
17
115
  extra_rdoc_files: []
18
116
  files:
19
- - .gitignore
20
- - .travis.yml
21
- - Appraisals
22
- - CHANGELOG
23
- - Gemfile
24
- - Gemfile.lock
25
- - Rakefile
26
- - Readme.md
27
- - benchmark/base.rb
28
- - benchmark/baseline.rb
29
- - benchmark/fast_gettext.rb
30
- - benchmark/i18n_simple.rb
31
- - benchmark/ideal.rb
32
- - benchmark/locale/de.yml
33
- - benchmark/locale/de/LC_MESSAGES/large.mo
34
- - benchmark/misc/threadsave.rb
35
- - benchmark/namespace/fast_gettext.rb
36
- - benchmark/namespace/original.rb
37
- - benchmark/original.rb
38
- - examples/db/migration.rb
39
- - examples/missing_translation_logger.rb
40
- - fast_gettext.gemspec
41
- - gemfiles/rails23.gemfile
42
- - gemfiles/rails23.gemfile.lock
43
- - gemfiles/rails32.gemfile
44
- - gemfiles/rails32.gemfile.lock
45
- - gemfiles/rails40.gemfile
46
- - gemfiles/rails40.gemfile.lock
47
117
  - lib/fast_gettext.rb
118
+ - lib/fast_gettext/cache.rb
48
119
  - lib/fast_gettext/mo_file.rb
49
120
  - lib/fast_gettext/po_file.rb
50
121
  - lib/fast_gettext/storage.rb
@@ -66,45 +137,6 @@ files:
66
137
  - lib/fast_gettext/vendor/poparser.rb
67
138
  - lib/fast_gettext/vendor/string.rb
68
139
  - lib/fast_gettext/version.rb
69
- - spec/aa_unconfigued_spec.rb
70
- - spec/cases/fake_load_path/iconv.rb
71
- - spec/cases/iconv_fallback.rb
72
- - spec/cases/interpolate_i18n_after_fast_gettext.rb
73
- - spec/cases/interpolate_i18n_before_fast_gettext.rb
74
- - spec/cases/safe_mode_can_handle_locales.rb
75
- - spec/fast_gettext/mo_file_spec.rb
76
- - spec/fast_gettext/po_file_spec.rb
77
- - spec/fast_gettext/storage_spec.rb
78
- - spec/fast_gettext/translation_repository/base_spec.rb
79
- - spec/fast_gettext/translation_repository/chain_spec.rb
80
- - spec/fast_gettext/translation_repository/db_spec.rb
81
- - spec/fast_gettext/translation_repository/logger_spec.rb
82
- - spec/fast_gettext/translation_repository/mo_spec.rb
83
- - spec/fast_gettext/translation_repository/po_spec.rb
84
- - spec/fast_gettext/translation_repository/yaml_spec.rb
85
- - spec/fast_gettext/translation_repository_spec.rb
86
- - spec/fast_gettext/translation_spec.rb
87
- - spec/fast_gettext/vendor/iconv_spec.rb
88
- - spec/fast_gettext/vendor/string_spec.rb
89
- - spec/fast_gettext_spec.rb
90
- - spec/fuzzy_locale/de/test.po
91
- - spec/locale/de/LC_MESSAGES/test.mo
92
- - spec/locale/de/LC_MESSAGES/test2.mo
93
- - spec/locale/de/test.po
94
- - spec/locale/de/test2.po
95
- - spec/locale/en/LC_MESSAGES/plural_test.mo
96
- - spec/locale/en/LC_MESSAGES/test.mo
97
- - spec/locale/en/plural_test.po
98
- - spec/locale/en/test.po
99
- - spec/locale/gsw_CH/LC_MESSAGES/test.mo
100
- - spec/locale/gsw_CH/test.po
101
- - spec/locale/yaml/de.yml
102
- - spec/locale/yaml/de2.yml
103
- - spec/locale/yaml/en.yml
104
- - spec/locale/yaml/notfound.yml
105
- - spec/obsolete_locale/de/test.po
106
- - spec/spec_helper.rb
107
- - spec/support/be_accessible_matcher.rb
108
140
  homepage: http://github.com/grosser/fast_gettext
109
141
  licenses:
110
142
  - MIT
@@ -116,17 +148,17 @@ require_paths:
116
148
  - lib
117
149
  required_ruby_version: !ruby/object:Gem::Requirement
118
150
  requirements:
119
- - - '>='
151
+ - - ">="
120
152
  - !ruby/object:Gem::Version
121
153
  version: '0'
122
154
  required_rubygems_version: !ruby/object:Gem::Requirement
123
155
  requirements:
124
- - - '>='
156
+ - - ">="
125
157
  - !ruby/object:Gem::Version
126
158
  version: '0'
127
159
  requirements: []
128
160
  rubyforge_project:
129
- rubygems_version: 2.0.3
161
+ rubygems_version: 2.2.2
130
162
  signing_key:
131
163
  specification_version: 4
132
164
  summary: A simple, fast, memory-efficient and threadsafe implementation of GetText
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- pkg
2
- benchmark/locle
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- bundler_args: ""
2
- script: "bundle exec rake spec"
3
- rvm:
4
- - ree
5
- - 1.9.3
6
- - 2.0.0
7
- gemfile:
8
- - gemfiles/rails23.gemfile
9
- - gemfiles/rails32.gemfile
10
- - gemfiles/rails40.gemfile
11
- bundler_args: --no-deployment
12
- matrix:
13
- exclude:
14
- - rvm: 2.0.0
15
- gemfile: gemfiles/rails23.gemfile
16
- - rvm: ree
17
- gemfile: gemfiles/rails40.gemfile