fast_gettext 1.8.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fast_gettext/translation_repository/po'
2
4
 
3
5
  module FastGettext
@@ -7,7 +9,7 @@ module FastGettext
7
9
  # - can be used instead of searching for translations in multiple domains
8
10
  # - requires reload when current locale is changed
9
11
  class Merge < Base
10
- def initialize(name, options={})
12
+ def initialize(name, options = {})
11
13
  clear
12
14
  super(name, options)
13
15
  options.fetch(:chain, []).each do |repo|
@@ -21,7 +23,9 @@ module FastGettext
21
23
 
22
24
  def pluralisation_rule
23
25
  @repositories.each do |r|
24
- result = r.pluralisation_rule and return result
26
+ if result = r.pluralisation_rule
27
+ return result
28
+ end
25
29
  end
26
30
  nil
27
31
  end
@@ -45,6 +49,7 @@ module FastGettext
45
49
 
46
50
  def add_repo(repo)
47
51
  raise "Unsupported repository" unless repo_supported?(repo)
52
+
48
53
  @repositories << repo
49
54
  load_repo(repo)
50
55
  true
@@ -65,8 +70,8 @@ module FastGettext
65
70
  repo.respond_to?(:all_translations)
66
71
  end
67
72
 
68
- def load_repo(r)
69
- @data = r.all_translations.merge(@data)
73
+ def load_repo(repo)
74
+ @data = repo.all_translations.merge(@data)
70
75
  end
71
76
  end
72
77
  end
@@ -1,11 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fast_gettext/translation_repository/base'
2
4
  module FastGettext
3
5
  module TranslationRepository
4
- # Responsibility:
6
+ # Responsibility:
5
7
  # - find and store mo files
6
8
  # - provide access to translations in mo files
7
9
  class Mo < Base
8
- def initialize(name,options={})
10
+ CONTEXT_SEPARATOR = "\u0004"
11
+
12
+ def initialize(name, options = {})
9
13
  super
10
14
  @eager_load = options.fetch(:eager_load, false)
11
15
  reload
@@ -30,9 +34,9 @@ module FastGettext
30
34
 
31
35
  protected
32
36
 
33
- def find_and_store_files(name,options)
37
+ def find_and_store_files(name, options)
34
38
  # parse all .mo files with the right name, that sit in locale/LC_MESSAGES folders
35
- find_files_in_locale_folders(File.join('LC_MESSAGES',"#{name}.mo"), options[:path]) do |locale,file|
39
+ find_files_in_locale_folders(File.join('LC_MESSAGES', "#{name}.mo"), options[:path]) do |_locale, file|
36
40
  MoFile.new(file, eager_load: @eager_load)
37
41
  end
38
42
  end
@@ -1,15 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fast_gettext/translation_repository/base'
2
4
  require 'fast_gettext/translation_repository/mo'
3
5
  module FastGettext
4
6
  module TranslationRepository
5
- # Responsibility:
7
+ # Responsibility:
6
8
  # - find and store po files
7
9
  # - provide access to translations in po files
8
10
  class Po < Mo
9
11
  protected
12
+
10
13
  def find_and_store_files(name, options)
11
14
  require 'fast_gettext/po_file'
12
- find_files_in_locale_folders("#{name}.po", options[:path]) do |locale,file|
15
+ find_files_in_locale_folders("#{name}.po", options[:path]) do |_locale, file|
13
16
  PoFile.new(file, options)
14
17
  end
15
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fast_gettext/translation_repository/base'
2
4
  require 'yaml'
3
5
 
@@ -7,7 +9,7 @@ module FastGettext
7
9
  # - find and store yaml files
8
10
  # - provide access to translations in yaml files
9
11
  class Yaml < Base
10
- def initialize(name,options={})
12
+ def initialize(name, options = {})
11
13
  super
12
14
  reload
13
15
  end
@@ -23,7 +25,11 @@ module FastGettext
23
25
  end
24
26
 
25
27
  def pluralisation_rule
26
- self['pluralisation_rule'] ? lambda{|n| eval(self['pluralisation_rule']) } : nil
28
+ return unless rule = self['pluralisation_rule']
29
+
30
+ ->(n) do # rubocop:disable Lint/UnusedBlockArgument n can be used from pluralisation_rule code
31
+ eval(rule) # rubocop:disable Security/Eval TODO remove eval
32
+ end
27
33
  end
28
34
 
29
35
  def reload
@@ -64,7 +70,7 @@ module FastGettext
64
70
 
65
71
  def add_yaml_key(result, prefix, hash)
66
72
  hash.each_pair do |key, value|
67
- if value.kind_of?(Hash)
73
+ if value.is_a?(Hash)
68
74
  add_yaml_key(result, yaml_dot_notation(prefix, key), value)
69
75
  else
70
76
  result[yaml_dot_notation(prefix, key)] = value
