rails_i18n_manager 1.1.1 → 1.1.3
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/app/views/layouts/rails_i18n_manager/_assets.html.slim +0 -4
- data/app/views/rails_i18n_manager/form_builder/_basic_field.html.erb +2 -0
- data/app/views/rails_i18n_manager/translations/import.html.slim +1 -1
- data/lib/rails_i18n_manager/version.rb +1 -1
- metadata +18 -4
- /data/app/{helpers → lib}/rails_i18n_manager/custom_form_builder.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: defa73fd31070325ba7285823e0a03ace7ab8c9a5808030f26638c0019de1acd
|
4
|
+
data.tar.gz: 11ea4841b06c54736b5be651d5d8e50d7bb232e4aedbfeaa82f7c9883bf7b4e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95c8a9c7e660fbe4b3294eca65aceda6a3dd0c550acb41cf7abdb1aa4c585e45c529cee2b81d18ac692039d5525c07ae6b80c8a242963ff388cbd12f13db9f20
|
7
|
+
data.tar.gz: 79fd6614787767d5173d5b5812515dc7118f4dcfe2d9583a160c61b8760b13f7b06e8baaa5cb4a09c9ab1a60213d933d87c753db7f68881ef4ac71435d3299b0
|
@@ -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, permitted_classes: [Symbol])
|
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 }
|
@@ -13,8 +13,4 @@ script src="https://cdnjs.cloudflare.com/ajax/libs/slim-select/2.4.5/slimselect.
|
|
13
13
|
|
14
14
|
script src="https://cdnjs.cloudflare.com/ajax/libs/autosize.js/3.0.20/autosize.min.js" integrity="sha512-EAEoidLzhKrfVg7qX8xZFEAebhmBMsXrIcI0h7VPx2CyAyFHuDvOAUs9CEATB2Ou2/kuWEDtluEVrQcjXBy9yw==" crossorigin="anonymous" referrerpolicy="no-referrer"
|
15
15
|
|
16
|
-
link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome.min.css" integrity="sha512-IJ+BZHGlT4K43sqBGUzJ90pcxfkREDVZPZxeexRigVL8rzdw/gyJIflDahMdNzBww4k0WxpyaWpC2PLQUWmMUQ==" crossorigin="anonymous" referrerpolicy="no-referrer"
|
17
|
-
|
18
|
-
link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha512-SfTiTlX6kk+qitfevl/7LibUOeJWlt9rbyDn92a1DqWOw9vWG2MFoays0sgObmWazO5BQPiFucnnEAjpAB+/Sw==" crossorigin="anonymous" referrerpolicy="no-referrer"
|
19
|
-
|
20
16
|
= render "layouts/rails_i18n_manager/app_javascript"
|
@@ -4,7 +4,7 @@ h2.page-sub-title Import Translations from Source File
|
|
4
4
|
|
5
5
|
.row
|
6
6
|
.col-6
|
7
|
-
= custom_form_for @form, as: :import_form, url: import_translations_path, method: :post, multipart: true,
|
7
|
+
= custom_form_for @form, as: :import_form, url: import_translations_path, method: :post, html: {multipart: true, class: "form-horizontal"} do |f|
|
8
8
|
= f.error_notification
|
9
9
|
|
10
10
|
= f.field :translation_app_id, label: "App Name", type: :select, collection: RailsI18nManager::TranslationApp.order(name: :asc).pluck(:name, :id)
|
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.3
|
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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec-html-matchers
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: factory_bot_rails
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,11 +238,11 @@ files:
|
|
224
238
|
- app/controllers/rails_i18n_manager/translation_apps_controller.rb
|
225
239
|
- app/controllers/rails_i18n_manager/translations_controller.rb
|
226
240
|
- app/helpers/rails_i18n_manager/application_helper.rb
|
227
|
-
- app/
|
228
|
-
- app/jobs/rails_i18n_manager/translations_import_job.rb
|
241
|
+
- app/lib/rails_i18n_manager/custom_form_builder.rb
|
229
242
|
- app/lib/rails_i18n_manager/forms/base.rb
|
230
243
|
- app/lib/rails_i18n_manager/forms/translation_file_form.rb
|
231
244
|
- app/lib/rails_i18n_manager/google_translate.rb
|
245
|
+
- app/lib/rails_i18n_manager/translations_importer.rb
|
232
246
|
- app/models/rails_i18n_manager/application_record.rb
|
233
247
|
- app/models/rails_i18n_manager/translation_app.rb
|
234
248
|
- app/models/rails_i18n_manager/translation_key.rb
|
File without changes
|