releaf-i18n_database 0.2.1 → 1.0.3
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/LICENSE +19 -21
- data/app/assets/javascripts/{releaf/controllers → controllers}/releaf/i18n_database/translations.js +0 -0
- data/app/assets/stylesheets/{releaf/controllers → controllers}/releaf/i18n_database/translations.scss +0 -0
- data/app/builders/releaf/i18n_database/translations/builders_common.rb +1 -1
- data/app/builders/releaf/i18n_database/translations/index_builder.rb +1 -1
- data/app/controllers/releaf/i18n_database/translations_controller.rb +121 -127
- data/app/lib/releaf/i18n_database/parse_spreadsheet_translations.rb +62 -0
- data/app/lib/releaf/i18n_database/translations_store.rb +149 -0
- data/app/lib/releaf/i18n_database/translations_utilities.rb +6 -6
- data/app/models/releaf/i18n_database/i18n_entry.rb +21 -0
- data/app/models/releaf/i18n_database/i18n_entry_translation.rb +11 -0
- data/app/views/releaf/i18n_database/translations/_form_fields.haml +2 -2
- data/lib/releaf-i18n_database.rb +14 -3
- data/lib/releaf/i18n_database/backend.rb +56 -131
- data/lib/releaf/i18n_database/configuration.rb +8 -0
- data/lib/releaf/i18n_database/engine.rb +1 -30
- data/lib/releaf/i18n_database/humanize_missing_translations.rb +1 -1
- data/misc/translations.xlsx +0 -0
- data/spec/builders/translations/builder_common_spec.rb +1 -1
- data/spec/builders/translations/edit_builder_spec.rb +2 -2
- data/spec/builders/translations/table_builder_spec.rb +1 -1
- data/spec/controllers/i18n_backend/translations_controller_spec.rb +10 -19
- data/spec/features/translations_spec.rb +235 -16
- data/spec/fixtures/invalid.xls +3 -0
- data/spec/fixtures/invalid.xlsx +3 -0
- data/spec/lib/releaf/i18n_database/backend_spec.rb +192 -0
- data/spec/lib/releaf/i18n_database/configuration_spec.rb +13 -0
- data/spec/lib/{i18n_database → releaf/i18n_database}/humanize_missing_translations_spec.rb +7 -1
- data/spec/lib/releaf/i18n_database/parse_spreadsheet_translations_spec.rb +151 -0
- data/spec/lib/releaf/i18n_database/translations_store_spec.rb +548 -0
- data/spec/lib/{i18n_database → releaf/i18n_database}/translations_utilities_spec.rb +39 -39
- data/spec/models/i18n_database/i18n_entry_spec.rb +50 -0
- data/spec/models/i18n_database/i18n_entry_translation_spec.rb +9 -0
- metadata +45 -30
- data/app/lib/releaf/i18n_database/translations_importer.rb +0 -72
- data/app/models/releaf/i18n_database/translation.rb +0 -17
- data/app/models/releaf/i18n_database/translation_data.rb +0 -11
- data/lib/releaf/i18n_database/builders_autoload.rb +0 -10
- data/releaf-i18n_database.gemspec +0 -21
- data/spec/lib/i18n_database/backend_spec.rb +0 -337
- data/spec/lib/i18n_database/translations_importer_spec.rb +0 -17
- data/spec/models/i18n_database/translation_data_spec.rb +0 -13
- data/spec/models/i18n_database/translation_spec.rb +0 -49
@@ -39,17 +39,17 @@ describe Releaf::I18nDatabase::TranslationsUtilities do
|
|
39
39
|
|
40
40
|
describe ".filter_only_blank_translations" do
|
41
41
|
it "returns given collection applied with empty translation data search" do
|
42
|
-
collection = Releaf::I18nDatabase::
|
42
|
+
collection = Releaf::I18nDatabase::I18nEntry.where("id > 1")
|
43
43
|
allow(described_class).to receive(:search_columns).and_return([
|
44
|
-
Releaf::I18nDatabase::
|
45
|
-
Releaf::I18nDatabase::
|
44
|
+
Releaf::I18nDatabase::I18nEntry.arel_table[:key],
|
45
|
+
Releaf::I18nDatabase::I18nEntry.arel_table.alias("lv_data")[:text],
|
46
46
|
])
|
47
47
|
if postgresql?
|
48
|
-
result = "WHERE (id > 1) AND ((\"
|
49
|
-
result += " OR (\"lv_data\".\"
|
48
|
+
result = "WHERE (id > 1) AND ((\"releaf_i18n_entries\".\"key\" = '' OR \"releaf_i18n_entries\".\"key\" IS NULL)"
|
49
|
+
result += " OR (\"lv_data\".\"text\" = '' OR \"lv_data\".\"text\" IS NULL))"
|
50
50
|
else
|
51
|
-
result = "WHERE (id > 1) AND ((`
|
52
|
-
result += " OR (`lv_data`.`
|
51
|
+
result = "WHERE (id > 1) AND ((`releaf_i18n_entries`.`key` = '' OR `releaf_i18n_entries`.`key` IS NULL)"
|
52
|
+
result += " OR (`lv_data`.`text` = '' OR `lv_data`.`text` IS NULL))"
|
53
53
|
end
|
54
54
|
expect(described_class.filter_only_blank_translations(collection).to_sql).to end_with(result)
|
55
55
|
end
|
@@ -57,7 +57,7 @@ describe Releaf::I18nDatabase::TranslationsUtilities do
|
|
57
57
|
|
58
58
|
describe ".filter_by_text" do
|
59
59
|
it "returns collection with grouped column searches" do
|
60
|
-
collection = Releaf::I18nDatabase::
|
60
|
+
collection = Releaf::I18nDatabase::I18nEntry.where("id > 1")
|
61
61
|
allow(described_class).to receive(:column_searches).with("redx").and_return([
|
62
62
|
"id = 8 AND id = 2",
|
63
63
|
"id = 9 AND id = 19",
|
@@ -70,17 +70,17 @@ describe Releaf::I18nDatabase::TranslationsUtilities do
|
|
70
70
|
describe ".column_searches" do
|
71
71
|
it "return array with column based searches" do
|
72
72
|
allow(described_class).to receive(:search_columns).and_return([
|
73
|
-
Releaf::I18nDatabase::
|
74
|
-
Releaf::I18nDatabase::
|
73
|
+
Releaf::I18nDatabase::I18nEntry.arel_table[:key],
|
74
|
+
Releaf::I18nDatabase::I18nEntry.arel_table.alias("lv_data")[:text],
|
75
75
|
])
|
76
76
|
allow(described_class).to receive(:escape_search_string).with("red").twice.and_return("escaped_red")
|
77
77
|
allow(described_class).to receive(:escape_search_string).with("car").twice.and_return("escaped_car")
|
78
78
|
if postgresql?
|
79
|
-
result = ["\"
|
80
|
-
"\"lv_data\".\"
|
79
|
+
result = ["\"releaf_i18n_entries\".\"key\" ILIKE '%escaped_red%' AND \"releaf_i18n_entries\".\"key\" ILIKE '%escaped_car%'",
|
80
|
+
"\"lv_data\".\"text\" ILIKE '%escaped_red%' AND \"lv_data\".\"text\" ILIKE '%escaped_car%'"]
|
81
81
|
else
|
82
|
-
result = ["`
|
83
|
-
"`lv_data`.`
|
82
|
+
result = ["`releaf_i18n_entries`.`key` LIKE '%escaped_red%' AND `releaf_i18n_entries`.`key` LIKE '%escaped_car%'",
|
83
|
+
"`lv_data`.`text` LIKE '%escaped_red%' AND `lv_data`.`text` LIKE '%escaped_car%'"]
|
84
84
|
end
|
85
85
|
expect(described_class.column_searches(" red car ")).to eq(result)
|
86
86
|
end
|
@@ -89,16 +89,16 @@ describe Releaf::I18nDatabase::TranslationsUtilities do
|
|
89
89
|
describe ".search_columns" do
|
90
90
|
it "returns array with translation key arel attribute and locale tables localization attributes" do
|
91
91
|
allow(described_class).to receive(:locale_tables).and_return(
|
92
|
-
de: Releaf::I18nDatabase::
|
93
|
-
lv: Releaf::I18nDatabase::
|
94
|
-
en: Releaf::I18nDatabase::
|
92
|
+
de: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("de_data"),
|
93
|
+
lv: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("lv_data"),
|
94
|
+
en: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("en_data")
|
95
95
|
)
|
96
96
|
|
97
97
|
result = [
|
98
|
-
Releaf::I18nDatabase::
|
99
|
-
Releaf::I18nDatabase::
|
100
|
-
Releaf::I18nDatabase::
|
101
|
-
Releaf::I18nDatabase::
|
98
|
+
Releaf::I18nDatabase::I18nEntry.arel_table[:key],
|
99
|
+
Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("de_data")[:text],
|
100
|
+
Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("lv_data")[:text],
|
101
|
+
Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("en_data")[:text]
|
102
102
|
]
|
103
103
|
expect(described_class.search_columns).to eq(result)
|
104
104
|
end
|
@@ -114,8 +114,8 @@ describe Releaf::I18nDatabase::TranslationsUtilities do
|
|
114
114
|
it "returns array with arel aliased locale tables" do
|
115
115
|
allow(Releaf.application.config).to receive(:all_locales).and_return([:de, :en])
|
116
116
|
result = {
|
117
|
-
de: Releaf::I18nDatabase::
|
118
|
-
en: Releaf::I18nDatabase::
|
117
|
+
de: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("de_data"),
|
118
|
+
en: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("en_data")
|
119
119
|
}
|
120
120
|
expect(described_class.locale_tables).to eq(result)
|
121
121
|
end
|
@@ -126,24 +126,24 @@ describe Releaf::I18nDatabase::TranslationsUtilities do
|
|
126
126
|
allow(described_class).to receive(:localization_include_joins).and_return(["a", "b"])
|
127
127
|
allow(described_class).to receive(:localization_include_selects).and_return("x")
|
128
128
|
if postgresql?
|
129
|
-
result = "SELECT x FROM \"
|
129
|
+
result = "SELECT x FROM \"releaf_i18n_entries\" a b"
|
130
130
|
else
|
131
|
-
result = "SELECT x FROM `
|
131
|
+
result = "SELECT x FROM `releaf_i18n_entries` a b"
|
132
132
|
end
|
133
|
-
expect(described_class.include_localizations(Releaf::I18nDatabase::
|
133
|
+
expect(described_class.include_localizations(Releaf::I18nDatabase::I18nEntry).to_sql).to eq(result)
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
137
|
describe ".localization_include_joins" do
|
138
138
|
it "returns array with locales translation table joins" do
|
139
139
|
allow(described_class).to receive(:locale_tables).and_return(
|
140
|
-
de: Releaf::I18nDatabase::
|
141
|
-
lv: Releaf::I18nDatabase::
|
142
|
-
en: Releaf::I18nDatabase::
|
140
|
+
de: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("de_data"),
|
141
|
+
lv: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("lv_data"),
|
142
|
+
en: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("en_data")
|
143
143
|
)
|
144
|
-
result = ["LEFT JOIN
|
145
|
-
"LEFT JOIN
|
146
|
-
"LEFT JOIN
|
144
|
+
result = ["LEFT JOIN releaf_i18n_entry_translations AS de_data ON de_data.i18n_entry_id = releaf_i18n_entries.id AND de_data.locale = 'de'",
|
145
|
+
"LEFT JOIN releaf_i18n_entry_translations AS lv_data ON lv_data.i18n_entry_id = releaf_i18n_entries.id AND lv_data.locale = 'lv'",
|
146
|
+
"LEFT JOIN releaf_i18n_entry_translations AS en_data ON en_data.i18n_entry_id = releaf_i18n_entries.id AND en_data.locale = 'en'"]
|
147
147
|
expect(described_class.localization_include_joins).to eq(result)
|
148
148
|
end
|
149
149
|
end
|
@@ -154,7 +154,7 @@ describe Releaf::I18nDatabase::TranslationsUtilities do
|
|
154
154
|
"de_data.localization AS de_localization",
|
155
155
|
"de_data.id AS de_localization_id"
|
156
156
|
])
|
157
|
-
result = "
|
157
|
+
result = "releaf_i18n_entries.*, de_data.localization AS de_localization, de_data.id AS de_localization_id"
|
158
158
|
expect(described_class.localization_include_selects).to eq(result)
|
159
159
|
end
|
160
160
|
end
|
@@ -162,13 +162,13 @@ describe Releaf::I18nDatabase::TranslationsUtilities do
|
|
162
162
|
describe ".localization_include_locales_columns" do
|
163
163
|
it "returns locales translated values columns and ids" do
|
164
164
|
allow(described_class).to receive(:locale_tables).and_return(
|
165
|
-
de: Releaf::I18nDatabase::
|
166
|
-
lv: Releaf::I18nDatabase::
|
167
|
-
en: Releaf::I18nDatabase::
|
165
|
+
de: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("de_data"),
|
166
|
+
lv: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("lv_data"),
|
167
|
+
en: Releaf::I18nDatabase::I18nEntryTranslation.arel_table.alias("en_data")
|
168
168
|
)
|
169
|
-
result = ["de_data.
|
170
|
-
"lv_data.
|
171
|
-
"en_data.
|
169
|
+
result = ["de_data.text AS de_localization", "de_data.id AS de_localization_id",
|
170
|
+
"lv_data.text AS lv_localization", "lv_data.id AS lv_localization_id",
|
171
|
+
"en_data.text AS en_localization", "en_data.id AS en_localization_id"]
|
172
172
|
expect(described_class.localization_include_locales_columns).to eq(result)
|
173
173
|
end
|
174
174
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
describe Releaf::I18nDatabase::I18nEntry do
|
4
|
+
it { is_expected.to validate_presence_of(:key) }
|
5
|
+
it { is_expected.to validate_length_of(:key).is_at_most(255) }
|
6
|
+
it { is_expected.to validate_uniqueness_of(:key) }
|
7
|
+
it { is_expected.to have_many(:i18n_entry_translation).dependent(:destroy) }
|
8
|
+
it { is_expected.to accept_nested_attributes_for(:i18n_entry_translation).allow_destroy(true) }
|
9
|
+
|
10
|
+
describe "#locale_value" do
|
11
|
+
it "returns translated value for given locale" do
|
12
|
+
subject.i18n_entry_translation.build(text: 'apple', locale: "en")
|
13
|
+
subject.i18n_entry_translation.build(text: 'apfel', locale: "de")
|
14
|
+
|
15
|
+
expect(subject.locale_value("en")).to eq("apple")
|
16
|
+
expect(subject.locale_value(:de)).to eq("apfel")
|
17
|
+
expect(subject.locale_value("lt")).to be nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#find_or_initialize_translation" do
|
22
|
+
before do
|
23
|
+
subject.key = "xx"
|
24
|
+
subject.i18n_entry_translation.build(text: 'apple', locale: "en")
|
25
|
+
subject.i18n_entry_translation.build(text: 'ābols', locale: "lv")
|
26
|
+
subject.save
|
27
|
+
allow(subject.i18n_entry_translation).to receive(:build).with(locale: "de").and_return(:new)
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when translation exists for given locale (given as string or symbol)" do
|
31
|
+
it "returns existing translation instance" do
|
32
|
+
expect(subject.find_or_initialize_translation(:en).text).to eq("apple")
|
33
|
+
expect(subject.find_or_initialize_translation("en").text).to eq("apple")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "uses AR cache to prevent multiple db hit for multiple locales lookup" do
|
37
|
+
expect {
|
38
|
+
subject.find_or_initialize_translation("en")
|
39
|
+
subject.find_or_initialize_translation("lv")
|
40
|
+
}.to make_database_queries(count: 1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when translation does not exists for given locale" do
|
45
|
+
it "returns newly builded translation instance" do
|
46
|
+
expect(subject.find_or_initialize_translation("de")).to eq(:new)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
describe Releaf::I18nDatabase::I18nEntryTranslation do
|
4
|
+
it { is_expected.to validate_presence_of(:i18n_entry) }
|
5
|
+
it { is_expected.to validate_presence_of(:locale) }
|
6
|
+
it { is_expected.to validate_length_of(:locale).is_at_most(5) }
|
7
|
+
it { subject.locale = "de"; is_expected.to validate_uniqueness_of(:i18n_entry_id).scoped_to([:locale]) }
|
8
|
+
it { is_expected.to belong_to(:i18n_entry) }
|
9
|
+
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: 0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CubeSystems
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: releaf-core
|
@@ -16,32 +16,35 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 1.0.3
|
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: 0.
|
26
|
+
version: 1.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: twitter_cldr
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.6'
|
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.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: axlsx_rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
45
48
|
- - ">="
|
46
49
|
- !ruby/object:Gem::Version
|
47
50
|
version: 0.3.0
|
@@ -49,6 +52,9 @@ dependencies:
|
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.3'
|
52
58
|
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: 0.3.0
|
@@ -73,25 +79,26 @@ extensions: []
|
|
73
79
|
extra_rdoc_files: []
|
74
80
|
files:
|
75
81
|
- LICENSE
|
76
|
-
- app/assets/javascripts/
|
77
|
-
- app/assets/stylesheets/
|
82
|
+
- app/assets/javascripts/controllers/releaf/i18n_database/translations.js
|
83
|
+
- app/assets/stylesheets/controllers/releaf/i18n_database/translations.scss
|
78
84
|
- app/builders/releaf/i18n_database/translations/builders_common.rb
|
79
85
|
- app/builders/releaf/i18n_database/translations/edit_builder.rb
|
80
86
|
- app/builders/releaf/i18n_database/translations/index_builder.rb
|
81
87
|
- app/builders/releaf/i18n_database/translations/table_builder.rb
|
82
88
|
- app/controllers/releaf/i18n_database/translations_controller.rb
|
83
|
-
- app/lib/releaf/i18n_database/
|
89
|
+
- app/lib/releaf/i18n_database/parse_spreadsheet_translations.rb
|
90
|
+
- app/lib/releaf/i18n_database/translations_store.rb
|
84
91
|
- app/lib/releaf/i18n_database/translations_utilities.rb
|
85
|
-
- app/models/releaf/i18n_database/
|
86
|
-
- app/models/releaf/i18n_database/
|
92
|
+
- app/models/releaf/i18n_database/i18n_entry.rb
|
93
|
+
- app/models/releaf/i18n_database/i18n_entry_translation.rb
|
87
94
|
- app/views/releaf/i18n_database/translations/_form_fields.haml
|
88
95
|
- app/views/releaf/i18n_database/translations/export.xlsx.axlsx
|
89
96
|
- lib/releaf-i18n_database.rb
|
90
97
|
- lib/releaf/i18n_database/backend.rb
|
91
|
-
- lib/releaf/i18n_database/
|
98
|
+
- lib/releaf/i18n_database/configuration.rb
|
92
99
|
- lib/releaf/i18n_database/engine.rb
|
93
100
|
- lib/releaf/i18n_database/humanize_missing_translations.rb
|
94
|
-
-
|
101
|
+
- misc/translations.xlsx
|
95
102
|
- spec/builders/translations/builder_common_spec.rb
|
96
103
|
- spec/builders/translations/edit_builder_spec.rb
|
97
104
|
- spec/builders/translations/index_builder_spec.rb
|
@@ -99,17 +106,22 @@ files:
|
|
99
106
|
- spec/controllers/i18n_backend/translations_controller_spec.rb
|
100
107
|
- spec/features/translations_spec.rb
|
101
108
|
- spec/fixtures/all_translations_exported.xlsx
|
109
|
+
- spec/fixtures/invalid.xls
|
110
|
+
- spec/fixtures/invalid.xlsx
|
102
111
|
- spec/fixtures/time.formats.xlsx
|
103
112
|
- spec/fixtures/translations_import.xlsx
|
104
113
|
- spec/fixtures/unsupported_import_file.png
|
105
|
-
- spec/lib/i18n_database/backend_spec.rb
|
106
|
-
- spec/lib/i18n_database/
|
107
|
-
- spec/lib/i18n_database/
|
108
|
-
- spec/lib/i18n_database/
|
109
|
-
- spec/
|
110
|
-
- spec/
|
114
|
+
- spec/lib/releaf/i18n_database/backend_spec.rb
|
115
|
+
- spec/lib/releaf/i18n_database/configuration_spec.rb
|
116
|
+
- spec/lib/releaf/i18n_database/humanize_missing_translations_spec.rb
|
117
|
+
- spec/lib/releaf/i18n_database/parse_spreadsheet_translations_spec.rb
|
118
|
+
- spec/lib/releaf/i18n_database/translations_store_spec.rb
|
119
|
+
- spec/lib/releaf/i18n_database/translations_utilities_spec.rb
|
120
|
+
- spec/models/i18n_database/i18n_entry_spec.rb
|
121
|
+
- spec/models/i18n_database/i18n_entry_translation_spec.rb
|
111
122
|
homepage: https://github.com/cubesystems/releaf
|
112
|
-
licenses:
|
123
|
+
licenses:
|
124
|
+
- MIT
|
113
125
|
metadata: {}
|
114
126
|
post_install_message:
|
115
127
|
rdoc_options: []
|
@@ -127,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
139
|
version: '0'
|
128
140
|
requirements: []
|
129
141
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.5.1
|
131
143
|
signing_key:
|
132
144
|
specification_version: 4
|
133
145
|
summary: i18n database gem for releaf
|
@@ -139,13 +151,16 @@ test_files:
|
|
139
151
|
- spec/controllers/i18n_backend/translations_controller_spec.rb
|
140
152
|
- spec/features/translations_spec.rb
|
141
153
|
- spec/fixtures/all_translations_exported.xlsx
|
154
|
+
- spec/fixtures/invalid.xls
|
155
|
+
- spec/fixtures/invalid.xlsx
|
142
156
|
- spec/fixtures/time.formats.xlsx
|
143
157
|
- spec/fixtures/translations_import.xlsx
|
144
158
|
- spec/fixtures/unsupported_import_file.png
|
145
|
-
- spec/lib/i18n_database/backend_spec.rb
|
146
|
-
- spec/lib/i18n_database/
|
147
|
-
- spec/lib/i18n_database/
|
148
|
-
- spec/lib/i18n_database/
|
149
|
-
- spec/
|
150
|
-
- spec/
|
151
|
-
|
159
|
+
- spec/lib/releaf/i18n_database/backend_spec.rb
|
160
|
+
- spec/lib/releaf/i18n_database/configuration_spec.rb
|
161
|
+
- spec/lib/releaf/i18n_database/humanize_missing_translations_spec.rb
|
162
|
+
- spec/lib/releaf/i18n_database/parse_spreadsheet_translations_spec.rb
|
163
|
+
- spec/lib/releaf/i18n_database/translations_store_spec.rb
|
164
|
+
- spec/lib/releaf/i18n_database/translations_utilities_spec.rb
|
165
|
+
- spec/models/i18n_database/i18n_entry_spec.rb
|
166
|
+
- spec/models/i18n_database/i18n_entry_translation_spec.rb
|
@@ -1,72 +0,0 @@
|
|
1
|
-
module Releaf::I18nDatabase
|
2
|
-
class TranslationsImporter
|
3
|
-
class UnsupportedFileFormatError < StandardError; end
|
4
|
-
|
5
|
-
def initialize file_path, file_extension
|
6
|
-
require "roo"
|
7
|
-
begin
|
8
|
-
@excel = Roo::Spreadsheet.open(file_path, file_warning: :ignore, extension: file_extension)
|
9
|
-
@data = []
|
10
|
-
@locales = []
|
11
|
-
rescue ArgumentError => e
|
12
|
-
error_string = "Don't know how to open file"
|
13
|
-
if e.message.match(error_string)
|
14
|
-
raise UnsupportedFileFormatError
|
15
|
-
else
|
16
|
-
raise
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def parsed_output
|
22
|
-
@excel.each_with_pagename do |name, sheet|
|
23
|
-
detect_sheet_locales(sheet)
|
24
|
-
parse_sheet(sheet)
|
25
|
-
end
|
26
|
-
|
27
|
-
@data
|
28
|
-
end
|
29
|
-
|
30
|
-
def detect_sheet_locales sheet
|
31
|
-
sheet.row(1).each_with_index do |cell, i|
|
32
|
-
if i > 0
|
33
|
-
@locales << cell
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def parse_sheet sheet
|
39
|
-
(2..sheet.last_row).each do |row_no|
|
40
|
-
key = sheet.row(row_no)[0]
|
41
|
-
localizations = sheet.row(row_no)[1..-1]
|
42
|
-
if key.present?
|
43
|
-
@data << load_translation(key, localizations)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def load_translation key, localizations
|
49
|
-
translation = Translation.where(key: key).first_or_initialize
|
50
|
-
translation.key = key
|
51
|
-
|
52
|
-
localizations.each_with_index do |localization, i|
|
53
|
-
load_translation_data(translation, @locales[i], localization)
|
54
|
-
end
|
55
|
-
|
56
|
-
translation
|
57
|
-
end
|
58
|
-
|
59
|
-
def load_translation_data translation, locale, localization
|
60
|
-
translation_data = translation.translation_data.find{ |x| x.lang == locale }
|
61
|
-
value = localization.nil? ? '' : localization
|
62
|
-
|
63
|
-
# replace existing locale value only if new one is not blank
|
64
|
-
if translation_data && !value.blank?
|
65
|
-
translation_data.localization = value
|
66
|
-
# always assign value for new locale
|
67
|
-
elsif translation_data.nil?
|
68
|
-
translation_data = translation.translation_data.build(lang: locale, localization: value)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|