fast_gettext 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ac283f35f54466e64db6ad5655786bf4e1468d5
4
- data.tar.gz: ee2a9e46dd0a4137420ce9ed119baa6eb47f0e9a
3
+ metadata.gz: f1c679c3594754eaf0836fe85d8727b4a104127f
4
+ data.tar.gz: 65b5ca0ccd954bc5b173d3076c0094f7cbfa8e83
5
5
  SHA512:
6
- metadata.gz: 31b81c071588437a83e164c9c901293baab9a619a5f29c024547506311fb4549a6566943c4e935995483ec8d3c21902f115ecf7f1a389bba3725a74c0b14b954
7
- data.tar.gz: 47486431368e3d66e2e20182c1e3168be9f4b028a30d79e3df4649f3c12f5851a94d2b5cdeff881e78674fc41106e2c54af715cba1548d2b6730351c2a3b202d
6
+ metadata.gz: 641ee741ba7027c9e85cdf8bd83f4cc1877bebe583633b52be941e0de1cb2794944fadea3916bcf929559faed7d00889aa85c362b6ad1892f4665016fbc05d7a
7
+ data.tar.gz: 304487d75a07a5b33e6b4241e332225b37e3e647e474fe77fd56aa23c4437a548a084a43d5b669dc6af0630815af209d875c320c6651d2f85b91c096c0db1886
@@ -6,17 +6,13 @@ module FastGettext
6
6
  PLURAL_SEPERATOR = "\000"
7
7
 
8
8
  # file => path or FastGettext::GetText::MOFile
9
- def initialize(file)
10
- if file.is_a? FastGettext::GetText::MOFile
11
- @data = file
12
- else
13
- @data = FastGettext::GetText::MOFile.open(file, "UTF-8")
14
- end
15
- make_singular_and_plural_available
9
+ def initialize(file, options={})
10
+ @filename = file
11
+ load_data if options[:eager_load]
16
12
  end
17
13
 
18
14
  def [](key)
19
- @data[key]
15
+ data[key]
20
16
  end
21
17
 
22
18
  #returns the plural forms or all singular translations that where found
@@ -28,7 +24,7 @@ module FastGettext
28
24
  def pluralisation_rule
29
25
  #gettext uses 0 as default rule, which would turn off all pluralisation, very clever...
30
26
  #additionally parsing fails when directly accessing po files, so this line was taken from gettext/mofile
31
- (@data['']||'').split("\n").each do |line|
27
+ (data['']||'').split("\n").each do |line|
32
28
  return lambda{|n|eval($2)} if /^Plural-Forms:\s*nplurals\s*\=\s*(\d*);\s*plural\s*\=\s*([^;]*)\n?/ =~ line
33
29
  end
34
30
  nil
@@ -40,6 +36,20 @@ module FastGettext
40
36
 
41
37
  private
42
38
 
39
+ def data
40
+ load_data if @data.nil?
41
+ @data
42
+ end
43
+
44
+ def load_data
45
+ @data = if @filename.is_a? FastGettext::GetText::MOFile
46
+ @filename
47
+ else
48
+ FastGettext::GetText::MOFile.open(@filename, "UTF-8")
49
+ end
50
+ make_singular_and_plural_available
51
+ end
52
+
43
53
  #(if plural==singular, prefer singular)
44
54
  def make_singular_and_plural_available
45
55
  data = {}
@@ -2,8 +2,28 @@ require 'fast_gettext/mo_file'
2
2
  module FastGettext
3
3
  # Responsibility:
4
4
  # - abstract po files for Po Repository
5
- class PoFile
5
+ class PoFile < MoFile
6
+ def initialize(file, options={})
7
+ @options = options
8
+ super
9
+ end
10
+
6
11
  def self.to_mo_file(file, options={})
12
+ MoFile.new(parse_po_file(file, options))
13
+ end
14
+
15
+ protected
16
+
17
+ def load_data
18
+ @data = if @filename.is_a? FastGettext::GetText::MOFile
19
+ @filename
20
+ else
21
+ FastGettext::PoFile.parse_po_file(@filename, @options)
22
+ end
23
+ make_singular_and_plural_available
24
+ end
25
+
26
+ def self.parse_po_file(file, options={})
7
27
  require 'fast_gettext/vendor/poparser'
8
28
  parser = FastGettext::GetText::PoParser.new
9
29
 
@@ -13,7 +33,7 @@ module FastGettext
13
33
 
14
34
  mo_file = FastGettext::GetText::MOFile.new
15
35
  parser.parse(File.read(file), mo_file)
16
- MoFile.new(mo_file)
36
+ mo_file
17
37
  end
18
38
  end
19
39
  end
@@ -4,14 +4,13 @@ module FastGettext
4
4
  module TranslationRepository
5
5
  extend self
6
6
 
7
- # only single-word types supported atm (mytype works, MyType will not)
8
7
  def build(name, options)
9
8
  type = options[:type] || :mo
10
- class_name = type.to_s.capitalize
9
+ class_name = type.to_s.split('_').map(&:capitalize).join
11
10
  unless FastGettext::TranslationRepository.constants.map{|c|c.to_s}.include?(class_name)
12
- require "fast_gettext/translation_repository/#{type}"
11
+ require "fast_gettext/translation_repository/#{type}"
13
12
  end
14
13
  eval(class_name).new(name,options)
15
14
  end
16
15
  end
17
- end
16
+ end
@@ -7,6 +7,7 @@ module FastGettext
7
7
  class Mo < Base
8
8
  def initialize(name,options={})
9
9
  super
10
+ @eager_load = options.fetch(:eager_load, false)
10
11
  reload
11
12
  end
12
13
 
@@ -28,7 +29,7 @@ module FastGettext
28
29
  def find_and_store_files(name,options)
29
30
  # parse all .mo files with the right name, that sit in locale/LC_MESSAGES folders
30
31
  find_files_in_locale_folders(File.join('LC_MESSAGES',"#{name}.mo"), options[:path]) do |locale,file|
31
- MoFile.new(file)
32
+ MoFile.new(file, eager_load: @eager_load)
32
33
  end
33
34
  end
34
35
 
@@ -10,7 +10,7 @@ module FastGettext
10
10
  def find_and_store_files(name, options)
11
11
  require 'fast_gettext/po_file'
12
12
  find_files_in_locale_folders("#{name}.po", options[:path]) do |locale,file|
13
- PoFile.to_mo_file(file, options)
13
+ PoFile.new(file, options)
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module FastGettext
2
- VERSION = Version = '1.0.0'
2
+ VERSION = Version = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_gettext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.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: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 2.2.2
163
+ rubygems_version: 2.4.5.1
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: A simple, fast, memory-efficient and threadsafe implementation of GetText