releaf-i18n_database 1.1.0 → 1.1.1
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/app/lib/releaf/i18n_database/translations_store.rb +1 -2
- data/lib/releaf-i18n_database.rb +1 -2
- data/lib/releaf/i18n_database/backend.rb +10 -5
- data/spec/features/translations_spec.rb +45 -0
- data/spec/lib/releaf/i18n_database/backend_spec.rb +2 -10
- data/spec/lib/releaf/i18n_database/translations_store_spec.rb +6 -24
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7ce7261adffcef80eeae554ebd065fd1184cb2e
|
4
|
+
data.tar.gz: b650feda888ca31f88229e99e45769b0bb102153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e18e5b7741bd21daec495cdbe6dae889a552214b453797f830e8ded89b045fa6958d1bd8186283ac08186b087691150b2039cc0bc2e28745334b0e354cf5643
|
7
|
+
data.tar.gz: b9b0051f920eb42253cefde4500261918462f44d2abefddf48c021fb7911df6e881473b1fa009ba7b846bdb1bdbed6ee07be13dbc65c5b115f58bb1b1f7fe8e1
|
@@ -56,8 +56,7 @@ class Releaf::I18nDatabase::TranslationsStore
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def valid_pluralized_result?(locale, count, result)
|
59
|
-
|
60
|
-
result.key?(TwitterCldr::Formatters::Plurals::Rules.rule_for(count, locale))
|
59
|
+
result.key?(I18n.t(:'i18n.plural.rule', locale: locale, resolve: false).call(count))
|
61
60
|
end
|
62
61
|
|
63
62
|
def returnable_result?(result, options)
|
data/lib/releaf-i18n_database.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'axlsx_rails'
|
2
|
-
require 'twitter_cldr'
|
3
2
|
require 'i18n'
|
3
|
+
require 'rails-i18n'
|
4
4
|
require 'roo'
|
5
5
|
|
6
6
|
module Releaf::I18nDatabase
|
@@ -13,4 +13,3 @@ module Releaf::I18nDatabase
|
|
13
13
|
[Releaf::I18nDatabase::Backend, Releaf::I18nDatabase::HumanizeMissingTranslations]
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
@@ -4,12 +4,15 @@ module Releaf
|
|
4
4
|
module I18nDatabase
|
5
5
|
class Backend
|
6
6
|
|
7
|
-
include ::I18n::Backend::Base
|
7
|
+
include ::I18n::Backend::Base
|
8
|
+
include ::I18n::Backend::Flatten
|
9
|
+
include ::I18n::Backend::Pluralization
|
10
|
+
|
8
11
|
UPDATED_AT_KEY = 'releaf.i18n_database.translations.updated_at'
|
9
12
|
DEFAULT_CONFIG = {
|
10
13
|
translation_auto_creation: true,
|
11
14
|
translation_auto_creation_patterns: [/.*/],
|
12
|
-
translation_auto_creation_exclusion_patterns: [/^attributes\./]
|
15
|
+
translation_auto_creation_exclusion_patterns: [/^attributes\./, /^i18n\./]
|
13
16
|
}
|
14
17
|
attr_accessor :translations_cache
|
15
18
|
|
@@ -18,9 +21,11 @@ module Releaf
|
|
18
21
|
end
|
19
22
|
|
20
23
|
def self.locales_pluralizations
|
21
|
-
Releaf.application.config.all_locales.map
|
22
|
-
|
23
|
-
|
24
|
+
keys = Releaf.application.config.all_locales.map{ |locale| I18n.t(:'i18n.plural.keys', locale: locale) }.flatten
|
25
|
+
# always add zero as it skipped for some locales even when there is zero form (lv for example)
|
26
|
+
keys << :zero
|
27
|
+
|
28
|
+
keys.uniq
|
24
29
|
end
|
25
30
|
|
26
31
|
def self.configure_component
|
@@ -335,6 +335,7 @@ feature "Translations" do
|
|
335
335
|
context "with nonexistent translation" do
|
336
336
|
before do
|
337
337
|
allow(Releaf.application.config).to receive(:all_locales).and_return(["ru", "lv"])
|
338
|
+
allow(I18n).to receive(:locale_available?).and_return(true)
|
338
339
|
end
|
339
340
|
|
340
341
|
it "creates empty translation" do
|
@@ -378,4 +379,48 @@ feature "Translations" do
|
|
378
379
|
end
|
379
380
|
end
|
380
381
|
end
|
382
|
+
|
383
|
+
|
384
|
+
describe "pluralization" do
|
385
|
+
|
386
|
+
before do
|
387
|
+
locales = [:lv, :ru]
|
388
|
+
allow(I18n.config).to receive(:available_locales).and_return(locales)
|
389
|
+
allow(Releaf.application.config).to receive(:available_locales).and_return(locales)
|
390
|
+
allow(Releaf.application.config).to receive(:all_locales).and_return(locales)
|
391
|
+
|
392
|
+
I18n.reload!
|
393
|
+
|
394
|
+
[:few, :many, :one, :other, :zero].each do |rule|
|
395
|
+
translation = Releaf::I18nDatabase::I18nEntry.create!(key: "public.years.#{rule}")
|
396
|
+
locales.each do |locale|
|
397
|
+
translation.i18n_entry_translation.create!( locale: locale.to_s, text: "years #{locale} #{rule} XX" )
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
Releaf::I18nDatabase::Backend.reset_cache
|
402
|
+
end
|
403
|
+
|
404
|
+
after do
|
405
|
+
# force I18n reloading to restore the original state.
|
406
|
+
# for this to work, the stubs must be removed beforehand
|
407
|
+
allow(I18n.config).to receive(:available_locales).and_call_original
|
408
|
+
allow(Releaf.application.config).to receive(:available_locales).and_call_original
|
409
|
+
allow(Releaf.application.config).to receive(:all_locales).and_call_original
|
410
|
+
I18n.reload!
|
411
|
+
end
|
412
|
+
|
413
|
+
it "uses rails-i18n pluralization mechanism to detect correct pluralization keys" do
|
414
|
+
expect(I18n.t("years", scope: "public", count: 0, locale: :lv)).to eq 'years lv zero XX'
|
415
|
+
expect(I18n.t("years", scope: "public", count: 1, locale: :lv)).to eq 'years lv one XX'
|
416
|
+
expect(I18n.t("years", scope: "public", count: 3, locale: :lv)).to eq 'years lv other XX'
|
417
|
+
|
418
|
+
expect(I18n.t("years", scope: "public", count: 1, locale: :ru)).to eq 'years ru one XX'
|
419
|
+
expect(I18n.t("years", scope: "public", count: 3, locale: :ru)).to eq 'years ru few XX'
|
420
|
+
expect(I18n.t("years", scope: "public", count: 5, locale: :ru)).to eq 'years ru many XX'
|
421
|
+
end
|
422
|
+
|
423
|
+
end
|
424
|
+
|
425
|
+
|
381
426
|
end
|
@@ -64,16 +64,8 @@ describe Releaf::I18nDatabase::Backend do
|
|
64
64
|
describe ".locales_pluralizations" do
|
65
65
|
it "returns array all pluralization forms for releaf locales" do
|
66
66
|
allow(Releaf.application.config).to receive(:all_locales).and_return([:de, :ru, :aasdsd])
|
67
|
-
|
68
|
-
|
69
|
-
allow(TwitterCldr::Formatters::Plurals::Rules).to receive(:all_for).with(:de).and_return([:one, :other, :many])
|
70
|
-
|
71
|
-
allow(TwitterCldr).to receive(:supported_locale?).with(:ru).and_return(true)
|
72
|
-
allow(TwitterCldr::Formatters::Plurals::Rules).to receive(:all_for).with(:ru).and_return([:one, :other, :few, :zero])
|
73
|
-
|
74
|
-
allow(TwitterCldr).to receive(:supported_locale?).with(:aasdsd).and_return(false)
|
75
|
-
|
76
|
-
expect(described_class.locales_pluralizations).to eq([:one, :other, :many, :few, :zero])
|
67
|
+
allow(I18n).to receive(:locale_available?).and_return(true)
|
68
|
+
expect(described_class.locales_pluralizations).to eq([:one, :other, :few, :many, :zero])
|
77
69
|
end
|
78
70
|
end
|
79
71
|
|
@@ -229,33 +229,15 @@ describe Releaf::I18nDatabase::TranslationsStore do
|
|
229
229
|
end
|
230
230
|
|
231
231
|
describe "#valid_pluralized_result?" do
|
232
|
-
before do
|
233
|
-
allow(TwitterCldr::Formatters::Plurals::Rules).to receive(:rule_for)
|
234
|
-
.with(2, :lv).and_return(:few)
|
235
|
-
end
|
236
|
-
|
237
|
-
context "when unsupported locale given" do
|
238
|
-
it "return false" do
|
239
|
-
allow(TwitterCldr).to receive(:supported_locale?).with(:lv).and_return(false)
|
240
|
-
expect(subject.valid_pluralized_result?(:lv, 2, few: "x", many: "y")).to be false
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
232
|
context "when given hash contains valid result for given locale and count" do
|
245
|
-
|
246
|
-
|
247
|
-
end
|
248
|
-
|
249
|
-
context "when given hash contains valid result for given locale and count" do
|
250
|
-
it "return true" do
|
251
|
-
expect(subject.valid_pluralized_result?(:lv, 2, few: "x", many: "y")).to be true
|
252
|
-
end
|
233
|
+
it "return true" do
|
234
|
+
expect(subject.valid_pluralized_result?(:lv, 2, one: "x", other: "y")).to be true
|
253
235
|
end
|
236
|
+
end
|
254
237
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
end
|
238
|
+
context "when given hash contains invalid result for given locale and count" do
|
239
|
+
it "return false" do
|
240
|
+
expect(subject.valid_pluralized_result?(:lv, 2, one: "x", few: "y")).to be false
|
259
241
|
end
|
260
242
|
end
|
261
243
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: releaf-i18n_database
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CubeSystems
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: releaf-core
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.1.
|
19
|
+
version: 1.1.1
|
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: 1.1.
|
26
|
+
version: 1.1.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rails-i18n
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 4.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: 4.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: axlsx_rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|