releaf-i18n_database 1.1.19 → 2.0.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/assets/config/releaf_i18n_database_manifest.js +2 -0
- data/app/controllers/releaf/i18n_database/translations_controller.rb +1 -1
- data/app/lib/releaf/i18n_database/parse_spreadsheet_translations.rb +2 -2
- data/app/lib/releaf/i18n_database/translations_store.rb +1 -1
- data/app/lib/releaf/i18n_database/translations_utilities.rb +1 -1
- data/app/models/releaf/i18n_database/i18n_entry.rb +1 -1
- data/app/views/releaf/i18n_database/translations/_form_fields.haml +1 -1
- data/lib/releaf-i18n_database.rb +1 -1
- data/lib/releaf/i18n_database/engine.rb +2 -2
- metadata +17 -63
- data/spec/builders/translations/builder_common_spec.rb +0 -39
- data/spec/builders/translations/edit_builder_spec.rb +0 -93
- data/spec/builders/translations/index_builder_spec.rb +0 -96
- data/spec/builders/translations/table_builder_spec.rb +0 -68
- data/spec/controllers/i18n_backend/translations_controller_spec.rb +0 -148
- data/spec/features/translations_spec.rb +0 -426
- data/spec/fixtures/all_translations_exported.xlsx +0 -0
- data/spec/fixtures/invalid.xls +0 -3
- data/spec/fixtures/invalid.xlsx +0 -3
- data/spec/fixtures/time.formats.xlsx +0 -0
- data/spec/fixtures/translations_import.xlsx +0 -0
- data/spec/fixtures/unsupported_import_file.png +0 -0
- data/spec/lib/releaf/i18n_database/backend_spec.rb +0 -198
- data/spec/lib/releaf/i18n_database/configuration_spec.rb +0 -13
- data/spec/lib/releaf/i18n_database/humanize_missing_translations_spec.rb +0 -24
- data/spec/lib/releaf/i18n_database/parse_spreadsheet_translations_spec.rb +0 -151
- data/spec/lib/releaf/i18n_database/translations_store_spec.rb +0 -530
- data/spec/lib/releaf/i18n_database/translations_utilities_spec.rb +0 -175
- data/spec/models/i18n_database/i18n_entry_spec.rb +0 -50
- data/spec/models/i18n_database/i18n_entry_translation_spec.rb +0 -9
@@ -1,68 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::I18nDatabase::Translations::TableBuilder, type: :class do
|
4
|
-
class TableBuilderTestHelper < ActionView::Base; end
|
5
|
-
let(:template){ TableBuilderTestHelper.new }
|
6
|
-
let(:resource_class){ Releaf::I18nDatabase::I18nEntry }
|
7
|
-
let(:subject){ described_class.new([], resource_class, template, {}) }
|
8
|
-
|
9
|
-
before do
|
10
|
-
allow(Releaf.application.config).to receive(:all_locales).and_return(["de", "ze"])
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#column_names" do
|
14
|
-
it "returns key and Releaf.application.config column names array" do
|
15
|
-
expect(subject.column_names).to eq([:key, "de", "ze"])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#head_cell_content" do
|
20
|
-
context "when locale column given" do
|
21
|
-
it "returns head cell content with translated locale" do
|
22
|
-
allow(subject).to receive(:translate_locale).with("de").and_return("gegxxxeg")
|
23
|
-
expect(subject.head_cell_content("de")).to eq('gegxxxeg')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when non locale column given" do
|
28
|
-
it "returns head cell content with translated locale" do
|
29
|
-
expect(subject).to_not receive(:translate_locale)
|
30
|
-
expect(subject.head_cell_content("lv")).to eq('Lv')
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#cell_content" do
|
36
|
-
it "wraps content within span element" do
|
37
|
-
resource = resource_class.new(key: "xx")
|
38
|
-
expect(subject.cell_content(resource, :key, format_method: :format_string_content)).to eq("<span>xx</span>")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#locale_value" do
|
43
|
-
it "returns localized value for given resource and column(locale)" do
|
44
|
-
resource = resource_class.new
|
45
|
-
allow(resource).to receive(:locale_value).with(:en).and_return("en value")
|
46
|
-
expect(subject.locale_value(resource, :en)).to eq("en value")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "#cell_format_method" do
|
51
|
-
before do
|
52
|
-
allow(Releaf.application.config).to receive(:all_locales).and_return([:de, :ze])
|
53
|
-
end
|
54
|
-
|
55
|
-
context "when given column name exists within Releaf.application.config.all_locales" do
|
56
|
-
it "returns :locale_value" do
|
57
|
-
expect(subject.cell_format_method(:de)).to eq(:locale_value)
|
58
|
-
expect(subject.cell_format_method(:ze)).to eq(:locale_value)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "when given column name does not exists within Releaf.application.config.all_locales" do
|
63
|
-
it "return super" do
|
64
|
-
expect(subject.cell_format_method(:en)).to eq(:format_string_content)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,148 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe Releaf::I18nDatabase::TranslationsController do
|
4
|
-
def file_attachment
|
5
|
-
test_document = File.expand_path('../../fixtures/translations_import.xlsx', __dir__)
|
6
|
-
Rack::Test::UploadedFile.new(test_document)
|
7
|
-
end
|
8
|
-
|
9
|
-
login_as_user :user
|
10
|
-
|
11
|
-
before do
|
12
|
-
@time_now = Time.parse("1981-02-23 21:00:00 UTC")
|
13
|
-
allow(Time).to receive(:now).and_return(@time_now)
|
14
|
-
end
|
15
|
-
|
16
|
-
before build_translations: true do
|
17
|
-
@t1 = Releaf::I18nDatabase::I18nEntry.create(key: 'test.key1')
|
18
|
-
@t2 = Releaf::I18nDatabase::I18nEntry.create(key: 'great.stuff')
|
19
|
-
@t3 = Releaf::I18nDatabase::I18nEntry.create(key: 'geek.stuff')
|
20
|
-
@t1.i18n_entry_translation.create(locale: 'en', text: 'testa atslēga')
|
21
|
-
@t2.i18n_entry_translation.create(locale: 'en', text: 'awesome stuff')
|
22
|
-
@t2.i18n_entry_translation.create(locale: 'lv', text: 'lieliska manta')
|
23
|
-
@t3.i18n_entry_translation.create(locale: 'en', text: 'geek stuff')
|
24
|
-
@t3.i18n_entry_translation.create(locale: 'lv', text: 'nūģu lieta')
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "GET #index", build_translations: true do
|
28
|
-
context "when not searching" do
|
29
|
-
it "renders all translations" do
|
30
|
-
get :index
|
31
|
-
expect( assigns(:collection).size ).to eq(3)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when searching" do
|
36
|
-
it "searches by translation key" do
|
37
|
-
get :index, search: 'great'
|
38
|
-
expect( assigns(:collection).size ).to eq(1)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "searched by localized values" do
|
42
|
-
get :index, search: 'manta'
|
43
|
-
expect( assigns(:collection).size ).to eq(1)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when searching blank translations" do
|
48
|
-
it "returns translations that has blank translation in any localization" do
|
49
|
-
get :index, only_blank: 'true'
|
50
|
-
expect( assigns(:collection).map(&:id) ).to match_array [@t1.id]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "GET #edit", build_translations: true do
|
56
|
-
context "when search scope is not given" do
|
57
|
-
it "renders all translations" do
|
58
|
-
get :edit
|
59
|
-
expect( assigns(:collection).size ).to eq(3)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when search scope is given" do
|
64
|
-
it "renders translations matching search pattern" do
|
65
|
-
get :index, search: 'stuff'
|
66
|
-
expect( assigns(:collection).size ).to eq(2)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "#update" do
|
72
|
-
context "when save successful" do
|
73
|
-
it "updates translations updated_at" do
|
74
|
-
expect(Releaf::I18nDatabase::Backend).to receive("translations_updated_at=").with(@time_now)
|
75
|
-
put :update, translations: [{key: 'a.b.c', localizations: {en: 'test', lv: 'xxl'}}]
|
76
|
-
end
|
77
|
-
|
78
|
-
context "when save with import" do
|
79
|
-
before do
|
80
|
-
put :update, translations: [{key: 'a.b.c', localizations: {en: 'test', lv: 'xxl'}}], import: "true"
|
81
|
-
end
|
82
|
-
|
83
|
-
it "redirects to index view" do
|
84
|
-
expect(subject).to redirect_to(action: :index)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "flash success notification with updated count" do
|
88
|
-
expect(flash["success"]).to eq("id" => "resource_status", "message" => "successfuly imported 1 translations")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context "when save without import" do
|
93
|
-
before do
|
94
|
-
put :update, translations: [{key: 'a.b.c', localizations: {en: 'test', lv: 'xxl'}}]
|
95
|
-
end
|
96
|
-
|
97
|
-
it "redirects to edit view" do
|
98
|
-
expect(subject).to redirect_to(action: :edit)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "flash success notification" do
|
102
|
-
expect(flash["success"]).to eq("id" => "resource_status", "message" => "Update succeeded")
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context "when save failed" do
|
108
|
-
it "renders edit view" do
|
109
|
-
put :update, translations: [{key: '', localizations: {en: 'test', lv: 'xxl'}}]
|
110
|
-
expect(response).to render_template(:edit)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "flash error notification" do
|
114
|
-
put :update, translations: [{key: '', localizations: {en: 'test', lv: 'xxl'}}]
|
115
|
-
expect(flash["error"]).to eq("id" => "resource_status", "message" => "Update failed")
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "#import" do
|
121
|
-
context "when file uploaded" do
|
122
|
-
before do
|
123
|
-
file = fixture_file_upload(File.expand_path('../../fixtures/translations_import.xlsx', __dir__),
|
124
|
-
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
125
|
-
post :import, import_file: file
|
126
|
-
end
|
127
|
-
|
128
|
-
it "parses uploaded file and assigns content to collection" do
|
129
|
-
expect( assigns(:collection).size ).to eq(4)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "assigns @import to true" do
|
133
|
-
expect( assigns(:import) ).to be true
|
134
|
-
end
|
135
|
-
|
136
|
-
it "appends breadcrumb with 'import' part" do
|
137
|
-
expect( assigns(:breadcrumbs).last ).to eq({name: "Import"})
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "when no file uploaded" do
|
142
|
-
it "redirects to index" do
|
143
|
-
post :import
|
144
|
-
expect(subject).to redirect_to(action: :index)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
@@ -1,426 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
feature "Translations" do
|
3
|
-
background(create_translations: true) do
|
4
|
-
auth_as_user
|
5
|
-
|
6
|
-
translation_1 = Releaf::I18nDatabase::I18nEntry.create(key: 'test.key1')
|
7
|
-
translation_2 = Releaf::I18nDatabase::I18nEntry.create(key: 'great.stuff')
|
8
|
-
translation_3 = Releaf::I18nDatabase::I18nEntry.create(key: 'geek.stuff')
|
9
|
-
translation_1.i18n_entry_translation.create(locale: 'en', text: 'testa atslēga')
|
10
|
-
translation_2.i18n_entry_translation.create(locale: 'en', text: 'awesome stuff')
|
11
|
-
translation_2.i18n_entry_translation.create(locale: 'lv', text: 'lieliska manta')
|
12
|
-
translation_3.i18n_entry_translation.create(locale: 'en', text: 'geek stuff')
|
13
|
-
translation_3.i18n_entry_translation.create(locale: 'lv', text: 'nūģu lieta')
|
14
|
-
end
|
15
|
-
|
16
|
-
scenario "blank only filtering", js: true, create_translations: true do
|
17
|
-
visit releaf_i18n_database_translations_path
|
18
|
-
expect(page).to have_number_of_resources(3)
|
19
|
-
|
20
|
-
check "Only blank"
|
21
|
-
expect(page).to have_number_of_resources(1)
|
22
|
-
|
23
|
-
click_link "Edit"
|
24
|
-
expect(page).to have_css(".table tbody.list tr", count: 1)
|
25
|
-
|
26
|
-
within ".table tr.item:first-child" do
|
27
|
-
fill_in "translations[][localizations][lv]", with: "lv tulkojums"
|
28
|
-
fill_in "translations[][localizations][en]", with: "en translation"
|
29
|
-
end
|
30
|
-
click_button "Save"
|
31
|
-
expect(page).to have_notification("Update succeeded")
|
32
|
-
|
33
|
-
# TODO: fix when phantomjs will have file download implemented
|
34
|
-
#click_link "Export"
|
35
|
-
#filename = page.response_headers["Content-Disposition"].split("=")[1].gsub("\"","")
|
36
|
-
#tmp_file = Dir.tmpdir + '/' + filename
|
37
|
-
#File.open(tmp_file, "wb") { |f| f.write(page.body) }
|
38
|
-
#fixture_path = File.expand_path('../fixtures/blank_translations_exported.xlsx', __dir__)
|
39
|
-
#expect(tmp_file).to match_excel(fixture_path)
|
40
|
-
#File.delete(tmp_file)
|
41
|
-
|
42
|
-
click_link "Back to list"
|
43
|
-
expect(page).to have_number_of_resources(0)
|
44
|
-
|
45
|
-
uncheck "Only blank"
|
46
|
-
expect(page).to have_number_of_resources(3)
|
47
|
-
end
|
48
|
-
|
49
|
-
scenario "index", create_translations: true do
|
50
|
-
visit releaf_i18n_database_translations_path
|
51
|
-
expect( page ).to have_content 'test.key1'
|
52
|
-
expect( page ).to have_content 'great.stuff'
|
53
|
-
expect( page ).to have_content 'geek.stuff'
|
54
|
-
|
55
|
-
expect( page ).to have_content 'testa atslēga'
|
56
|
-
expect( page ).to have_content 'awesome stuff'
|
57
|
-
expect( page ).to have_content 'lieliska manta'
|
58
|
-
expect( page ).to have_content 'geek stuff'
|
59
|
-
expect( page ).to have_content 'nūģu lieta'
|
60
|
-
end
|
61
|
-
|
62
|
-
scenario "Editing", js: true, create_translations: true do
|
63
|
-
visit releaf_i18n_database_translations_path
|
64
|
-
|
65
|
-
fill_in 'search', with: "stuff"
|
66
|
-
expect(page).to have_number_of_resources(2)
|
67
|
-
click_link "Edit"
|
68
|
-
|
69
|
-
within ".table tr.item:first-child" do
|
70
|
-
expect(find_field("translations[][key]").value).to eq("geek.stuff")
|
71
|
-
fill_in "translations[][key]", with: ""
|
72
|
-
fill_in "translations[][localizations][lv]", with: "lv tulkojums"
|
73
|
-
fill_in "translations[][localizations][en]", with: "en translation"
|
74
|
-
end
|
75
|
-
|
76
|
-
click_button "Save"
|
77
|
-
expect(page).to have_notification("Update failed", :error)
|
78
|
-
|
79
|
-
within ".table tr.item:last-child" do
|
80
|
-
click_button "Remove"
|
81
|
-
end
|
82
|
-
expect(page).to have_css(".table tr.item", count: 1) # wait for fade out to complete
|
83
|
-
|
84
|
-
within ".table tr.item:first-child" do
|
85
|
-
fill_in "translations[][key]", with: "great.stuff"
|
86
|
-
end
|
87
|
-
|
88
|
-
click_button "Save"
|
89
|
-
expect(page).to have_notification("Update succeeded")
|
90
|
-
|
91
|
-
# rename key
|
92
|
-
within ".table tr.item:first-child" do
|
93
|
-
fill_in "translations[][key]", with: "another.great.stuff"
|
94
|
-
end
|
95
|
-
click_button "Save"
|
96
|
-
expect(page).to have_notification("Update succeeded")
|
97
|
-
|
98
|
-
click_link "Back to list"
|
99
|
-
expect(page).to have_number_of_resources(1)
|
100
|
-
expect(page).to have_content 'lv tulkojums'
|
101
|
-
expect(page).to have_content 'en translation'
|
102
|
-
end
|
103
|
-
|
104
|
-
scenario "Do not save empty translations", create_translations: true do
|
105
|
-
visit releaf_i18n_database_translations_path
|
106
|
-
click_link "Edit"
|
107
|
-
click_button "Save"
|
108
|
-
|
109
|
-
expect(Releaf::I18nDatabase::I18nEntryTranslation.where(text: "").count).to eq(0)
|
110
|
-
end
|
111
|
-
|
112
|
-
scenario "Import excel file with translations", js: true, create_translations: true do
|
113
|
-
visit releaf_i18n_database_translations_path
|
114
|
-
expect(page).to have_no_css(".table td span", text: "Eksports")
|
115
|
-
expect(page).to have_no_css(".table td span", text: "Export")
|
116
|
-
expect(page).to have_no_css(".table td span", text: "jauns")
|
117
|
-
|
118
|
-
script = "$('form.import').css({display: 'block'});"
|
119
|
-
page.execute_script(script)
|
120
|
-
|
121
|
-
fixture_path = File.expand_path('../fixtures/translations_import.xlsx', __dir__)
|
122
|
-
|
123
|
-
within('form.import') do
|
124
|
-
attach_file(:import_file, fixture_path)
|
125
|
-
end
|
126
|
-
|
127
|
-
expect(page).to have_css(".breadcrumbs li:last-child", text: "Import")
|
128
|
-
find(:css, 'input[name="translations[][localizations][lv]"][value="Eksports"]')
|
129
|
-
find(:css, 'input[name="translations[][localizations][en]"][value="Export"]')
|
130
|
-
|
131
|
-
click_button "Import"
|
132
|
-
expect(page).to have_notification("successfuly imported 4 translations")
|
133
|
-
|
134
|
-
visit releaf_i18n_database_translations_path
|
135
|
-
expect(page).to have_css(".table td span", text: "Eksports")
|
136
|
-
expect(page).to have_css(".table td span", text: "Export")
|
137
|
-
expect(page).to have_css(".table td span", text: "jauns")
|
138
|
-
end
|
139
|
-
|
140
|
-
scenario "Import unsupported file", js: true, create_translations: true do
|
141
|
-
visit releaf_i18n_database_translations_path
|
142
|
-
|
143
|
-
script = "$('form.import').css({display: 'block'});"
|
144
|
-
page.execute_script(script)
|
145
|
-
|
146
|
-
fixture_path = File.expand_path('../fixtures/unsupported_import_file.png', __dir__)
|
147
|
-
|
148
|
-
within('form.import') do
|
149
|
-
attach_file(:import_file, fixture_path)
|
150
|
-
end
|
151
|
-
|
152
|
-
expect(page).to have_notification("Unsupported file format", "error")
|
153
|
-
end
|
154
|
-
|
155
|
-
scenario "Import corrupt xls file", js: true, create_translations: true do
|
156
|
-
visit releaf_i18n_database_translations_path
|
157
|
-
|
158
|
-
script = "$('form.import').css({display: 'block'});"
|
159
|
-
page.execute_script(script)
|
160
|
-
|
161
|
-
fixture_path = File.expand_path('../fixtures/invalid.xls', __dir__)
|
162
|
-
|
163
|
-
within('form.import') do
|
164
|
-
attach_file(:import_file, fixture_path)
|
165
|
-
end
|
166
|
-
|
167
|
-
expect(page).to have_notification("Unsupported file format", "error")
|
168
|
-
end
|
169
|
-
|
170
|
-
|
171
|
-
scenario "Import corrupt xlsx file", js: true, create_translations: true do
|
172
|
-
visit releaf_i18n_database_translations_path
|
173
|
-
|
174
|
-
script = "$('form.import').css({display: 'block'});"
|
175
|
-
page.execute_script(script)
|
176
|
-
|
177
|
-
fixture_path = File.expand_path('../fixtures/invalid.xlsx', __dir__)
|
178
|
-
|
179
|
-
within('form.import') do
|
180
|
-
attach_file(:import_file, fixture_path)
|
181
|
-
end
|
182
|
-
|
183
|
-
expect(page).to have_notification("Unsupported file format", "error")
|
184
|
-
end
|
185
|
-
|
186
|
-
|
187
|
-
scenario "Export translations", create_translations: true do
|
188
|
-
visit releaf_i18n_database_translations_path
|
189
|
-
click_link "Export"
|
190
|
-
|
191
|
-
expect(page.response_headers["Content-Type"]).to eq('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8')
|
192
|
-
|
193
|
-
filename = page.response_headers["Content-Disposition"].split("=")[1].gsub("\"","")
|
194
|
-
tmp_file = Dir.tmpdir + '/' + filename
|
195
|
-
File.open(tmp_file, "wb") { |f| f.write(page.body) }
|
196
|
-
|
197
|
-
fixture_path = File.expand_path('../fixtures/all_translations_exported.xlsx', __dir__)
|
198
|
-
expect(tmp_file).to match_excel(fixture_path)
|
199
|
-
|
200
|
-
File.delete(tmp_file)
|
201
|
-
end
|
202
|
-
|
203
|
-
describe "Lookup" do
|
204
|
-
background do
|
205
|
-
Releaf::I18nDatabase::Backend.reset_cache
|
206
|
-
allow( Releaf.application.config.i18n_database ).to receive(:translation_auto_creation).and_return(true)
|
207
|
-
end
|
208
|
-
|
209
|
-
context "when translation exists within higher level key (instead of being scope)" do
|
210
|
-
it "returns nil (Humanize key)" do
|
211
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "some.food")
|
212
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "suņi")
|
213
|
-
|
214
|
-
expect(I18n.t("some.food", locale: "lv")).to eq("suņi")
|
215
|
-
expect(I18n.t("some.food.asd", locale: "lv")).to eq("Asd")
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
context "when pluralized translation requested" do
|
220
|
-
context "when valid pluralized data matched" do
|
221
|
-
it "returns pluralized translation" do
|
222
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "dog.other")
|
223
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "suņi")
|
224
|
-
|
225
|
-
expect(I18n.t("dog", locale: "lv", count: 2)).to eq("suņi")
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
context "when invalid pluralized data matched" do
|
230
|
-
it "returns nil (Humanize key)" do
|
231
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "dog.food")
|
232
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "suņi")
|
233
|
-
|
234
|
-
expect(I18n.t("dog", locale: "lv", count: 2)).to eq("Dog")
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
context "when same translations with different cases exists" do
|
240
|
-
it "returns case sensitive translation" do
|
241
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "Save")
|
242
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "Saglabāt")
|
243
|
-
|
244
|
-
expect(I18n.t("save", locale: "lv")).to eq("Save")
|
245
|
-
expect(I18n.t("Save", locale: "lv")).to eq("Saglabāt")
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
context "existing translation" do
|
250
|
-
context "when translations hash exists in parent scope" do
|
251
|
-
before do
|
252
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "dog.other")
|
253
|
-
translation.i18n_entry_translation.create(locale: "en", text: "dogs")
|
254
|
-
end
|
255
|
-
|
256
|
-
context "when pluralized translation requested" do
|
257
|
-
it "returns pluralized translation" do
|
258
|
-
expect(I18n.t("admin.controller.dog", count: 2)).to eq("dogs")
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
context "when non pluralized translation requested" do
|
263
|
-
it "returns nil" do
|
264
|
-
expect(I18n.t("admin.controller.dog")).to eq("Dog")
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
context "when ignorable pattern" do
|
270
|
-
it "does not auto create missing translation" do
|
271
|
-
expect{ I18n.t("attributes.title") }.to_not change{ Releaf::I18nDatabase::I18nEntry.count }
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
context "in parent scope" do
|
276
|
-
context "nonexistent translation in given scope" do
|
277
|
-
it "uses parent scope" do
|
278
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.blank")
|
279
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "Tukšs")
|
280
|
-
expect(I18n.t("blank", scope: "validation.admin.roles", locale: "lv")).to eq("Tukšs")
|
281
|
-
end
|
282
|
-
|
283
|
-
context "when `inherit_scopes` option is `false`" do
|
284
|
-
it "does not lookup upon higher level scopes" do
|
285
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.blank")
|
286
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "Tukšs")
|
287
|
-
expect(I18n.t("blank", scope: "validation.admin.roles", locale: "lv", inherit_scopes: false)).to eq("Blank")
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
context "and empty translation value in given scope" do
|
293
|
-
it "uses parent scope" do
|
294
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.roles.blank")
|
295
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "")
|
296
|
-
|
297
|
-
parent_translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.blank")
|
298
|
-
parent_translation.i18n_entry_translation.create(locale: "lv", text: "Tukšs")
|
299
|
-
|
300
|
-
expect(I18n.t("blank", scope: "validation.admin.roles", locale: "lv")).to eq("Tukšs")
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
context "and existing translation value in given scope" do
|
305
|
-
it "uses given scope" do
|
306
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.roles.blank")
|
307
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "Tukša vērtība")
|
308
|
-
|
309
|
-
parent_translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.blank")
|
310
|
-
parent_translation.i18n_entry_translation.create(locale: "lv", text: "Tukšs")
|
311
|
-
|
312
|
-
expect(I18n.t("blank", scope: "validation.admin.roles", locale: "lv")).to eq("Tukša vērtība")
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
context "when scope defined" do
|
318
|
-
it "uses given scope" do
|
319
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "admin.content.cancel")
|
320
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "Atlikt")
|
321
|
-
expect(I18n.t("cancel", scope: "admin.content", locale: "lv")).to eq("Atlikt")
|
322
|
-
end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
context "nonexistent translation" do
|
327
|
-
context "loading multiple times" do
|
328
|
-
it "queries db only for the first time" do
|
329
|
-
I18n.t("save", scope: "admin.xx")
|
330
|
-
expect(Releaf::I18nDatabase::I18nEntry).not_to receive(:where)
|
331
|
-
I18n.t("save", scope: "admin.xx")
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
context "with nonexistent translation" do
|
336
|
-
before do
|
337
|
-
allow(Releaf.application.config).to receive(:all_locales).and_return(["ru", "lv"])
|
338
|
-
allow(I18n).to receive(:locale_available?).and_return(true)
|
339
|
-
end
|
340
|
-
|
341
|
-
it "creates empty translation" do
|
342
|
-
expect { I18n.t("save") }.to change { Releaf::I18nDatabase::I18nEntry.where(key: "save").count }.by(1)
|
343
|
-
end
|
344
|
-
|
345
|
-
context "when count option passed" do
|
346
|
-
context "when create_plurals option not passed" do
|
347
|
-
it "creates empty translation" do
|
348
|
-
expect { I18n.t("animals.horse", count: 1) }.to change { Releaf::I18nDatabase::I18nEntry.where(key: "animals.horse").count }.by(1)
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
context "when negative create_plurals option passed" do
|
353
|
-
it "creates empty translation" do
|
354
|
-
expect { I18n.t("animals.horse", create_plurals: false, count: 1) }.to change { Releaf::I18nDatabase::I18nEntry.where(key: "animals.horse").count }.by(1)
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
context "when positive create_plurals option passed" do
|
359
|
-
it "creates pluralized translations for all Releaf locales" do
|
360
|
-
result = ["animals.horse.few", "animals.horse.many", "animals.horse.one", "animals.horse.other", "animals.horse.zero"]
|
361
|
-
expect{ I18n.t("animals.horse", count: 1, create_plurals: true) }.to change{ Releaf::I18nDatabase::I18nEntry.pluck(:key).sort }.
|
362
|
-
from([]).to(result.sort)
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
context "when scope requested" do
|
370
|
-
it "returns all scope translations" do
|
371
|
-
translation_1 = Releaf::I18nDatabase::I18nEntry.create(key: "admin.content.cancel")
|
372
|
-
translation_1.i18n_entry_translation.create(locale: "lv", text: "Atlikt")
|
373
|
-
|
374
|
-
translation_2 = Releaf::I18nDatabase::I18nEntry.create(key: "admin.content.save")
|
375
|
-
translation_2.i18n_entry_translation.create(locale: "lv", text: "Saglabāt")
|
376
|
-
|
377
|
-
expect(I18n.t("admin.content", locale: "lv")).to eq(cancel: "Atlikt", save: "Saglabāt")
|
378
|
-
expect(I18n.t("admin.content", locale: "en")).to eq(cancel: nil, save: nil)
|
379
|
-
end
|
380
|
-
end
|
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
|
-
|
426
|
-
end
|