fast_gettext 1.8.0 → 2.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -3
- data/Readme.md +142 -51
- data/lib/fast_gettext/cache.rb +4 -2
- data/lib/fast_gettext/mo_file.rb +29 -19
- data/lib/fast_gettext/po_file.rb +17 -14
- data/lib/fast_gettext/storage.rb +38 -32
- data/lib/fast_gettext/translation.rb +79 -113
- data/lib/fast_gettext/translation_repository/base.rb +9 -6
- data/lib/fast_gettext/translation_repository/chain.rb +11 -5
- data/lib/fast_gettext/translation_repository/db.rb +12 -13
- data/lib/fast_gettext/translation_repository/db_models/translation_key.rb +11 -8
- data/lib/fast_gettext/translation_repository/db_models/translation_text.rb +4 -2
- data/lib/fast_gettext/translation_repository/logger.rb +4 -2
- data/lib/fast_gettext/translation_repository/merge.rb +9 -4
- data/lib/fast_gettext/translation_repository/mo.rb +8 -4
- data/lib/fast_gettext/translation_repository/po.rb +5 -2
- data/lib/fast_gettext/translation_repository/yaml.rb +10 -4
- data/lib/fast_gettext/translation_repository.rb +5 -5
- data/lib/fast_gettext/version.rb +3 -1
- data/lib/fast_gettext.rb +16 -16
- metadata +33 -6
|
@@ -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
|
|
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(
|
|
69
|
-
@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
|
-
|
|
6
|
+
# Responsibility:
|
|
5
7
|
# - find and store mo files
|
|
6
8
|
# - provide access to translations in mo files
|
|
7
9
|
class Mo < Base
|
|
8
|
-
|
|
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 |
|
|
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
|
-
|
|
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 |
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
|
10
|
+
unless FastGettext::TranslationRepository.constants.map(&:to_s).include?(class_name)
|
|
11
11
|
require "fast_gettext/translation_repository/#{type}"
|
|
12
12
|
end
|
|
13
|
-
|
|
13
|
+
const_get(class_name).new(name, options)
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
end
|
data/lib/fast_gettext/version.rb
CHANGED
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
|
-
|
|
10
|
-
extend
|
|
11
|
+
extend FastGettext::Storage
|
|
12
|
+
extend FastGettext::Translation
|
|
11
13
|
|
|
12
|
-
LOCALE_REX =
|
|
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
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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.
|
|
4
|
+
version: 2.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:
|
|
11
|
+
date: 2021-08-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -95,7 +95,35 @@ dependencies:
|
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
|
-
name:
|
|
98
|
+
name: rubocop
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: single_cov
|
|
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: forking_test_runner
|
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
|
100
128
|
requirements:
|
|
101
129
|
- - ">="
|
|
@@ -153,15 +181,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
153
181
|
requirements:
|
|
154
182
|
- - ">="
|
|
155
183
|
- !ruby/object:Gem::Version
|
|
156
|
-
version: 2.
|
|
184
|
+
version: 2.5.0
|
|
157
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
186
|
requirements:
|
|
159
187
|
- - ">="
|
|
160
188
|
- !ruby/object:Gem::Version
|
|
161
189
|
version: '0'
|
|
162
190
|
requirements: []
|
|
163
|
-
|
|
164
|
-
rubygems_version: 2.7.6
|
|
191
|
+
rubygems_version: 3.2.16
|
|
165
192
|
signing_key:
|
|
166
193
|
specification_version: 4
|
|
167
194
|
summary: A simple, fast, memory-efficient and threadsafe implementation of GetText
|