rails_i18n_manager 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/rails_i18n_manager/translations_controller.rb +7 -12
- data/app/lib/rails_i18n_manager/forms/translation_file_form.rb +24 -7
- data/app/{jobs/rails_i18n_manager/translations_import_job.rb → lib/rails_i18n_manager/translations_importer.rb} +14 -3
- data/lib/rails_i18n_manager/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3398a11d93b08bd8d36e596876a4022bd6317cf45f99f69884652e39a66637ae
|
4
|
+
data.tar.gz: 1c2e294199f783bdd8edffea56742e20de92368e4e12cd386c8203d3fc4d640b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5e012eac4960dd31575b95670eef389abee24fce0e5e12111e6d38d401bf2dc518d46c169679609c1108015a8c2762c99f3a84f1a10b8bcdfbe65f2d41c086f
|
7
|
+
data.tar.gz: 9b8b8ec138663a5d6a536f5db8b5a743ae870a9ac07addbf5246decbbff84427af676158165a4db15599e2ce9e7ca51572a87aeb7bd59d0be97f55b83e977ab5
|
@@ -96,26 +96,21 @@ module RailsI18nManager
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def import
|
99
|
-
@form = Forms::TranslationFileForm.new(params[:import_form])
|
100
|
-
|
101
99
|
if request.get?
|
100
|
+
@form = Forms::TranslationFileForm.new
|
102
101
|
render
|
103
102
|
else
|
104
|
-
|
105
|
-
if @form.file.path.end_with?(".json")
|
106
|
-
parsed_file_contents = JSON.parse(@form.file.read)
|
107
|
-
else
|
108
|
-
parsed_file_contents = YAML.safe_load(@form.file.read)
|
109
|
-
end
|
103
|
+
@form = Forms::TranslationFileForm.new(params[:import_form])
|
110
104
|
|
105
|
+
if @form.valid?
|
111
106
|
begin
|
112
|
-
|
107
|
+
TranslationsImporter.import(
|
113
108
|
translation_app_id: @form.translation_app_id,
|
114
|
-
parsed_file_contents: parsed_file_contents,
|
109
|
+
parsed_file_contents: @form.parsed_file_contents,
|
115
110
|
overwrite_existing: @form.overwrite_existing,
|
116
111
|
mark_inactive_translations: @form.mark_inactive_translations,
|
117
112
|
)
|
118
|
-
rescue
|
113
|
+
rescue TranslationsImporter::ImportAbortedError => e
|
119
114
|
flash.now.alert = e.message
|
120
115
|
render
|
121
116
|
return
|
@@ -123,7 +118,7 @@ module RailsI18nManager
|
|
123
118
|
|
124
119
|
redirect_to translations_path, notice: "Import Successful"
|
125
120
|
else
|
126
|
-
flash.now.alert = "
|
121
|
+
flash.now.alert = "Please see form errors below"
|
127
122
|
render
|
128
123
|
end
|
129
124
|
end
|
@@ -17,36 +17,53 @@ module RailsI18nManager
|
|
17
17
|
@mark_inactive_translations = ["1", "true", "t"].include?(val.to_s.downcase)
|
18
18
|
end
|
19
19
|
|
20
|
+
def file_extname
|
21
|
+
@file_extname ||= File.extname(file)
|
22
|
+
end
|
23
|
+
|
24
|
+
def file_contents_string
|
25
|
+
@file_contents_string ||= file.read
|
26
|
+
end
|
27
|
+
|
28
|
+
def parsed_file_contents
|
29
|
+
if defined?(@parsed_file_contents)
|
30
|
+
return @parsed_file_contents
|
31
|
+
end
|
32
|
+
|
33
|
+
case file_extname
|
34
|
+
when ".yml", ".yaml"
|
35
|
+
@parsed_file_contents = YAML.safe_load(file_contents_string)
|
36
|
+
when ".json"
|
37
|
+
@parsed_file_contents = JSON.parse(file_contents_string)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
20
41
|
def validate_file
|
21
42
|
if file.blank?
|
22
43
|
errors.add(:file, "Must upload a valid translation file.")
|
23
44
|
return
|
24
45
|
end
|
25
46
|
|
26
|
-
file_extname = File.extname(file)
|
27
|
-
|
28
47
|
if [".yml", ".yaml", ".json"].exclude?(file_extname)
|
29
48
|
errors.add(:file, "Invalid file format. Must be yaml or json file.")
|
30
49
|
return
|
31
50
|
end
|
32
51
|
|
33
|
-
|
34
|
-
|
35
|
-
if file_contents.blank?
|
52
|
+
if file_contents_string.blank?
|
36
53
|
errors.add(:file, "Empty file provided.")
|
37
54
|
return
|
38
55
|
end
|
39
56
|
|
40
57
|
case file_extname
|
41
58
|
when ".yml", ".yaml"
|
42
|
-
if !
|
59
|
+
if !parsed_file_contents.is_a?(Hash)
|
43
60
|
errors.add(:file, "Invalid #{file_extname.sub(".","")} file.")
|
44
61
|
return
|
45
62
|
end
|
46
63
|
|
47
64
|
when ".json"
|
48
65
|
begin
|
49
|
-
|
66
|
+
parsed_file_contents
|
50
67
|
rescue JSON::ParserError
|
51
68
|
errors.add(:file, "Invalid json file.")
|
52
69
|
return
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module RailsI18nManager
|
2
|
-
class
|
2
|
+
class TranslationsImporter
|
3
3
|
|
4
4
|
class ImportAbortedError < StandardError; end
|
5
5
|
|
6
|
-
def
|
6
|
+
def self.import(translation_app_id:, parsed_file_contents:, overwrite_existing: false, mark_inactive_translations: false)
|
7
7
|
app_record = TranslationApp.find(translation_app_id)
|
8
8
|
|
9
9
|
new_locales = parsed_file_contents.keys - app_record.all_locales
|
@@ -29,7 +29,18 @@ module RailsI18nManager
|
|
29
29
|
app_record.all_locales.each do |locale|
|
30
30
|
split_keys = [locale] + key.split(".").map{|x| x}
|
31
31
|
|
32
|
-
val =
|
32
|
+
val = nil
|
33
|
+
|
34
|
+
current_hash = parsed_file_contents
|
35
|
+
|
36
|
+
split_keys.each do |k|
|
37
|
+
if current_hash[k].is_a?(Hash)
|
38
|
+
current_hash = current_hash[k]
|
39
|
+
else
|
40
|
+
val = current_hash[k]
|
41
|
+
break
|
42
|
+
end
|
43
|
+
end
|
33
44
|
|
34
45
|
if val.present?
|
35
46
|
val_record = key_record.translation_values.detect{|x| x.locale == locale.to_s }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_i18n_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Weston Ganger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -225,10 +225,10 @@ files:
|
|
225
225
|
- app/controllers/rails_i18n_manager/translations_controller.rb
|
226
226
|
- app/helpers/rails_i18n_manager/application_helper.rb
|
227
227
|
- app/helpers/rails_i18n_manager/custom_form_builder.rb
|
228
|
-
- app/jobs/rails_i18n_manager/translations_import_job.rb
|
229
228
|
- app/lib/rails_i18n_manager/forms/base.rb
|
230
229
|
- app/lib/rails_i18n_manager/forms/translation_file_form.rb
|
231
230
|
- app/lib/rails_i18n_manager/google_translate.rb
|
231
|
+
- app/lib/rails_i18n_manager/translations_importer.rb
|
232
232
|
- app/models/rails_i18n_manager/application_record.rb
|
233
233
|
- app/models/rails_i18n_manager/translation_app.rb
|
234
234
|
- app/models/rails_i18n_manager/translation_key.rb
|