@@ -73,7 +79,7 @@ module FastGettext
73
79
  result
74
80
  end
75
81
 
76
- def yaml_dot_notation(a,b)
82
+ def yaml_dot_notation(a, b) # rubocop:disable Naming/UncommunicativeMethodParamName
77
83
  a ? "#{a}.#{b}" : b
78
84
  end
79
85
  end
@@ -1,16 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FastGettext
2
4
  # Responsibility:
3
5
  # - decide which repository to choose from given input
4
6
  module TranslationRepository
5
- extend self
6
-
7
- def build(name, options)
7
+ def self.build(name, options)
8
8
  type = options[:type] || :mo
9
9
  class_name = type.to_s.split('_').map(&:capitalize).join
10
- unless FastGettext::TranslationRepository.constants.map{|c|c.to_s}.include?(class_name)
10
+ unless FastGettext::TranslationRepository.constants.map(&:to_s).include?(class_name)
11
11
  require "fast_gettext/translation_repository/#{type}"
12
12
  end
13
- eval(class_name).new(name,options)
13
+ const_get(class_name).new(name, options)
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FastGettext
2
- VERSION = Version = '1.8.0'
4
+ VERSION = Version = '2.3.0' # rubocop:disable Naming/ConstantName
3
5
  end
data/lib/fast_gettext.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fast_gettext/mo_file'
2
4
  require 'fast_gettext/storage'
3
5
  require 'fast_gettext/translation'
@@ -6,30 +8,28 @@ require 'fast_gettext/vendor/string'
6
8
  require 'fast_gettext/version'
7
9
 
8
10
  module FastGettext
9
- include FastGettext::Storage
10
- extend self
11
+ extend FastGettext::Storage
12
+ extend FastGettext::Translation
11
13
 
12
- LOCALE_REX = /^[a-z]{2,3}$|^[a-z]{2,3}_[A-Z]{2,3}$/
14
+ LOCALE_REX = /^[a-z]{2,3}$|^[a-z]{2,3}_[A-Z]{2,3}$/.freeze
13
15
  NAMESPACE_SEPARATOR = '|'
16
+ CONTEXT_SEPARATOR = "\004"
14
17
 
15
- # users should not include FastGettext, since this would contaminate their namespace
16
- # rather use
17
- # FastGettext.locale = ..
18
- # FastGettext.text_domain = ..
19
- # and
20
- # include FastGettext::Translation
21
- FastGettext::Translation.public_instance_methods.each do |method|
22
- define_method method do |*args|
23
- Translation.send(method,*args)
24
- end
18
+ # helper block for changing domains
19
+ def self.with_domain(domain)
20
+ old_domain = FastGettext.text_domain
21
+ FastGettext.text_domain = domain
22
+ yield
23
+ ensure
24
+ FastGettext.text_domain = old_domain
25
25
  end
26
26
 
27
- def add_text_domain(name,options)
28
- translation_repositories[name] = TranslationRepository.build(name,options)
27
+ def self.add_text_domain(name, options)
28
+ translation_repositories[name] = TranslationRepository.build(name, options)
29
29
  end
30
30
 
31
31
  # some repositories know where to store their locales
32
- def locale_path
32
+ def self.locale_path
33
33
  translation_repositories[text_domain].instance_variable_get(:@options)[:path]
34
34
  end
35
35
  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.8.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-08 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: wwtd
98
+ name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -108,13 +108,56 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description:
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-packaging
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: single_cov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: forking_test_runner
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description:
112
154
  email: michael@grosser.it
113
155
  executables: []
114
156
  extensions: []
115
157
  extra_rdoc_files: []
116
158
  files:
117
159
  - CHANGELOG
160
+ - LICENSE
118
161
  - Readme.md
119
162
  - lib/fast_gettext.rb
120
163
  - lib/fast_gettext/cache.rb
@@ -145,7 +188,7 @@ licenses:
145
188
  - MIT
146
189
  - Ruby
147
190
  metadata: {}
148
- post_install_message:
191
+ post_install_message:
149
192
  rdoc_options: []
150
193
  require_paths:
151
194
  - lib
@@ -153,16 +196,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
196
  requirements:
154
197
  - - ">="
155
198
  - !ruby/object:Gem::Version
156
- version: 2.1.0
199
+ version: 2.5.0
157
200
  required_rubygems_version: !ruby/object:Gem::Requirement
158
201
  requirements:
159
202
  - - ">="
160
203
  - !ruby/object:Gem::Version
161
204
  version: '0'
162
205
  requirements: []
163
- rubyforge_project:
164
- rubygems_version: 2.7.6
165
- signing_key:
206
+ rubygems_version: 3.3.3
207
+ signing_key:
166
208
  specification_version: 4
167
209
  summary: A simple, fast, memory-efficient and threadsafe implementation of GetText
168
210
  test_files: []