r18n-rails-api 2.2.0 → 3.0.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 +5 -5
- data/.rspec +1 -1
- data/Rakefile +5 -3
- data/lib/r18n-rails-api.rb +21 -23
- data/lib/r18n-rails-api/backend.rb +40 -37
- data/lib/r18n-rails-api/filters.rb +23 -21
- data/lib/r18n-rails-api/loader.rb +28 -25
- data/lib/r18n-rails-api/rails_plural.rb +18 -18
- data/r18n-rails-api.gemspec +6 -4
- data/spec/backend_spec.rb +29 -28
- data/spec/data/simple/ru.rb +3 -1
- data/spec/filters_spec.rb +17 -13
- data/spec/loader_spec.rb +22 -20
- data/spec/spec_helper.rb +7 -5
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4e6b0328797e38e0c254f9cb16d766dba6e25cfec33f159b047962a0d8964b7f
|
4
|
+
data.tar.gz: f28b4872106cf2ac7df1fd1af0f8a528154be49fb8f1730fd2d900718df094b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c18011d243cde29d90eace25a276c5d2de4a41c3849614c9759921c7c36b9ccf6f3f4b9b0b05b8c70acaa98b9e06ce15fd6d3361e78a3b5662c4c2a98f47e70
|
7
|
+
data.tar.gz: 915a2058918ec20875a6aa32fb763afd16cb08353eaa00f0639568d4062668f8f6ddee42f98dca1f68401f6b288251d0d646771b584411ae582d106383ee9d0b
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--format documentation --colour
|
1
|
+
--format documentation --colour --warnings --require spec_helper
|
data/Rakefile
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/setup'
|
2
4
|
Bundler::GemHelper.install_tasks
|
3
5
|
|
4
6
|
require 'rspec/core/rake_task'
|
5
7
|
RSpec::Core::RakeTask.new
|
6
|
-
task :
|
8
|
+
task default: :spec
|
7
9
|
|
8
10
|
task :clobber_package do
|
9
|
-
|
11
|
+
rm_rf 'pkg'
|
10
12
|
end
|
11
|
-
task :
|
13
|
+
task clobber: [:clobber_package]
|
data/lib/r18n-rails-api.rb
CHANGED
@@ -1,27 +1,25 @@
|
|
1
|
-
|
2
|
-
Rails I18n compatibility for R18n.
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
# Rails I18n compatibility for R18n.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
5
19
|
|
6
|
-
This program is free software: you can redistribute it and/or modify
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
9
|
-
(at your option) any later version.
|
10
|
-
|
11
|
-
This program is distributed in the hope that it will be useful,
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
GNU Lesser General Public License for more details.
|
15
|
-
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
17
|
-
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
=end
|
19
|
-
|
20
|
-
require 'pathname'
|
21
20
|
require 'r18n-core'
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
require dir + 'backend'
|
22
|
+
require_relative 'r18n-rails-api/rails_plural'
|
23
|
+
require_relative 'r18n-rails-api/filters'
|
24
|
+
require_relative 'r18n-rails-api/loader'
|
25
|
+
require_relative 'r18n-rails-api/backend'
|
@@ -1,21 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
the
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# R18n backend for Rails I18n.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
require 'i18n/backend/transliterator'
|
21
21
|
|
@@ -29,7 +29,7 @@ module R18n
|
|
29
29
|
class Backend
|
30
30
|
include ::I18n::Backend::Transliterator
|
31
31
|
|
32
|
-
RESERVED_KEYS = [
|
32
|
+
RESERVED_KEYS = %i[scope default separator].freeze
|
33
33
|
|
34
34
|
# Find translation in R18n. It didn’t use +locale+ argument, only current
|
35
35
|
# R18n I18n object. Also it doesn’t support Proc and variables in +default+
|
@@ -38,12 +38,12 @@ module R18n
|
|
38
38
|
return key.map { |k| translate(locale, k, options) } if key.is_a?(Array)
|
39
39
|
|
40
40
|
scope, default, separator = options.values_at(*RESERVED_KEYS)
|
41
|
-
params = options.reject { |name,
|
41
|
+
params = options.reject { |name, _value| RESERVED_KEYS.include?(name) }
|
42
42
|
|
43
43
|
result = lookup(locale, scope, key, separator, params)
|
44
44
|
|
45
45
|
if result.is_a? Untranslated
|
46
|
-
options = options.reject { |
|
46
|
+
options = options.reject { |opts_key, _value| opts_key == :default }
|
47
47
|
|
48
48
|
default = [] if default.nil?
|
49
49
|
default = [default] unless default.is_a? Array
|
@@ -73,7 +73,7 @@ module R18n
|
|
73
73
|
# Support Rails I18n (+:default+, +:short+, +:long+, +:long_ordinal+,
|
74
74
|
# +:only_day+ and +:only_second+) and R18n (+:full+, +:human+, +:standard+
|
75
75
|
# and +:month+) time formatters.
|
76
|
-
def localize(locale, object, format = :default,
|
76
|
+
def localize(locale, object, format = :default, _options = {})
|
77
77
|
i18n = get_i18n(locale)
|
78
78
|
if format.is_a? Symbol
|
79
79
|
key = format
|
@@ -117,11 +117,12 @@ module R18n
|
|
117
117
|
|
118
118
|
def translation_to_hash(translation)
|
119
119
|
Utils.hash_map(translation.to_hash) do |key, value|
|
120
|
-
value =
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
120
|
+
value =
|
121
|
+
if value.is_a? Hash
|
122
|
+
translation_to_hash(value)
|
123
|
+
else
|
124
|
+
format_value(value)
|
125
|
+
end
|
125
126
|
[key.to_sym, value]
|
126
127
|
end
|
127
128
|
end
|
@@ -129,23 +130,25 @@ module R18n
|
|
129
130
|
# Find translation by <tt>scope.key(params)</tt> in current R18n I18n
|
130
131
|
# object.
|
131
132
|
def lookup(locale, scope, key, separator, params)
|
132
|
-
keys = (Array(scope) + Array(key))
|
133
|
-
k.to_s.split(separator || ::I18n.default_separator) }
|
133
|
+
keys = (Array(scope) + Array(key))
|
134
|
+
.map { |k| k.to_s.split(separator || ::I18n.default_separator) }
|
135
|
+
.flatten
|
134
136
|
last = keys.pop.to_sym
|
135
137
|
|
136
|
-
result = keys.inject(get_i18n(locale).t) do |node,
|
138
|
+
result = keys.inject(get_i18n(locale).t) do |node, iterated_key|
|
137
139
|
if node.is_a? TranslatedString
|
138
|
-
node.get_untranslated(
|
140
|
+
node.get_untranslated(iterated_key)
|
139
141
|
else
|
140
|
-
node[
|
142
|
+
node[iterated_key]
|
141
143
|
end
|
142
144
|
end
|
143
145
|
|
144
|
-
result =
|
145
|
-
result.
|
146
|
-
|
147
|
-
|
148
|
-
|
146
|
+
result =
|
147
|
+
if result.is_a? TranslatedString
|
148
|
+
result.get_untranslated(key)
|
149
|
+
else
|
150
|
+
result[last, params]
|
151
|
+
end
|
149
152
|
|
150
153
|
format_value(result)
|
151
154
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
|
2
|
-
Filters for Rails I18n compatibility for R18n.
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
# Filters for Rails I18n compatibility for R18n.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
# Filter to use Rails named variables:
|
21
21
|
#
|
@@ -53,14 +53,16 @@ end
|
|
53
53
|
|
54
54
|
# Pluralization by named variable <tt>%{count}</tt>.
|
55
55
|
R18n::Filters.add('pl', :named_pluralization) do |content, config, param|
|
56
|
-
if param.is_a?
|
56
|
+
if param.is_a?(Hash) && param.key?(:count)
|
57
57
|
hash = content.to_hash
|
58
58
|
type = config[:locale].pluralize(param[:count])
|
59
|
-
type = 'n'
|
59
|
+
type = 'n' unless hash.key?(type)
|
60
60
|
hash[type]
|
61
61
|
elsif content.is_a? R18n::UnpluralizetedTranslation
|
62
|
-
R18n::RailsUnpluralizetedTranslation.new(
|
63
|
-
|
62
|
+
R18n::RailsUnpluralizetedTranslation.new(
|
63
|
+
config[:locale], config[:path],
|
64
|
+
locale: config[:locale], translations: content.to_hash
|
65
|
+
)
|
64
66
|
else
|
65
67
|
content
|
66
68
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
|
2
|
-
Loader for Rails translations.
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
# Loader for Rails translations.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
require 'i18n'
|
21
21
|
|
@@ -56,7 +56,7 @@ module R18n
|
|
56
56
|
|
57
57
|
# Reload backend if <tt>I18n.load_path</tt> is changed.
|
58
58
|
def reload!
|
59
|
-
return if @last_path == ::I18n.load_path
|
59
|
+
return if defined?(@last_path) && @last_path == ::I18n.load_path
|
60
60
|
@last_path = ::I18n.load_path.clone
|
61
61
|
@backend.reload!
|
62
62
|
@backend.send(:init_translations)
|
@@ -69,8 +69,8 @@ module R18n
|
|
69
69
|
end
|
70
70
|
|
71
71
|
# Is another +loader+ is also load Rails translations.
|
72
|
-
def ==(
|
73
|
-
self.class ==
|
72
|
+
def ==(other)
|
73
|
+
self.class == other.class
|
74
74
|
end
|
75
75
|
|
76
76
|
protected
|
@@ -80,14 +80,17 @@ module R18n
|
|
80
80
|
if value.is_a? Hash
|
81
81
|
if value.empty?
|
82
82
|
value
|
83
|
-
elsif value.keys.inject(true) { |a, i| a
|
84
|
-
Typed.new(
|
85
|
-
|
86
|
-
|
83
|
+
elsif value.keys.inject(true) { |a, i| a && RailsPlural.is_rails?(i) }
|
84
|
+
Typed.new(
|
85
|
+
'pl',
|
86
|
+
R18n::Utils.hash_map(value) do |k, v|
|
87
|
+
[RailsPlural.to_r18n(k), transform(v)]
|
88
|
+
end
|
89
|
+
)
|
87
90
|
else
|
88
91
|
Utils.hash_map(value) { |k, v| [k.to_s, transform(v)] }
|
89
92
|
end
|
90
|
-
elsif @private_type_class
|
93
|
+
elsif defined?(@private_type_class) && value.is_a?(@private_type_class)
|
91
94
|
Typed.new(value.type_id, value.value)
|
92
95
|
else
|
93
96
|
value
|
@@ -1,28 +1,28 @@
|
|
1
|
-
|
2
|
-
Converter between R18n and Rails I18n plural keys.
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
# Converter between R18n and Rails I18n plural keys.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
module R18n
|
21
21
|
# Converter between R18n and Rails I18n plural keys.
|
22
22
|
class RailsPlural
|
23
23
|
# Check, that +key+ is Rails plural key.
|
24
24
|
def self.is_rails?(k)
|
25
|
-
[
|
25
|
+
%i[zero one few many other].include? k
|
26
26
|
end
|
27
27
|
|
28
28
|
# Convert Rails I18n plural key to R18n.
|
data/r18n-rails-api.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../r18n-core/lib/r18n-core/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
6
|
s.platform = Gem::Platform::RUBY
|
@@ -7,14 +9,14 @@ Gem::Specification.new do |s|
|
|
7
9
|
s.date = Time.now.strftime('%Y-%m-%d')
|
8
10
|
|
9
11
|
s.summary = 'Rails I18n compatibility for R18n'
|
10
|
-
s.description = <<-
|
12
|
+
s.description = <<-DESC
|
11
13
|
R18n backend for Rails I18n and R18n filters and loader to support Rails
|
12
14
|
translation format.
|
13
15
|
R18n has nice Ruby-style syntax, filters, flexible locales, custom loaders,
|
14
16
|
translation support for any classes, time and number localization, several
|
15
17
|
user language support, agnostic core package with out-of-box support for
|
16
18
|
Rails, Sinatra and desktop applications.
|
17
|
-
|
19
|
+
DESC
|
18
20
|
|
19
21
|
s.files = `git ls-files`.split("\n")
|
20
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -26,6 +28,6 @@ Gem::Specification.new do |s|
|
|
26
28
|
s.homepage = 'https://github.com/ai/r18n/tree/master/r18n-rails-api'
|
27
29
|
s.license = 'LGPL-3'
|
28
30
|
|
29
|
-
s.add_dependency 'r18n-core', "= #{R18n::VERSION}"
|
30
31
|
s.add_dependency 'i18n'
|
32
|
+
s.add_dependency 'r18n-core', "= #{R18n::VERSION}"
|
31
33
|
end
|
data/spec/backend_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Backend do
|
4
4
|
before do
|
@@ -8,11 +8,11 @@ describe R18n::Backend do
|
|
8
8
|
R18n.set('en')
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
12
|
-
expect(I18n.available_locales).to match_array([
|
11
|
+
it 'returns available locales' do
|
12
|
+
expect(I18n.available_locales).to match_array(%i[en ru])
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'localizes objects' do
|
16
16
|
time = Time.at(0).utc
|
17
17
|
date = Date.parse('1970-01-01')
|
18
18
|
|
@@ -25,66 +25,67 @@ describe R18n::Backend do
|
|
25
25
|
expect(I18n.l(-5000.5)).to eq '−5,000.5'
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'translates by key and scope' do
|
29
29
|
expect(I18n.t('in.another.level')).to eq 'Hierarchical'
|
30
30
|
expect(I18n.t(:level, scope: 'in.another')).to eq 'Hierarchical'
|
31
31
|
expect(I18n.t(:'another.level', scope: 'in')).to eq 'Hierarchical'
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
34
|
+
it 'uses pluralization and variables' do
|
35
35
|
expect(I18n.t('users', count: 0)).to eq '0 users'
|
36
36
|
expect(I18n.t('users', count: 1)).to eq '1 user'
|
37
37
|
expect(I18n.t('users', count: 5)).to eq '5 users'
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'uses another separator' do
|
41
41
|
expect(I18n.t('in/another/level', separator: '/')).to eq 'Hierarchical'
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'translates array' do
|
45
45
|
expect(I18n.t(['in.another.level', 'in.default'])).to eq(
|
46
|
-
[
|
46
|
+
%w[Hierarchical Default]
|
47
|
+
)
|
47
48
|
end
|
48
49
|
|
49
|
-
it
|
50
|
+
it 'uses default value' do
|
50
51
|
expect(I18n.t(:missed, default: 'Default')).to eq 'Default'
|
51
52
|
expect(I18n.t(:missed, default: :default, scope: :in)).to eq 'Default'
|
52
|
-
expect(I18n.t(:missed, default: [
|
53
|
+
expect(I18n.t(:missed, default: %i[also_no in.default])).to eq 'Default'
|
53
54
|
expect(I18n.t(:missed, default: proc { |key| key.to_s })).to eq 'missed'
|
54
55
|
end
|
55
56
|
|
56
|
-
it
|
57
|
-
expect(
|
57
|
+
it 'raises error on no translation' do
|
58
|
+
expect(lambda {
|
58
59
|
I18n.backend.translate(:en, :missed)
|
59
60
|
}).to raise_error(::I18n::MissingTranslationData)
|
60
61
|
|
61
|
-
expect(
|
62
|
+
expect(lambda {
|
62
63
|
I18n.t(:missed)
|
63
64
|
}).to raise_error(::I18n::MissingTranslationData)
|
64
65
|
end
|
65
66
|
|
66
|
-
it
|
67
|
+
it 'reloads translations' do
|
67
68
|
expect(-> { I18n.t(:other) }).to raise_error(::I18n::MissingTranslationData)
|
68
69
|
I18n.load_path << OTHER
|
69
70
|
I18n.reload!
|
70
71
|
expect(I18n.t(:other)).to eq 'Other'
|
71
72
|
end
|
72
73
|
|
73
|
-
it
|
74
|
+
it 'returns plain classes' do
|
74
75
|
expect(I18n.t('in.another.level').class).to eq ActiveSupport::SafeBuffer
|
75
76
|
expect(I18n.t('in.another').class).to eq Hash
|
76
77
|
end
|
77
78
|
|
78
|
-
it
|
79
|
-
expect(I18n.t('users')).to eq
|
79
|
+
it 'returns correct unpluralized hash' do
|
80
|
+
expect(I18n.t('users')).to eq(one: '1 user', other: '%{count} users')
|
80
81
|
end
|
81
82
|
|
82
|
-
it
|
83
|
-
expect(
|
83
|
+
it 'corrects detect untranslated, whem path is deeper than string' do
|
84
|
+
expect(lambda {
|
84
85
|
I18n.t('in.another.level.deeper')
|
85
86
|
}).to raise_error(::I18n::MissingTranslationData)
|
86
87
|
|
87
|
-
expect(
|
88
|
+
expect(lambda {
|
88
89
|
I18n.t('in.another.level.go.deeper')
|
89
90
|
}).to raise_error(::I18n::MissingTranslationData)
|
90
91
|
end
|
@@ -94,23 +95,23 @@ describe R18n::Backend do
|
|
94
95
|
end
|
95
96
|
|
96
97
|
it "doesn't call object methods" do
|
97
|
-
expect(
|
98
|
+
expect(lambda {
|
98
99
|
I18n.t('in.another.level.to_sym')
|
99
100
|
}).to raise_error(::I18n::MissingTranslationData)
|
100
101
|
end
|
101
102
|
|
102
|
-
it
|
103
|
+
it 'works deeper pluralization' do
|
103
104
|
expect(I18n.t('users.other', count: 5)).to eq '5 users'
|
104
105
|
end
|
105
106
|
|
106
|
-
it
|
107
|
-
expect(I18n.t('in')).to eq(
|
107
|
+
it 'returns hash with symbols keys' do
|
108
|
+
expect(I18n.t('in')).to eq(
|
108
109
|
another: { level: 'Hierarchical' },
|
109
110
|
default: 'Default'
|
110
|
-
|
111
|
+
)
|
111
112
|
end
|
112
113
|
|
113
|
-
it
|
114
|
+
it 'changes locale in place' do
|
114
115
|
I18n.load_path << PL
|
115
116
|
expect(I18n.t('users', count: 5)).to eq '5 users'
|
116
117
|
expect(I18n.t('users', count: 5, locale: :ru)).to eq 'Много'
|
@@ -118,7 +119,7 @@ describe R18n::Backend do
|
|
118
119
|
expect(I18n.l(Date.parse('1970-01-01'), locale: :ru)).to eq '01.01.1970'
|
119
120
|
end
|
120
121
|
|
121
|
-
it
|
122
|
+
it 'has transliterate method' do
|
122
123
|
expect(I18n.transliterate('café')).to eq 'cafe'
|
123
124
|
end
|
124
125
|
end
|
data/spec/data/simple/ru.rb
CHANGED
data/spec/filters_spec.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe 'Rails filters' do
|
4
|
-
it
|
5
|
-
i18n = R18n::Translation.new(
|
6
|
-
translations: { 'echo' => 'Value is %{value}' }
|
4
|
+
it 'uses named variables' do
|
5
|
+
i18n = R18n::Translation.new(
|
6
|
+
EN, '', locale: EN, translations: { 'echo' => 'Value is %{value}' }
|
7
|
+
)
|
7
8
|
|
8
9
|
expect(i18n.echo(value: 'R18n')).to eq 'Value is R18n'
|
9
10
|
expect(i18n.echo(value: -5.5)).to eq 'Value is −5.5'
|
@@ -12,21 +13,24 @@ describe 'Rails filters' do
|
|
12
13
|
expect(i18n.echo).to eq 'Value is %{value}'
|
13
14
|
end
|
14
15
|
|
15
|
-
it
|
16
|
-
i18n = R18n::Translation.new(
|
17
|
-
translations: { 'echo' => 'Value is {{value}}' }
|
16
|
+
it 'uses old variables syntax' do
|
17
|
+
i18n = R18n::Translation.new(
|
18
|
+
EN, '', locale: EN, translations: { 'echo' => 'Value is {{value}}' }
|
19
|
+
)
|
18
20
|
expect(i18n.echo(value: 'Old')).to eq 'Value is Old'
|
19
21
|
end
|
20
22
|
|
21
|
-
it
|
22
|
-
i18n = R18n::Translation.new(
|
23
|
-
translations: {
|
24
|
-
'users' => R18n::Typed.new(
|
23
|
+
it 'pluralizes by variable %{count}' do
|
24
|
+
i18n = R18n::Translation.new(
|
25
|
+
EN, '', locale: EN, translations: {
|
26
|
+
'users' => R18n::Typed.new(
|
27
|
+
'pl',
|
25
28
|
0 => 'no users',
|
26
29
|
1 => '1 user',
|
27
30
|
'n' => '%{count} users'
|
28
|
-
|
29
|
-
}
|
31
|
+
)
|
32
|
+
}
|
33
|
+
)
|
30
34
|
|
31
35
|
expect(i18n.users(count: 0)).to eq 'no users'
|
32
36
|
expect(i18n.users(count: 1)).to eq '1 user'
|
data/spec/loader_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Loader::Rails do
|
4
4
|
before do
|
@@ -6,51 +6,53 @@ describe R18n::Loader::Rails do
|
|
6
6
|
@loader = R18n::Loader::Rails.new
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'returns available locales' do
|
10
10
|
expect(@loader.available).to match_array([DECH, EN, RU])
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
expect(@loader.load(RU)).to eq(
|
13
|
+
it 'loads translation' do
|
14
|
+
expect(@loader.load(RU)).to eq('one' => 'Один', 'two' => 'Два')
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
expect(@loader.load(DECH)).to eq(
|
17
|
+
it 'loads translation for dialects' do
|
18
|
+
expect(@loader.load(DECH)).to eq('a' => 1)
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
expect(@loader.load(EN)).to eq(
|
23
|
-
'users' => R18n::Typed.new(
|
21
|
+
it 'changes pluralization' do
|
22
|
+
expect(@loader.load(EN)).to eq(
|
23
|
+
'users' => R18n::Typed.new(
|
24
|
+
'pl',
|
24
25
|
0 => 'Zero',
|
25
26
|
1 => 'One',
|
26
27
|
2 => 'Few',
|
27
28
|
'n' => 'Other'
|
28
|
-
|
29
|
-
|
29
|
+
)
|
30
|
+
)
|
30
31
|
end
|
31
32
|
|
32
|
-
it
|
33
|
+
it 'changes Russian pluralization' do
|
33
34
|
I18n.load_path = [PL]
|
34
|
-
expect(@loader.load(RU)).to eq(
|
35
|
-
'users' => R18n::Typed.new(
|
35
|
+
expect(@loader.load(RU)).to eq(
|
36
|
+
'users' => R18n::Typed.new(
|
37
|
+
'pl',
|
36
38
|
0 => 'Ноль',
|
37
39
|
1 => 'Один',
|
38
40
|
2 => 'Несколько',
|
39
41
|
'n' => 'Много'
|
40
|
-
|
41
|
-
|
42
|
+
)
|
43
|
+
)
|
42
44
|
end
|
43
45
|
|
44
|
-
it
|
46
|
+
it 'reloads translations on load_path changes' do
|
45
47
|
I18n.load_path << OTHER
|
46
|
-
expect(@loader.load(RU)).to eq(
|
48
|
+
expect(@loader.load(RU)).to eq(
|
47
49
|
'one' => 'Один',
|
48
50
|
'two' => 'Два',
|
49
51
|
'three' => 'Три'
|
50
|
-
|
52
|
+
)
|
51
53
|
end
|
52
54
|
|
53
|
-
it
|
55
|
+
it 'changes hash on load_path changes' do
|
54
56
|
before = @loader.hash
|
55
57
|
I18n.load_path << OTHER
|
56
58
|
expect(@loader.hash).not_to eq before
|
data/spec/spec_helper.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pp'
|
2
4
|
require 'i18n'
|
3
5
|
require 'active_support'
|
4
6
|
|
5
7
|
I18n.enforce_available_locales = true
|
6
8
|
|
7
|
-
|
9
|
+
require_relative '../lib/r18n-rails-api'
|
8
10
|
|
9
11
|
EN = R18n.locale(:en)
|
10
12
|
RU = R18n.locale(:ru)
|
11
13
|
DECH = R18n.locale(:'de-CH')
|
12
14
|
|
13
|
-
GENERAL = Dir.glob(File.join(
|
14
|
-
SIMPLE = Dir.glob(File.join(
|
15
|
-
OTHER = Dir.glob(File.join(
|
16
|
-
PL = Dir.glob(File.join(
|
15
|
+
GENERAL = Dir.glob(File.join(__dir__, 'data', 'general', '*'))
|
16
|
+
SIMPLE = Dir.glob(File.join(__dir__, 'data', 'simple', '*'))
|
17
|
+
OTHER = Dir.glob(File.join(__dir__, 'data', 'other', '*'))
|
18
|
+
PL = Dir.glob(File.join(__dir__, 'data', 'pl', '*'))
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-rails-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Sitnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: i18n
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: r18n-core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.0.0
|
41
41
|
description: |2
|
42
42
|
R18n backend for Rails I18n and R18n filters and loader to support Rails
|
43
43
|
translation format.
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.7.6
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: Rails I18n compatibility for R18n
|