fast_gettext 0.4.17 → 0.5.1

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.
data/README.markdown CHANGED
@@ -2,10 +2,43 @@ FastGettext
2
2
  ===========
3
3
  GetText but 3.5 x faster, 560 x less memory, simple, clean namespace (7 vs 34) and threadsave!
4
4
 
5
- It supports multiple backends (atm: .mo files, .po files, Database(ActiveRecor + any other), Chain, Loggers) and can easily be extended.
5
+ It supports multiple backends (.mo, .po, .yml files, Database(ActiveRecor + any other), Chain, Loggers) and can easily be extended.
6
6
 
7
7
  [Example Rails application](https://github.com/grosser/gettext_i18n_rails_example)
8
8
 
9
+ Comparison
10
+ ==========
11
+ <table>
12
+ <tr>
13
+ <td></td>
14
+ <td width="100">Hash</td>
15
+ <td width="150">FastGettext</td>
16
+ <td width="100">GetText</td>
17
+ <td width="100">ActiveSupport I18n::Simple</td>
18
+ </tr>
19
+ <tr>
20
+ <td>Speed*</td>
21
+ <td>0.82s</td>
22
+ <td>1.36s</td>
23
+ <td>4.88s</td>
24
+ <td>21.77s</td>
25
+ </tr>
26
+ <tr>
27
+ <td>RAM*</td>
28
+ <td>4K</td>
29
+ <td>8K</td>
30
+ <td>4480K</td>
31
+ <td>10100K</td>
32
+ </tr>
33
+ <tr>
34
+ <td>Included backends</td>
35
+ <td></td>
36
+ <td>db, yml, mo, po, logger, chain</td>
37
+ <td>mo</td>
38
+ <td>yml</td>
39
+ </tr>
40
+ </table>
41
+ <small>*50.000 translations with ruby enterprise 1.8.6 through `rake benchmark`</small>
9
42
 
10
43
  Setup
11
44
  =====
@@ -17,10 +50,14 @@ Setup
17
50
  From mo files (traditional/default)
18
51
  FastGettext.add_text_domain('my_app',:path=>'locale')
19
52
 
20
- Or po files (less maintenacnce than mo)
53
+ Or po files (less maintenance than mo)
21
54
  FastGettext.add_text_domain('my_app',:path=>'locale', :type=>:po)
22
55
 
23
- Or database (scaleable, great for many locales/translators)
56
+ Or yaml files (use I18n syntax/indentation)
57
+ FastGettext.add_text_domain('my_app',:path=>'config/locales', :type=>:yaml)
58
+
59
+ Or database (scaleable, good for many locales/translators)
60
+ # db access is cached <-> only first lookup hits the db
24
61
  require "fast_gettext/translation_repository/db"
25
62
  include FastGettext::TranslationRepository::Db.require_models #load and include default models
26
63
  FastGettext.add_text_domain('my_app', :type=>:db, :model=>TranslationKey)
@@ -51,7 +88,6 @@ Use the [original GetText](http://github.com/mutoh/gettext) to create and manage
51
88
  (Work on a po/mo parser & reader that is easier to use has started, contributions welcome @ [pomo](http://github.com/grosser/pomo) )
52
89
 
53
90
  ###Database
54
- !!!new/only short time in production, please report back any ideas/suggestions you have!!!
55
91
  [Example migration for ActiveRecord](http://github.com/grosser/fast_gettext/blob/master/examples/db/migration.rb)
56
92
  The default plural seperator is `||||` but you may overwrite it (or suggest a better one..).
57
93
 
@@ -60,28 +96,6 @@ If you want to use your own models, have a look at the [default models](http://g
60
96
 
61
97
  To manage translations via a Web GUI, use a [Rails application and the translation_db_engine](http://github.com/grosser/translation_db_engine)
62
98
 
63
-
64
- Performance
65
- ===========
66
- 50_000 translations speed / memory
67
- small translation file <-> large translation file
68
- (ruby enterprise 1.8.6, your results may vary, try `rake benchmark`)
69
- Baseline: (doing nothing in a loop)
70
- 0.250000s / 0K <->
71
-
72
- Ideal: (primitive Hash lookup)
73
- 0.820000s / 4K <-> 0.760000s / 4K
74
-
75
- FastGettext:
76
- 1.360000s / 8K <-> 1.320000s / 8K
77
-
78
- GetText 2.0.1:
79
- 4.880000s / 4480K <-> 4.810000s / 4480K
80
-
81
- ActiveSupport I18n::Backend::Simple :
82
- 21.770000s / 10100K <->
83
-
84
-
85
99
  Rails
86
100
  =======================
87
101
  Try the [gettext_i18n_rails plugin](http://github.com/grosser/gettext_i18n_rails), it simplifies the setup.
@@ -145,7 +159,7 @@ Unfound may not always mean missing, if you chose not to translate a word becaus
145
159
  A lambda or anything that responds to `call` will do as callback. A good starting point may be `examples/missing_translations_logger.rb`.
146
160
 
147
161
  ###Plugins
148
- Want a yml, xml version ?
162
+ Want a xml version ?
149
163
  Write your own TranslationRepository!
150
164
  #fast_gettext/translation_repository/xxx.rb
151
165
  module FastGettext
@@ -174,6 +188,7 @@ Mo/Po-file parsing from Masao Mutoh, see vendor/README
174
188
 
175
189
  ###Contributors
176
190
  - [geekq](http://www.innoq.com/blog/vd)
191
+ - [Matt Sanford](http://blog.mzsanford.com)
177
192
  - Rudolf Gavlas
178
193
 
179
194
  [Michael Grosser](http://pragmatig.wordpress.com)
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
- desc "Run all specs in spec directory"
2
- task :default do |t|
3
- options = "--colour --format progress --loadby --reverse"
4
- files = FileList['spec/**/*_spec.rb']
5
- system("spec #{options} #{files}")
6
- end
1
+ task :default => :spec
2
+ require 'spec/rake/spectask'
3
+ Spec::Rake::SpecTask.new {|t| t.spec_opts = ['--color']}
7
4
 
8
5
  task :benchmark do
9
6
  puts "Running on #{RUBY}"
@@ -27,16 +24,9 @@ begin
27
24
  gem.email = "grosser.michael@gmail.com"
28
25
  gem.homepage = "http://github.com/grosser/#{project_name}"
29
26
  gem.authors = ["Michael Grosser"]
30
- gem.rubyforge_project = project_name.sub('_','-')
31
- end
32
-
33
- # fake task so that rubyforge:release works
34
- task :rdoc do
35
- `mkdir rdoc`
36
- `echo documentation is at http://github.com/grosser/#{project_name} > rdoc/README.rdoc`
37
27
  end
38
28
 
39
- Jeweler::RubyforgeTasks.new
29
+ Jeweler::GemcutterTasks.new
40
30
  rescue LoadError
41
- puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
31
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
42
32
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.17
1
+ 0.5.1
data/fast_gettext.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fast_gettext}
8
- s.version = "0.4.17"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2009-10-16}
12
+ s.date = %q{2010-01-30}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
48
48
  "lib/fast_gettext/translation_repository/logger.rb",
49
49
  "lib/fast_gettext/translation_repository/mo.rb",
50
50
  "lib/fast_gettext/translation_repository/po.rb",
51
- "rdoc/README.rdoc",
51
+ "lib/fast_gettext/translation_repository/yaml.rb",
52
52
  "spec/aa_unconfigued_spec.rb",
53
53
  "spec/fast_gettext/mo_file_spec.rb",
54
54
  "spec/fast_gettext/storage_spec.rb",
@@ -58,6 +58,8 @@ Gem::Specification.new do |s|
58
58
  "spec/fast_gettext/translation_repository/logger_spec.rb",
59
59
  "spec/fast_gettext/translation_repository/mo_spec.rb",
60
60
  "spec/fast_gettext/translation_repository/po_spec.rb",
61
+ "spec/fast_gettext/translation_repository/yaml_spec.rb",
62
+ "spec/fast_gettext/translation_repository_spec.rb",
61
63
  "spec/fast_gettext/translation_spec.rb",
62
64
  "spec/fast_gettext_spec.rb",
63
65
  "spec/locale/de/LC_MESSAGES/test.mo",
@@ -66,6 +68,9 @@ Gem::Specification.new do |s|
66
68
  "spec/locale/en/LC_MESSAGES/test.mo",
67
69
  "spec/locale/en/plural_test.po",
68
70
  "spec/locale/en/test.po",
71
+ "spec/locale/yaml/de.yml",
72
+ "spec/locale/yaml/en.yml",
73
+ "spec/locale/yaml/notfound.yml",
69
74
  "spec/spec_helper.rb",
70
75
  "spec/vendor/fake_load_path/iconv.rb",
71
76
  "spec/vendor/iconv_spec.rb",
@@ -80,27 +85,28 @@ Gem::Specification.new do |s|
80
85
  s.homepage = %q{http://github.com/grosser/fast_gettext}
81
86
  s.rdoc_options = ["--charset=UTF-8"]
82
87
  s.require_paths = ["lib"]
83
- s.rubyforge_project = %q{fast-gettext}
84
88
  s.rubygems_version = %q{1.3.5}
85
89
  s.summary = %q{A simple, fast and threadsafe implementation of GetText}
86
90
  s.test_files = [
87
- "spec/fast_gettext_spec.rb",
88
- "spec/spec_helper.rb",
89
- "spec/fast_gettext/translation_spec.rb",
90
- "spec/fast_gettext/storage_spec.rb",
91
- "spec/fast_gettext/translation_repository/chain_spec.rb",
91
+ "spec/spec_helper.rb",
92
+ "spec/aa_unconfigued_spec.rb",
93
+ "spec/vendor/fake_load_path/iconv.rb",
94
+ "spec/vendor/iconv_spec.rb",
95
+ "spec/vendor/string_spec.rb",
96
+ "spec/fast_gettext_spec.rb",
97
+ "spec/fast_gettext/translation_repository_spec.rb",
98
+ "spec/fast_gettext/translation_repository/mo_spec.rb",
99
+ "spec/fast_gettext/translation_repository/db_spec.rb",
100
+ "spec/fast_gettext/translation_repository/yaml_spec.rb",
92
101
  "spec/fast_gettext/translation_repository/logger_spec.rb",
93
102
  "spec/fast_gettext/translation_repository/base_spec.rb",
94
103
  "spec/fast_gettext/translation_repository/po_spec.rb",
95
- "spec/fast_gettext/translation_repository/db_spec.rb",
96
- "spec/fast_gettext/translation_repository/mo_spec.rb",
104
+ "spec/fast_gettext/translation_repository/chain_spec.rb",
105
+ "spec/fast_gettext/translation_spec.rb",
97
106
  "spec/fast_gettext/mo_file_spec.rb",
98
- "spec/aa_unconfigued_spec.rb",
99
- "spec/vendor/iconv_spec.rb",
100
- "spec/vendor/fake_load_path/iconv.rb",
101
- "spec/vendor/string_spec.rb",
102
- "examples/db/migration.rb",
103
- "examples/missing_translation_logger.rb"
107
+ "spec/fast_gettext/storage_spec.rb",
108
+ "examples/missing_translation_logger.rb",
109
+ "examples/db/migration.rb"
104
110
  ]
105
111
 
106
112
  if s.respond_to? :specification_version then
@@ -113,3 +119,4 @@ Gem::Specification.new do |s|
113
119
  else
114
120
  end
115
121
  end
122
+
@@ -19,7 +19,7 @@ module FastGettext
19
19
  @data[key]
20
20
  end
21
21
 
22
- #returns the plural forms or all singlgular translations that where found
22
+ #returns the plural forms or all singular translations that where found
23
23
  def plural(*msgids)
24
24
  translations = plural_translations(msgids)
25
25
  return translations unless translations.empty?
@@ -5,11 +5,13 @@ module FastGettext
5
5
  extend self
6
6
 
7
7
  # only single-word types supported atm (mytype works, MyType will not)
8
- def build(name,options)
8
+ def build(name, options)
9
9
  type = options[:type] || :mo
10
- require "fast_gettext/translation_repository/#{type}"
11
- klas = eval(type.to_s.capitalize)
12
- klas.new(name,options)
10
+ class_name = type.to_s.capitalize
11
+ unless FastGettext::TranslationRepository.constants.map{|c|c.to_s}.include?(class_name)
12
+ require "fast_gettext/translation_repository/#{type}"
13
+ end
14
+ eval(class_name).new(name,options)
13
15
  end
14
16
  end
15
17
  end
@@ -22,7 +22,7 @@ module FastGettext
22
22
 
23
23
  def find_and_store_files(name,options)
24
24
  # parse all .mo files with the right name, that sit in locale/LC_MESSAGES folders
25
- find_files_in_locale_folders(File.join('LC_MESSAGES',"#{name}.mo"),options[:path]) do |locale,file|
25
+ find_files_in_locale_folders(File.join('LC_MESSAGES',"#{name}.mo"), options[:path]) do |locale,file|
26
26
  @files[locale] = MoFile.new(file)
27
27
  end
28
28
  end
@@ -0,0 +1,72 @@
1
+ require 'fast_gettext/translation_repository/base'
2
+ require 'yaml'
3
+
4
+ module FastGettext
5
+ module TranslationRepository
6
+ # Responsibility:
7
+ # - find and store yaml files
8
+ # - provide access to translations in yaml files
9
+ class Yaml < Base
10
+ def initialize(name,options={})
11
+ find_and_store_files(options)
12
+ super
13
+ end
14
+
15
+ def available_locales
16
+ @files.keys
17
+ end
18
+
19
+ def plural(*keys)
20
+ ['one', 'other', 'plural2', 'plural3'].map do |name|
21
+ self[yaml_dot_notation(keys.first, name)]
22
+ end
23
+ end
24
+
25
+ def pluralisation_rule
26
+ self['pluralisation_rule'] ? lambda{|n| eval(self['pluralisation_rule']) } : nil
27
+ end
28
+
29
+ protected
30
+
31
+ MAX_FIND_DEPTH = 10
32
+
33
+ def find_and_store_files(options)
34
+ @files = {}
35
+ path = options[:path] || 'config/locales'
36
+ Dir["#{path}/??.yml"].each do |yaml_file|
37
+ locale = yaml_file.match(/([a-z]{2})\.yml$/)[1]
38
+ @files[locale] = load_yaml(yaml_file, locale)
39
+ end
40
+ end
41
+
42
+ def current_translations
43
+ @files[FastGettext.locale] || super
44
+ end
45
+
46
+ # Given a yaml file return a hash of key -> translation
47
+ def load_yaml(file, locale)
48
+ yaml = YAML.load_file(file)
49
+ yaml_hash_to_dot_notation(yaml[locale])
50
+ end
51
+
52
+ def yaml_hash_to_dot_notation(yaml_hash)
53
+ add_yaml_key({}, nil, yaml_hash)
54
+ end
55
+
56
+ def add_yaml_key(result, prefix, hash)
57
+ hash.each_pair do |key, value|
58
+ if value.kind_of?(Hash)
59
+ add_yaml_key(result, yaml_dot_notation(prefix, key), value)
60
+ else
61
+ result[yaml_dot_notation(prefix, key)] = value
62
+ end
63
+ end
64
+ result
65
+ end
66
+
67
+ def yaml_dot_notation(a,b)
68
+ a ? "#{a}.#{b}" : b
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,11 +1,10 @@
1
1
  current_folder = File.dirname(__FILE__)
2
2
  require File.join(current_folder,'..','spec_helper')
3
3
 
4
- include FastGettext
5
4
  de_file = File.join(current_folder,'..','locale','de','LC_MESSAGES','test.mo')
6
- de = MoFile.new(de_file)
5
+ de = FastGettext::MoFile.new(de_file)
7
6
 
8
- describe MoFile do
7
+ describe FastGettext::MoFile do
9
8
  before :all do
10
9
  File.exist?(de_file).should == true
11
10
  end
@@ -1,9 +1,9 @@
1
1
  current_folder = File.dirname(__FILE__)
2
2
  require File.join(current_folder,'..','spec_helper')
3
3
 
4
- include FastGettext::Storage
5
-
6
4
  describe 'Storage' do
5
+ include FastGettext::Storage
6
+
7
7
  before do
8
8
  #reset everything to nil
9
9
  self.available_locales = nil
@@ -258,7 +258,7 @@ describe 'Storage' do
258
258
 
259
259
  describe :key_exist? do
260
260
  it "does not find default keys" do
261
- _('abcde')
261
+ FastGettext._('abcde')
262
262
  key_exist?('abcde').should be_false
263
263
  end
264
264
 
@@ -291,19 +291,19 @@ describe 'Storage' do
291
291
  end
292
292
  end
293
293
 
294
- describe NoTextDomainConfigured do
294
+ describe FastGettext::Storage::NoTextDomainConfigured do
295
295
  it "shows what to do" do
296
- NoTextDomainConfigured.new.to_s.should =~ /FastGettext\.add_text_domain/
296
+ FastGettext::Storage::NoTextDomainConfigured.new.to_s.should =~ /FastGettext\.add_text_domain/
297
297
  end
298
298
 
299
299
  it "warns when text_domain is nil" do
300
300
  FastGettext.text_domain = nil
301
- NoTextDomainConfigured.new.to_s.should =~ /\(nil\)/
301
+ FastGettext::Storage::NoTextDomainConfigured.new.to_s.should =~ /\(nil\)/
302
302
  end
303
303
 
304
304
  it "shows current text_domain" do
305
305
  FastGettext.text_domain = 'xxx'
306
- NoTextDomainConfigured.new('xxx').to_s.should =~ /xxx/
306
+ FastGettext::Storage::NoTextDomainConfigured.new('xxx').to_s.should =~ /xxx/
307
307
  end
308
308
  end
309
309
  end
@@ -1,11 +1,12 @@
1
1
  current_folder = File.dirname(__FILE__)
2
2
  require File.join(current_folder,'..','..','spec_helper')
3
3
 
4
- require 'activerecord'
4
+ require 'active_record'
5
5
  require 'fast_gettext/translation_repository/db'
6
- include FastGettext::TranslationRepository::Db.require_models
7
6
 
7
+ include FastGettext::TranslationRepository::Db.require_models
8
8
  describe FastGettext::TranslationRepository::Db do
9
+
9
10
  before :all do
10
11
  ActiveRecord::Base.establish_connection({
11
12
  :adapter => "sqlite3",
@@ -9,7 +9,7 @@ describe 'FastGettext::TranslationRepository::Mo' do
9
9
  end
10
10
 
11
11
  it "can be built" do
12
- @rep.available_locales.should == ['de','en']
12
+ @rep.available_locales.sort.should == ['de','en']
13
13
  end
14
14
 
15
15
  it "can translate" do
@@ -9,7 +9,7 @@ describe 'FastGettext::TranslationRepository::Po' do
9
9
  end
10
10
 
11
11
  it "can be built" do
12
- @rep.available_locales.should == ['de','en']
12
+ @rep.available_locales.sort.should == ['de','en']
13
13
  end
14
14
 
15
15
  it "can translate" do
@@ -0,0 +1,61 @@
1
+ current_folder = File.dirname(__FILE__)
2
+ require File.join(current_folder,'..','..','spec_helper')
3
+
4
+ describe 'FastGettext::TranslationRepository::Yaml' do
5
+ before do
6
+ @rep = FastGettext::TranslationRepository.build('test', :path => File.join(current_folder,'..', '..', '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
+ it "handles unfound plurals with nil" do
37
+ @rep.plural('cars.xxx').should == [nil, nil, nil, nil]
38
+ end
39
+
40
+ it "can be used to translate plural forms" do
41
+ FastGettext.stub!(:current_repository).and_return @rep
42
+ FastGettext.n_('cars.axis','cars.axis',2).should == 'Achsen'
43
+ FastGettext.n_('cars.axis',2).should == 'Achsen'
44
+ FastGettext.n_('cars.axis',1).should == 'Achse'
45
+ end
46
+
47
+ it "can be used to do wanky pluralisation rules" do
48
+ FastGettext.stub!(:current_repository).and_return @rep
49
+ 4.times do |i|
50
+ @rep.stub!(:pluralisation_rule).and_return lambda{i}
51
+ FastGettext.n_('cars.silly',1).should == i.to_s
52
+ end
53
+ end
54
+
55
+ it "can use custom pluraliztion rules" do
56
+ FastGettext.locale = 'en'
57
+ {0 => 0, 1 => 1, 2 => 2, 3 => 0}.each do |input, expected|
58
+ @rep.pluralisation_rule.call(input).should == expected
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,34 @@
1
+ current_folder = File.dirname(__FILE__)
2
+ require File.join(current_folder,'..','spec_helper')
3
+
4
+ module FastGettext
5
+ module TranslationRepository
6
+ class Dummy
7
+ attr_accessor :name, :options
8
+ def initialize(name, options)
9
+ @name = name
10
+ @options = options
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ describe FastGettext::TranslationRepository do
17
+ describe "build" do
18
+ it "auto requires class by default" do
19
+ lambda { FastGettext::TranslationRepository.build('xx', { :type => 'invalid'}) }.should raise_error(LoadError)
20
+ end
21
+
22
+ it "can have auto-require disabled" do
23
+ FastGettext::TranslationRepository.build('xx', { :type => 'dummy' })
24
+ end
25
+
26
+ it "makes a new repository" do
27
+ options = { :type => 'dummy', :external => true }
28
+ repo = FastGettext::TranslationRepository.build('xx', options)
29
+ repo.class.should == FastGettext::TranslationRepository::Dummy
30
+ repo.name.should == 'xx'
31
+ repo.options.should == options
32
+ end
33
+ end
34
+ end
@@ -1,9 +1,9 @@
1
1
  current_folder = File.dirname(__FILE__)
2
2
  require File.join(current_folder,'..','spec_helper')
3
3
 
4
- include FastGettext::Translation
5
-
6
4
  describe FastGettext::Translation do
5
+ include FastGettext::Translation
6
+
7
7
  before do
8
8
  default_setup
9
9
  end
@@ -107,11 +107,11 @@ describe FastGettext::Translation do
107
107
  before do
108
108
  FastGettext.translation_repositories.replace({})
109
109
  #singular cache keys
110
- current_cache['xxx'] = '1'
110
+ FastGettext.current_cache['xxx'] = '1'
111
111
 
112
112
  #plural cache keys
113
- current_cache['||||xxx'] = ['1','2']
114
- current_cache['||||xxx||||yyy'] = ['1','2']
113
+ FastGettext.current_cache['||||xxx'] = ['1','2']
114
+ FastGettext.current_cache['||||xxx||||yyy'] = ['1','2']
115
115
  end
116
116
 
117
117
  it "uses the cache when translating with _" do
@@ -15,9 +15,8 @@ class IncludeTest
15
15
  end
16
16
  end
17
17
 
18
- include FastGettext
19
-
20
18
  describe FastGettext do
19
+ include FastGettext
21
20
  before :all do
22
21
  default_setup
23
22
  end
@@ -0,0 +1,25 @@
1
+ de:
2
+ simple: einfach
3
+ date:
4
+ relative: "vor %{relative_time}"
5
+
6
+ cars:
7
+ axis:
8
+ one: "Achse"
9
+ other: "Achsen"
10
+ silly:
11
+ one: '0'
12
+ other: '1'
13
+ plural2: '2'
14
+ plural3: '3'
15
+ model: "Modell"
16
+ wheel_count: "Räderzahl"
17
+ created: "Erstellt"
18
+ month: "Monat"
19
+ car: "Auto"
20
+ messages:
21
+ created: "Auto wurde erfolgreich gespeichert"
22
+ updated: "Auto wurde erfolgreich aktualisiert"
23
+
24
+ test_log:
25
+ phrases: "Dies ist eine dynamische Übersetzung, die durch gettext_test_log gefunden wurde!"
@@ -0,0 +1,21 @@
1
+ en:
2
+ pluralisation_rule: n<3?n:0
3
+ simple: easy
4
+ date:
5
+ relative: "%{relative_time} ago"
6
+
7
+ cars:
8
+ axis:
9
+ one: "Axis"
10
+ other: "Axis"
11
+ model: "Model"
12
+ wheel_count: "Wheels count"
13
+ created: "Created"
14
+ month: "Month"
15
+ car: "Car"
16
+ messages:
17
+ created: "Car was successfully created."
18
+ updated: "Car was successfully updated."
19
+
20
+ test_log:
21
+ phrases: "this is a dynamic translation which was found thorugh gettext_test_log!"
@@ -0,0 +1,2 @@
1
+ xx:
2
+ simple: FUUUU
@@ -9,7 +9,7 @@ describe String do
9
9
 
10
10
  describe "old % style replacement" do
11
11
  it "substitudes using % + Hash" do
12
- "x%{name}y" %{:name=>'a'}.should == 'xay'
12
+ ("x%{name}y" %{:name=>'a'}).should == 'xay'
13
13
  end
14
14
 
15
15
  it "does not substitute after %%" do
@@ -20,20 +20,22 @@ describe String do
20
20
  ("abc" % {:x=>1}).should == 'abc'
21
21
  end
22
22
 
23
- it "sustitutes strings" do
24
- ("a%{b}c" % {'b'=>1}).should == 'a1c'
25
- end
23
+ if RUBY_VERSION < '1.9' # this does not longer work in 1.9, use :"my weird string"
24
+ it "sustitutes strings" do
25
+ ("a%{b}c" % {'b'=>1}).should == 'a1c'
26
+ end
26
27
 
27
- it "sustitutes strings with -" do
28
- ("a%{b-a}c" % {'b-a'=>1}).should == 'a1c'
29
- end
28
+ it "sustitutes strings with -" do
29
+ ("a%{b-a}c" % {'b-a'=>1}).should == 'a1c'
30
+ end
30
31
 
31
- it "sustitutes string with ." do
32
- ("a%{b.a}c" % {'b.a'=>1}).should == 'a1c'
33
- end
32
+ it "sustitutes string with ." do
33
+ ("a%{b.a}c" % {'b.a'=>1}).should == 'a1c'
34
+ end
34
35
 
35
- it "sustitutes string with number" do
36
- ("a%{1}c" % {'1'=>1}).should == 'a1c'
36
+ it "sustitutes string with number" do
37
+ ("a%{1}c" % {'1'=>1}).should == 'a1c'
38
+ end
37
39
  end
38
40
  end
39
41
 
@@ -42,12 +44,14 @@ describe String do
42
44
  ("x%sy%s" % ['a','b']).should == 'xayb'
43
45
  end
44
46
 
45
- it "does not remove %{} style replacements" do
46
- ("%{name} x%sy%s" % ['a','b']).should == '%{name} xayb'
47
- end
47
+ if RUBY_VERSION < '1.9' # this does not longer work in 1.9, ArgumentError is raised
48
+ it "does not remove %{} style replacements" do
49
+ ("%{name} x%sy%s" % ['a','b']).should == '%{name} xayb'
50
+ end
48
51
 
49
- it "does not remove %<> style replacement" do
50
- ("%{name} %<num>f %s" % ['x']).should == "%{name} %<num>f x"
52
+ it "does not remove %<> style replacement" do
53
+ ("%{name} %<num>f %s" % ['x']).should == "%{name} %<num>f x"
54
+ end
51
55
  end
52
56
  end
53
57
 
@@ -64,4 +68,10 @@ describe String do
64
68
  ("%<num>#b" % {:num => 1}).should == "0b1"
65
69
  end
66
70
  end
71
+
72
+ if RUBY_VERSION >= '1.9'
73
+ it "does not raise when key was not found" do
74
+ ("%{typo} xxx" % {:something=>1}).should == "%{typo} xxx"
75
+ end
76
+ end
67
77
  end
data/vendor/string.rb CHANGED
@@ -56,3 +56,19 @@ rescue ArgumentError
56
56
  end
57
57
  end
58
58
  end
59
+
60
+ # 1.9.1 if you misspell a %{key} your whole page would blow up, no thanks...
61
+ begin
62
+ ("%{b}" % {:a=>'b'})
63
+ rescue KeyError
64
+ class String
65
+ alias :_fast_gettext_old_format_m :%
66
+ def %(*args)
67
+ begin
68
+ _fast_gettext_old_format_m(*args)
69
+ rescue KeyError
70
+ self
71
+ end
72
+ end
73
+ end
74
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_gettext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.17
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-16 00:00:00 +02:00
12
+ date: 2010-01-30 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -55,7 +55,7 @@ files:
55
55
  - lib/fast_gettext/translation_repository/logger.rb
56
56
  - lib/fast_gettext/translation_repository/mo.rb
57
57
  - lib/fast_gettext/translation_repository/po.rb
58
- - rdoc/README.rdoc
58
+ - lib/fast_gettext/translation_repository/yaml.rb
59
59
  - spec/aa_unconfigued_spec.rb
60
60
  - spec/fast_gettext/mo_file_spec.rb
61
61
  - spec/fast_gettext/storage_spec.rb
@@ -65,6 +65,8 @@ files:
65
65
  - spec/fast_gettext/translation_repository/logger_spec.rb
66
66
  - spec/fast_gettext/translation_repository/mo_spec.rb
67
67
  - spec/fast_gettext/translation_repository/po_spec.rb
68
+ - spec/fast_gettext/translation_repository/yaml_spec.rb
69
+ - spec/fast_gettext/translation_repository_spec.rb
68
70
  - spec/fast_gettext/translation_spec.rb
69
71
  - spec/fast_gettext_spec.rb
70
72
  - spec/locale/de/LC_MESSAGES/test.mo
@@ -73,6 +75,9 @@ files:
73
75
  - spec/locale/en/LC_MESSAGES/test.mo
74
76
  - spec/locale/en/plural_test.po
75
77
  - spec/locale/en/test.po
78
+ - spec/locale/yaml/de.yml
79
+ - spec/locale/yaml/en.yml
80
+ - spec/locale/yaml/notfound.yml
76
81
  - spec/spec_helper.rb
77
82
  - spec/vendor/fake_load_path/iconv.rb
78
83
  - spec/vendor/iconv_spec.rb
@@ -106,26 +111,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
111
  version:
107
112
  requirements: []
108
113
 
109
- rubyforge_project: fast-gettext
114
+ rubyforge_project:
110
115
  rubygems_version: 1.3.5
111
116
  signing_key:
112
117
  specification_version: 3
113
118
  summary: A simple, fast and threadsafe implementation of GetText
114
119
  test_files:
115
- - spec/fast_gettext_spec.rb
116
120
  - spec/spec_helper.rb
117
- - spec/fast_gettext/translation_spec.rb
118
- - spec/fast_gettext/storage_spec.rb
119
- - spec/fast_gettext/translation_repository/chain_spec.rb
121
+ - spec/aa_unconfigued_spec.rb
122
+ - spec/vendor/fake_load_path/iconv.rb
123
+ - spec/vendor/iconv_spec.rb
124
+ - spec/vendor/string_spec.rb
125
+ - spec/fast_gettext_spec.rb
126
+ - spec/fast_gettext/translation_repository_spec.rb
127
+ - spec/fast_gettext/translation_repository/mo_spec.rb
128
+ - spec/fast_gettext/translation_repository/db_spec.rb
129
+ - spec/fast_gettext/translation_repository/yaml_spec.rb
120
130
  - spec/fast_gettext/translation_repository/logger_spec.rb
121
131
  - spec/fast_gettext/translation_repository/base_spec.rb
122
132
  - spec/fast_gettext/translation_repository/po_spec.rb
123
- - spec/fast_gettext/translation_repository/db_spec.rb
124
- - spec/fast_gettext/translation_repository/mo_spec.rb
133
+ - spec/fast_gettext/translation_repository/chain_spec.rb
134
+ - spec/fast_gettext/translation_spec.rb
125
135
  - spec/fast_gettext/mo_file_spec.rb
126
- - spec/aa_unconfigued_spec.rb
127
- - spec/vendor/iconv_spec.rb
128
- - spec/vendor/fake_load_path/iconv.rb
129
- - spec/vendor/string_spec.rb
130
- - examples/db/migration.rb
136
+ - spec/fast_gettext/storage_spec.rb
131
137
  - examples/missing_translation_logger.rb
138
+ - examples/db/migration.rb
data/rdoc/README.rdoc DELETED
@@ -1 +0,0 @@
1
- documentation is at http://github.com/grosser/fast_gettext