grosser-fast_gettext 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -34,8 +34,8 @@ Start translating
34
34
  Disable translation errors(like no text domain setup) while doing e.g. console session / testing
35
35
  FastGettext.silence_errors
36
36
 
37
- Speed
38
- =====
37
+ Performance
38
+ ===========
39
39
  50_000 translations speed / memory
40
40
  small translation file <-> large translation file
41
41
  Baseline: (doing nothing in a loop)
@@ -93,7 +93,7 @@ Advanced features
93
93
  =================
94
94
  ###Abnormal pluralisation
95
95
  Pluralisation rules can be set directly via a lambda (see code/specs), or by using the Gettext
96
- plural definition (see spec/locale/en/test_plural.po or [GNU Gettext documentation](http://www.gnu.org/software/libtool/manual/libc/Advanced-gettext-functions.html).
96
+ plural definition (see spec/locale/en/test_plural.po or [Plural expressions for all languages](http://translate.sourceforge.net/wiki/l10n/pluralforms).
97
97
 
98
98
  ###Plugins
99
99
  Want a yml, xml, database version ?
@@ -102,7 +102,7 @@ Write your own TranslationRepository!
102
102
  module FastGettext
103
103
  module TranslationRepository
104
104
  class Wtf
105
- define initialize(name,options), available_locales, [key], plural(singular,plural,count)
105
+ define initialize(name,options), available_locales, [key], plural(*msgids)
106
106
  end
107
107
  end
108
108
  end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 3
4
- :patch: 0
4
+ :patch: 1
@@ -0,0 +1,14 @@
1
+ require 'fast_gettext/mo_file'
2
+ module FastGettext
3
+ # Responsibility:
4
+ # - abstract po files for Po Repository
5
+ # TODO refactor...
6
+ class PoFile
7
+ def self.to_mo_file(file)
8
+ require File.join(File.dirname(__FILE__),'..','..','vendor','poparser')
9
+ mo_file = FastGettext::GetText::MOFile.new
10
+ FastGettext::GetText::PoParser.new.parse(File.read(file),mo_file)
11
+ MoFile.new(mo_file)
12
+ end
13
+ end
14
+ end
@@ -31,6 +31,7 @@ module FastGettext
31
31
 
32
32
  translations = FastGettext.current_repository.plural(*msgids)
33
33
  selected = FastGettext.current_repository.pluralisation_rule.call(count)
34
+ selected = selected ? 1 : 0 unless selected.is_a? Numeric #convert booleans to numbers
34
35
  translations[selected] || msgids[selected] || msgids.last
35
36
  end
36
37
 
@@ -8,12 +8,9 @@ module FastGettext
8
8
  class Po < Mo
9
9
  protected
10
10
  def find_and_store_files(name,options)
11
- require File.join(File.dirname(__FILE__),'..','..','..','vendor','poparser')
12
- require 'fast_gettext/mo_file'
11
+ require 'fast_gettext/po_file'
13
12
  find_files_in_locale_folders("#{name}.po",options[:path]) do |locale,file|
14
- mo_file = FastGettext::GetText::MOFile.new
15
- FastGettext::GetText::PoParser.new.parse(File.read(file),mo_file)
16
- @files[locale] = MoFile.new(mo_file)
13
+ @files[locale] = PoFile.to_mo_file(file)
17
14
  end
18
15
  end
19
16
  end
@@ -33,22 +33,33 @@ describe FastGettext::Translation do
33
33
  end
34
34
 
35
35
  describe :n_ do
36
+ before do
37
+ FastGettext.current_repository.pluralisation_rule = lambda{|n|n==1?0:1}
38
+ end
39
+
36
40
  it "translates pluralized" do
37
41
  n_('Axis','Axis',1).should == 'Achse'
38
42
  n_('Axis','Axis',2).should == 'Achsen'
39
43
  n_('Axis','Axis',0).should == 'Achsen'
40
44
  end
41
45
 
42
- it "supports abstract pluralisation rules" do
43
- begin
46
+ describe "pluralisations rules" do
47
+ it "supports abstract pluralisation rules" do
44
48
  FastGettext.current_repository.pluralisation_rule = lambda{|n|2}
45
49
  n_('a','b','c','d',4).should == 'c'
46
- ensure
47
- #restore default
48
- FastGettext.current_repository.pluralisation_rule = lambda{|n|n==1?0:1}
49
50
  end
50
- end
51
51
 
52
+ it "supports false as singular" do
53
+ FastGettext.current_repository.pluralisation_rule = lambda{|n|n!=2}
54
+ n_('singular','plural','c','d',2).should == 'singular'
55
+ end
56
+
57
+ it "supports true as plural" do
58
+ FastGettext.current_repository.pluralisation_rule = lambda{|n|n==2}
59
+ n_('singular','plural','c','d',2).should == 'plural'
60
+ end
61
+ end
62
+
52
63
  it "returns the appropriate msgid if no translation was found" do
53
64
  n_('NOTFOUND','NOTFOUNDs',1).should == 'NOTFOUND'
54
65
  n_('NOTFOUND','NOTFOUNDs',2).should == 'NOTFOUNDs'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grosser-fast_gettext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.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-03-09 00:00:00 -07:00
12
+ date: 2009-03-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -27,6 +27,7 @@ files:
27
27
  - lib/fast_gettext
28
28
  - lib/fast_gettext.rb
29
29
  - lib/fast_gettext/mo_file.rb
30
+ - lib/fast_gettext/po_file.rb
30
31
  - lib/fast_gettext/storage.rb
31
32
  - lib/fast_gettext/translation.rb
32
33
  - lib/fast_gettext/translation_repository