fast_gettext 0.8.1 → 0.9.0

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 (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
@@ -1,24 +0,0 @@
1
- require "spec_helper"
2
- require 'fast_gettext/translation_repository/base'
3
-
4
- describe 'FastGettext::TranslationRepository::Base' do
5
- before do
6
- @rep = FastGettext::TranslationRepository::Base.new('x')
7
- end
8
-
9
- it "can be built" do
10
- @rep.available_locales.should == []
11
- end
12
-
13
- it "cannot translate" do
14
- @rep['car'].should == nil
15
- end
16
-
17
- it "cannot pluralize" do
18
- @rep.plural('Axis','Axis').should == []
19
- end
20
-
21
- it "can be reloaded" do
22
- @rep.reload.should be_true
23
- end
24
- end
@@ -1,98 +0,0 @@
1
- require "spec_helper"
2
-
3
- class MockRepo
4
- def [](key)#should_receive :[] does not work so well...
5
- singular key
6
- end
7
- end
8
-
9
- describe 'FastGettext::TranslationRepository::Chain' do
10
- describe "empty chain" do
11
- before do
12
- @rep = FastGettext::TranslationRepository.build('chain', :chain=>[], :type=>:chain)
13
- end
14
-
15
- it "has no locales" do
16
- @rep.available_locales.should == []
17
- end
18
-
19
- it "cannot translate" do
20
- @rep['car'].should == nil
21
- end
22
-
23
- it "cannot pluralize" do
24
- @rep.plural('Axis','Axis').should == []
25
- end
26
-
27
- it "has no pluralisation rule" do
28
- @rep.pluralisation_rule.should == nil
29
- end
30
-
31
- it "returns true on reload" do
32
- @rep.reload.should be_true
33
- end
34
- end
35
-
36
- describe "filled chain" do
37
- before do
38
- @one = MockRepo.new
39
- @one.stub(:singular).with('xx').and_return 'one'
40
- @two = MockRepo.new
41
- @two.stub(:singular).with('xx').and_return 'two'
42
- @rep = FastGettext::TranslationRepository.build('chain', :chain=>[@one, @two], :type=>:chain)
43
- end
44
-
45
- describe :singular do
46
- it "uses the first repo in the chain if it responds" do
47
- @rep['xx'].should == 'one'
48
- end
49
-
50
- it "uses the second repo in the chain if the first does not respond" do
51
- @one.should_receive(:singular).and_return nil
52
- @rep['xx'].should == 'two'
53
- end
54
- end
55
-
56
- describe :plural do
57
- it "uses the first repo in the chain if it responds" do
58
- @one.should_receive(:plural).with('a','b').and_return ['A','B']
59
- @rep.plural('a','b').should == ['A','B']
60
- end
61
-
62
- it "uses the second repo in the chain if the first does not respond" do
63
- @one.should_receive(:plural).with('a','b').and_return []
64
- @two.should_receive(:plural).with('a','b').and_return ['A','B']
65
- @rep.plural('a','b').should == ['A','B']
66
- end
67
- end
68
-
69
- describe :available_locales do
70
- it "should be the sum of all added repositories" do
71
- @one.should_receive(:available_locales).and_return ['de']
72
- @two.should_receive(:available_locales).and_return ['de','en']
73
- @rep.available_locales.should == ['de','en']
74
- end
75
- end
76
-
77
- describe :pluralisation_rule do
78
- it "chooses the first that exists" do
79
- @one.should_receive(:pluralisation_rule).and_return nil
80
- @two.should_receive(:pluralisation_rule).and_return 'x'
81
- @rep.pluralisation_rule.should == 'x'
82
- end
83
- end
84
-
85
- describe :reload do
86
- it "reloads all repositories" do
87
- @one.should_receive(:reload)
88
- @two.should_receive(:reload)
89
- @rep.reload
90
- end
91
-
92
- it "returns true" do
93
- @rep.chain.each { |c| c.stub(:reload) }
94
- @rep.reload.should be_true
95
- end
96
- end
97
- end
98
- end
@@ -1,114 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_record'
3
- require 'fast_gettext/translation_repository/db'
4
- require 'support/be_accessible_matcher'
5
-
6
- FastGettext::TranslationRepository::Db.require_models
7
-
8
- describe FastGettext::TranslationRepository::Db do
9
- before :all do
10
- ActiveRecord::Base.establish_connection(
11
- :adapter => "sqlite3",
12
- :database => ":memory:"
13
- )
14
-
15
- #create model table
16
- ActiveRecord::Migration.verbose = false
17
- ActiveRecord::Schema.define(:version => 1) do
18
- create_table :translation_keys do |t|
19
- t.string :key, :unique=>true, :null=>false
20
- t.timestamps
21
- end
22
-
23
- create_table :translation_texts do |t|
24
- t.string :text, :locale
25
- t.integer :translation_key_id, :null=>false
26
- t.timestamps
27
- end
28
- end
29
- end
30
-
31
- before do
32
- TranslationKey.delete_all
33
- TranslationText.delete_all
34
- FastGettext.locale = 'de'
35
- @rep = FastGettext::TranslationRepository::Db.new('x', :model=>TranslationKey)
36
- end
37
-
38
- def create_translation(key, text)
39
- translation_key = TranslationKey.create!(:key => key)
40
- TranslationText.create!(:translation_key_id => translation_key.id, :text => text, :locale => "de")
41
- end
42
-
43
- it "reads locales from the db" do
44
- locales = ['de','en','es']
45
- locales.reverse.each do |locale|
46
- TranslationText.create!(:translation_key_id=>1, :text=>'asdasd', :locale=>locale)
47
- end
48
- @rep.available_locales.should == locales
49
- end
50
-
51
- it "has no pluralisation_rule by default" do
52
- @rep.pluralisation_rule.should == nil
53
- end
54
-
55
- it "cannot translate when no models are present" do
56
- @rep['car'].should == nil
57
- end
58
-
59
- it "can translate" do
60
- create_translation 'car', 'Auto'
61
- @rep['car'].should == 'Auto'
62
- end
63
-
64
- it "cannot pluralize when no model is present" do
65
- @rep.plural('Axis','Axis').should == []
66
- end
67
-
68
- it "can pluralize" do
69
- create_translation 'Axis||||Axis', 'Achse||||Achsen'
70
- @rep.plural('Axis','Axis').should == ['Achse','Achsen']
71
- end
72
-
73
- it "can ignore newline format" do
74
- create_translation "good\r\nmorning", "guten\r\nMorgen"
75
- @rep["good\nmorning"].should == "guten\r\nMorgen"
76
- end
77
-
78
- it "removes texts when key is removed" do
79
- t = create_translation("a", "b")
80
- expect{
81
- expect{
82
- t.translation_key.destroy
83
- }.to change{ TranslationText.count }.by(-1)
84
- }.to change{ TranslationKey.count }.by(-1)
85
- end
86
-
87
- it "model attributes should be accessible" do
88
- key = TranslationKey.new(:key => 'New Key', :translations_attributes => { '0' => {:text => 'New Key En', :locale => 'en'}})
89
-
90
- key.key.should == 'New Key'
91
-
92
- key.should be_accessible(:key)
93
- key.should be_accessible(:translations)
94
- key.should be_accessible(:translations_attributes)
95
- key.should_not be_accessible(:created_at)
96
-
97
- translation = key.translations.first
98
-
99
- translation.text.should == 'New Key En'
100
- translation.locale.should == 'en'
101
-
102
- translation.should be_accessible(:locale)
103
- translation.should be_accessible(:text)
104
- translation.should be_accessible(:translation_key)
105
- translation.should be_accessible(:translation_key_id)
106
- translation.should_not be_accessible(:created_at)
107
- end
108
-
109
- it "expires the cache when updated" do
110
- FastGettext.should_receive(:expire_cache_for).with('car')
111
- translation_text = create_translation 'car', 'Auto'
112
- translation_text.update_attributes :text => 'Autobot'
113
- end
114
- end
@@ -1,40 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe 'FastGettext::TranslationRepository::Logger' do
4
- before do
5
- @callback = lambda{}
6
- @rep = FastGettext::TranslationRepository.build('test', :type=>:logger, :callback=>@callback)
7
- @rep.is_a?(FastGettext::TranslationRepository::Logger).should be_true
8
- end
9
- subject{@rep}
10
-
11
- it{ should have(0).available_locales}
12
-
13
- it "has no pluralisation_rule" do
14
- @rep.pluralisation_rule.should == nil
15
- end
16
-
17
- describe :single do
18
- it "logs every call" do
19
- @callback.should_receive(:call).with('the_key')
20
- @rep['the_key']
21
- end
22
-
23
- it "returns nil" do
24
- @callback.should_receive(:call).with('the_key').and_return 'something'
25
- @rep['the_key'].should == nil
26
- end
27
- end
28
-
29
- describe :plural do
30
- it "logs every call" do
31
- @callback.should_receive(:call).with(['a','b'])
32
- @rep.plural('a','b')
33
- end
34
-
35
- it "returns an empty array" do
36
- @callback.should_receive(:call).with(['a','b']).and_return 'something'
37
- @rep.plural('a','b').should == []
38
- end
39
- end
40
- end
@@ -1,58 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe 'FastGettext::TranslationRepository::Mo' do
4
- before do
5
- @rep = FastGettext::TranslationRepository.build('test',:path=>File.join('spec', 'locale'))
6
- @rep.is_a?(FastGettext::TranslationRepository::Mo).should be_true
7
- end
8
-
9
- it "can be built" do
10
- @rep.available_locales.sort.should == ['de','en','gsw_CH']
11
- end
12
-
13
- it "can translate" do
14
- FastGettext.locale = 'de'
15
- @rep['car'].should == 'Auto'
16
- end
17
-
18
- it "can pluralize" do
19
- FastGettext.locale = 'de'
20
- @rep.plural('Axis','Axis').should == ['Achse','Achsen']
21
- end
22
-
23
- describe :reload do
24
- before do
25
- mo_file = FastGettext::MoFile.new('spec/locale/de/LC_MESSAGES/test2.mo')
26
-
27
- FastGettext::MoFile.stub(:new).and_return(FastGettext::MoFile.empty)
28
- FastGettext::MoFile.stub(:new).with('spec/locale/de/LC_MESSAGES/test.mo').and_return(mo_file)
29
- end
30
-
31
- it "can reload" do
32
- FastGettext.locale = 'de'
33
-
34
- @rep['Untranslated and translated in test2'].should be_nil
35
-
36
- @rep.reload
37
-
38
- @rep['Untranslated and translated in test2'].should == 'Translated'
39
- end
40
-
41
- it "returns true" do
42
- @rep.reload.should be_true
43
- end
44
- end
45
-
46
- it "has access to the mo repositories pluralisation rule" do
47
- FastGettext.locale = 'en'
48
- rep = FastGettext::TranslationRepository.build('plural_test',:path=>File.join('spec','locale'))
49
- rep['car'].should == 'Test'#just check it is loaded correctly
50
- rep.pluralisation_rule.call(2).should == 3
51
- end
52
-
53
- it "can work in SAFE mode" do
54
- pending_if RUBY_VERSION > "2.0" do
55
- `ruby spec/cases/safe_mode_can_handle_locales.rb 2>&1`.should == 'true'
56
- end
57
- end
58
- end
@@ -1,65 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe 'FastGettext::TranslationRepository::Po' do
4
- before do
5
- @rep = FastGettext::TranslationRepository.build('test',:path=>File.join('spec','locale'),:type=>:po)
6
- @rep.is_a?(FastGettext::TranslationRepository::Po).should be_true
7
- end
8
-
9
- it "can be built" do
10
- @rep.available_locales.sort.should == ['de','en','gsw_CH']
11
- end
12
-
13
- it "can translate" do
14
- FastGettext.locale = 'de'
15
- @rep['car'].should == 'Auto'
16
- end
17
-
18
- it "can pluralize" do
19
- FastGettext.locale = 'de'
20
- @rep.plural('Axis','Axis').should == ['Achse','Achsen']
21
- end
22
-
23
- it "has access to the mo repositories pluralisation rule" do
24
- FastGettext.locale = 'en'
25
- rep = FastGettext::TranslationRepository.build('plural_test',:path=>File.join('spec','locale'),:type=>:po)
26
- rep['car'].should == 'Test'#just check it is loaded correctly
27
- rep.pluralisation_rule.call(2).should == 3
28
- end
29
-
30
- describe 'fuzzy' do
31
- before do
32
- @fuzzy = File.join('spec','fuzzy_locale')
33
- end
34
-
35
- it "should use fuzzy by default" do
36
- $stderr.should_receive(:print).at_least(:once)
37
- repo = FastGettext::TranslationRepository.build('test',:path=>@fuzzy,:type=>:po)
38
- repo["%{relative_time} ago"].should == "vor %{relative_time}"
39
- end
40
-
41
- it "should warn on fuzzy when ignoring" do
42
- $stderr.should_receive(:print).at_least(:once)
43
- repo = FastGettext::TranslationRepository.build('test',:path=>@fuzzy,:type=>:po, :ignore_fuzzy => true)
44
- repo["%{relative_time} ago"].should == nil
45
- end
46
-
47
- it "should ignore fuzzy and not report when told to do so" do
48
- $stderr.should_not_receive(:print)
49
- repo = FastGettext::TranslationRepository.build('test',:path=>@fuzzy,:type=>:po, :ignore_fuzzy => true, :report_warning => false)
50
- repo["%{relative_time} ago"].should == nil
51
- end
52
- end
53
-
54
- describe 'obsolete' do
55
- it "should warn on obsolete by default" do
56
- $stderr.should_receive(:print).at_least(:once)
57
- FastGettext::TranslationRepository.build('test',:path=>File.join('spec','obsolete_locale'),:type=>:po)
58
- end
59
-
60
- it "should ignore obsolete when told to do so" do
61
- $stderr.should_not_receive(:print)
62
- FastGettext::TranslationRepository.build('test',:path=>File.join('spec','obsolete_locale'),:type=>:po, :report_warning => false)
63
- end
64
- end
65
- end
@@ -1,84 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe 'FastGettext::TranslationRepository::Yaml' do
4
- before do
5
- FastGettext.pluralisation_rule = nil
6
- @rep = FastGettext::TranslationRepository.build('test', :path => File.join('spec', 'locale', 'yaml'), :type => :yaml)
7
- @rep.is_a?(FastGettext::TranslationRepository::Yaml).should be_true
8
- FastGettext.locale = 'de'
9
- end
10
-
11
- it "can be built" do
12
- @rep.available_locales.sort.should == ['de', 'en']
13
- end
14
-
15
- it "translates nothing when locale is unsupported" do
16
- FastGettext.locale = 'xx'
17
- @rep['simple'].should == nil
18
- end
19
-
20
- it "does not translated categories" do
21
- @rep['cars'].should == nil
22
- end
23
-
24
- it "can translate simple" do
25
- @rep['simple'].should == 'einfach'
26
- end
27
-
28
- it "can translate nested" do
29
- @rep['cars.car'].should == 'Auto'
30
- end
31
-
32
- it "can pluralize" do
33
- @rep.plural('cars.axis').should == ['Achse', 'Achsen', nil, nil]
34
- end
35
-
36
- describe :reload do
37
- before do
38
- yaml = YAML.load_file('spec/locale/yaml/de2.yml')
39
-
40
- YAML.stub(:load_file).and_return('en' => {}, 'de' => {})
41
- YAML.stub(:load_file).with('spec/locale/yaml/de.yml').and_return(yaml)
42
- end
43
-
44
- it "can reload" do
45
- FastGettext.locale = 'de'
46
-
47
- @rep['cars.car'].should == 'Auto'
48
-
49
- @rep.reload
50
-
51
- @rep['cars.car'].should == 'Aufzugskabine'
52
- end
53
-
54
- it "returns true" do
55
- @rep.reload.should be_true
56
- end
57
- end
58
-
59
- it "handles unfound plurals with nil" do
60
- @rep.plural('cars.xxx').should == [nil, nil, nil, nil]
61
- end
62
-
63
- it "can be used to translate plural forms" do
64
- FastGettext.stub(:current_repository).and_return @rep
65
- FastGettext.n_('cars.axis','cars.axis',2).should == 'Achsen'
66
- FastGettext.n_('cars.axis',2).should == 'Achsen'
67
- FastGettext.n_('cars.axis',1).should == 'Achse'
68
- end
69
-
70
- 4.times do |i|
71
- it "can be used to do wanky pluralisation rules #{i}" do
72
- FastGettext.stub(:current_repository).and_return @rep
73
- @rep.stub(:pluralisation_rule).and_return lambda{|x| i}
74
- FastGettext.n_('cars.silly',1).should == i.to_s # cars.silly translations are 0,1,2,3
75
- end
76
- end
77
-
78
- it "can use custom pluraliztion rules" do
79
- FastGettext.locale = 'en'
80
- {0 => 0, 1 => 1, 2 => 2, 3 => 0}.each do |input, expected|
81
- @rep.pluralisation_rule.call(input).should == expected
82
- end
83
- end
84
- end