awesome_translations 0.0.57 → 0.0.61
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +1 -1
- data/app/controllers/awesome_translations/clean_ups_controller.rb +1 -1
- data/app/controllers/awesome_translations/groups_controller.rb +1 -0
- data/app/controllers/awesome_translations/handlers_controller.rb +1 -0
- data/app/helpers/awesome_translations/application_helper.rb +0 -1
- data/app/models/awesome_translations/group.rb +2 -2
- data/app/models/awesome_translations/translated_value.rb +6 -3
- data/app/models/awesome_translations/translation.rb +9 -4
- data/app/views/awesome_translations/duplicates/index.html.erb +2 -2
- data/app/views/awesome_translations/groups/show.html.erb +9 -4
- data/app/views/awesome_translations/handler_translations/index.html.erb +21 -6
- data/app/views/awesome_translations/handlers/show.html.erb +29 -6
- data/app/views/awesome_translations/movals/index.html.erb +2 -2
- data/lib/awesome_translations/cache_database_generator/group.rb +10 -3
- data/lib/awesome_translations/cache_database_generator/handler.rb +9 -2
- data/lib/awesome_translations/cache_database_generator/handler_translation.rb +13 -3
- data/lib/awesome_translations/cache_database_generator/translation_key.rb +4 -4
- data/lib/awesome_translations/cache_database_generator/translation_value.rb +3 -1
- data/lib/awesome_translations/cache_database_generator.rb +2 -2
- data/lib/awesome_translations/config.rb +3 -3
- data/lib/awesome_translations/controller_translate_functionality.rb +2 -2
- data/lib/awesome_translations/engine.rb +0 -4
- data/lib/awesome_translations/erb_inspector/file_inspector.rb +4 -4
- data/lib/awesome_translations/erb_inspector/translation_inspector.rb +8 -8
- data/lib/awesome_translations/erb_inspector.rb +1 -0
- data/lib/awesome_translations/global_translator.rb +14 -28
- data/lib/awesome_translations/handlers/file_handler.rb +1 -0
- data/lib/awesome_translations/handlers/model_handler.rb +1 -1
- data/lib/awesome_translations/handlers/validations_handler.rb +4 -4
- data/lib/awesome_translations/handlers.rb +1 -0
- data/lib/awesome_translations/model_inspector.rb +23 -17
- data/lib/awesome_translations/object_extensions.rb +2 -2
- data/lib/awesome_translations/translation_migrator.rb +3 -3
- data/lib/awesome_translations/version.rb +1 -1
- data/lib/awesome_translations.rb +1 -1
- data/lib/tasks/awesome_translations_tasks.rake +1 -4
- data/spec/controllers/groups_controller_spec.rb +5 -5
- data/spec/controllers/handlers_controller_spec.rb +4 -4
- data/spec/controllers/users_controller_spec.rb +4 -2
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -7
- data/spec/dummy/app/controllers/users_controller.rb +1 -1
- data/spec/dummy/app/mailers/my_mailer.rb +1 -1
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/role.rb +2 -5
- data/spec/dummy/app/models/user.rb +1 -1
- data/spec/dummy/bin/bundle +1 -1
- data/spec/dummy/bin/rails +1 -1
- data/spec/dummy/config/application.rb +7 -2
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/db/awesome_translations.sqlite3 +0 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +52 -0
- data/spec/dummy/log/test.log +770 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2m/2mnPY9uUnBNkGHLxtFaWv5hB3oA7sY2K1ZtwQlZLnAY.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/3N/3NnKgR2TsTI1qCXKZpts0uJzp2dRJcoYp3nnFU6YE4o.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/5r/5rpKlqLSFsRCibev7g6MQkIOhWuOah-1KAN3aqV_fYI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/6E/6ExTs_VkmUe-fovt99Kw8rq-xCfx0_qGsSoldSWScZI.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8O/8OrG8phjC9s5-_7GAI2TEmRjsrGsuvq1gnJQPdMm8v8.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8f/8f4REKYOWkNfHexyAVqGXnbOP3vky_ANapWzlRMDeQ4.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8n/8n_viDw_qMQaQmqHM0ObPADed5uRyEYo3gDZIiTqUyA.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9e/9euY4B26kaHeiqfd1Qc0bsfRjpzmq36X6uqUfaRNtIs.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/AB/AB5PxrhEqi8qOm7AmSf-sHDs9ffj_iTsytaHas2ryPA.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/AI/AICJO1oM9dzlQ_N1QlHcCN9e8PC0wjtYk7-VmuNdfwg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ca/CaGQBiCuFgkHQ5gw8ZnGQqO8iP1md3GcllDsmaKBFdQ.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ch/ChWez9UVXMuuBpLJMDRGuDmMuXy8gIuFo6794-wBgXc.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/D9/D9eOwgl8pLlC7LJu-LL59UeHm9d-CH1mPgsA8j6xkMg.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Do/Do83AoOat5W-c1g7piDGy2GMmffsY6JY0Qfuh5PY3GM.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Hn/Hn53895nYKzu-g1FJKYS_yszYqCADXasTmN615R_qMQ.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/It/ItV7jxV0bfHndR-H3cidDwpTFGhvs0ETLRqCTmZMXB8.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/LL/LL0EenAcTXP-UNCqfcKtMF4Z8oDeWvdlwLQfuOVRPdw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Mj/MjwYGG9GkHD1fwwH2bg66EBYl3zCA_mqeDF9otey4-U.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/NU/NUN9oO9gyoo-sY32AOLHdDACjLIxisCxXdKd84ou6cs.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ob/ObuKkBd-camcT52YpgeuyheU-GDFLZCJnoVtq2plgW0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Og/Og_HPfE6734sqkQ0_h4EkOOx3Aoq1LABLH9ovjl6Bvw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pw/Pwuhz_6So_JcSrxT0Uf4VaLhh_FFSJMKxLZFMbS0LNQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/R-/R-nohuDiORrLlJJtKc5bQsjIRS8yTQFVR3EIxJx3JZw.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/SX/SXA6qKBlsAQ-MLPi7-KPCPcSx9Gg2VR1xa-lCmgipgA.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Sb/Sb1Vug319YfPL2Rci1PLMLXJjeIFYcNbHb5hKOvO1eo.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/_f/_f0DjbdXTMEPb52THCCF5qbKkDs28tHHnap5ag4jsdU.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dT/dTb1O_9BwFdhA3VT1UTxY-XIIoAGDHGHVO9bzRUNIfc.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dV/dVTKOfd8qDIHT3VD-4emnl0yAIxcSF1pY0CUESPHwdM.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/i0/i0TQIUsntlYrsibtn9YfB3qbI6bj8hLPom8KUfxR078.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jF/jFFXBsyFdv_TiNykX219AHs3Q7dQInYRP_80cAWZsgE.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/mX/mXfx3VRudxpXrRx1aejtNA5YHOwND3kwWUfvdXHSors.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/nG/nGQXdOLWsP4c926DJJBNXFUE0cKfZynnqN5aQ4T1I48.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/oX/oXeqOS7RZb4eFbKrraeQtr6TUrXPTueLN_Crp7S0RLE.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/p2/p27Ube4R6tciXRc0F8lpz6wUzmXIPxwqz7dKaUYVVuc.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/pv/pv6tV3CDkIAmLXdU8EPLlNEkXAKJPufVD4VP30o4fWo.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/q6/q6BYa32YJF11eGVapO4ouNl6gayPIsARgMavlzZmoi0.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/r5/r5draRYO72lGMZZKpqYbscAWxAawJVG7uO0uyx3iw24.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/r7/r7kGQJTsdrqs3i-prYAVnngsoc6uAtrjLTULTJdgy9g.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/rI/rITk_65QtUwq61bjRPAksGeJxbLUFfz-sFPnQiZPHjw.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/rR/rRS9OkVGJ9Wvs1fwZH-raqD4sXkbV8WmlLGIibYpZmI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/u9/u9nsXMBU9hA4UnH4SDHgk19ev_JNeeiS1-EZDrgStCI.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/un/unZXcRqhGJwHvVWJmJ1rTizBZq6H5jF28E5-FHyTYL4.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/wP/wP-1NwhQC0Sp_5PHpwAI7N0_N99vLNy0TA2FcMd6zgE.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/x7/x7KkTV3ibfIEysLB_ug5bfmnn2VLV_BldukPR3EoPBk.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/xr/xrDdkyCzfXr-pIE8gfvD8iFiWPuq9EwuZIl-uU9s0_o.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yc/yc3EXb1cvVLmwnk8aQN89bgVFeuwsVz2k2p0mvC2c3c.cache +1 -0
- data/spec/factories/group.rb +2 -2
- data/spec/factories/handler.rb +4 -4
- data/spec/factories/handler_translation.rb +5 -5
- data/spec/factories/translation_key.rb +1 -1
- data/spec/factories/translation_value.rb +3 -3
- data/spec/features/clean_ups_spec.rb +2 -5
- data/spec/features/duplicates_spec.rb +5 -7
- data/spec/features/movals_spec.rb +8 -10
- data/spec/handlers/file_handler_spec.rb +8 -8
- data/spec/handlers/model_handler_spec.rb +4 -4
- data/spec/handlers/validations_handler_spec.rb +3 -3
- data/spec/handlers_spec.rb +1 -1
- data/spec/lib/cache_database_generator_spec.rb +4 -4
- data/spec/lib/erb_inspector/file_inspector_spec.rb +2 -2
- data/spec/lib/erb_inspector/translation_inspector_spec.rb +2 -2
- data/spec/lib/erb_inspector_spec.rb +5 -5
- data/spec/lib/model_inspector_spec.rb +4 -4
- data/spec/lib/translation_migrator_spec.rb +3 -3
- data/spec/models/awesome_translations/handler_spec.rb +1 -1
- data/spec/models/awesome_translations/translated_value_spec.rb +1 -3
- data/spec/models/awesome_translations/translation_spec.rb +7 -2
- data/spec/spec_helper.rb +7 -8
- metadata +186 -101
- data/config/initializers/simple_form_ransack.rb +0 -1
@@ -1,28 +1,13 @@
|
|
1
1
|
class AwesomeTranslations::GlobalTranslator
|
2
|
-
RUBY_2 = RUBY_VERSION.starts_with?("2")
|
3
|
-
|
4
2
|
def self.call_information(caller_number)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
else
|
15
|
-
call = caller[caller_number + 1]
|
16
|
-
file_info = call.match(/\A(.+):(\d+):in `(.+?)'/)
|
17
|
-
|
18
|
-
raise "Could not get previous file name from: #{caller[0]}" if file_info[1].blank?
|
19
|
-
|
20
|
-
{
|
21
|
-
method: file_info[3],
|
22
|
-
path: file_info[1],
|
23
|
-
line_no: file_info[2]
|
24
|
-
}
|
25
|
-
end
|
3
|
+
# This is much faster than the other solution
|
4
|
+
call = caller_locations(caller_number + 2, caller_number + 2).first
|
5
|
+
|
6
|
+
{
|
7
|
+
method: call.label,
|
8
|
+
path: call.absolute_path,
|
9
|
+
line_no: call.lineno
|
10
|
+
}
|
26
11
|
end
|
27
12
|
|
28
13
|
def self.translate(key, args, &blk)
|
@@ -52,7 +37,7 @@ class AwesomeTranslations::GlobalTranslator
|
|
52
37
|
@key = translation_key
|
53
38
|
end
|
54
39
|
|
55
|
-
I18n.t(@key, *args[:translation_args], &blk)
|
40
|
+
I18n.t(@key, *args[:translation_args], **args[:translation_opts], &blk)
|
56
41
|
end
|
57
42
|
|
58
43
|
private
|
@@ -60,8 +45,8 @@ private
|
|
60
45
|
def dir
|
61
46
|
if @_dir.nil?
|
62
47
|
@_dir = File.dirname(previous_file)
|
63
|
-
@_dir
|
64
|
-
@_dir
|
48
|
+
@_dir.delete_prefix!("#{Rails.root}/") # rubocop:disable Rails/FilePath
|
49
|
+
@_dir.delete_prefix!("spec/dummy/")
|
65
50
|
|
66
51
|
if @_dir.starts_with?("app/controllers")
|
67
52
|
@_dir = @_dir.gsub(/\Aapp\/controllers(\/?)/, "")
|
@@ -69,7 +54,7 @@ private
|
|
69
54
|
elsif @_dir.starts_with?("app/views")
|
70
55
|
@_dir = @_dir.gsub(/\Aapp\/views(\/?)/, "")
|
71
56
|
elsif @_dir.starts_with?("app/")
|
72
|
-
@_dir
|
57
|
+
@_dir.delete_prefix!("app/")
|
73
58
|
end
|
74
59
|
end
|
75
60
|
|
@@ -99,6 +84,7 @@ private
|
|
99
84
|
root = engine.root.to_s
|
100
85
|
|
101
86
|
next unless @_previous_file.starts_with?(root)
|
87
|
+
|
102
88
|
@_previous_file = @_previous_file.gsub(/\A#{Regexp.escape(root)}\//, "")
|
103
89
|
break
|
104
90
|
end
|
@@ -109,7 +95,7 @@ private
|
|
109
95
|
|
110
96
|
def translation_key
|
111
97
|
translation_key = dir
|
112
|
-
translation_key = translation_key.
|
98
|
+
translation_key = translation_key.delete_prefix("app/")
|
113
99
|
translation_key << "/#{file}"
|
114
100
|
|
115
101
|
key_parts = translation_key.split("/")
|
@@ -27,6 +27,7 @@ class AwesomeTranslations::Handlers::FileHandler < AwesomeTranslations::Handlers
|
|
27
27
|
file = erb_inspector.file(group.data.fetch(:root_path), group.data.fetch(:file_path))
|
28
28
|
file.translations.each do |translation|
|
29
29
|
next if translations_found.key?(translation.full_key)
|
30
|
+
|
30
31
|
translations_found[translation.full_key] = true
|
31
32
|
yielder << translation.model
|
32
33
|
end
|
@@ -12,7 +12,7 @@ class AwesomeTranslations::Handlers::ModelHandler < AwesomeTranslations::Handler
|
|
12
12
|
|
13
13
|
def translations_for_group(group)
|
14
14
|
ArrayEnumerator.new do |yielder|
|
15
|
-
model_inspector = AwesomeTranslations::ModelInspector.model_classes.find { |
|
15
|
+
model_inspector = AwesomeTranslations::ModelInspector.model_classes.find { |model_inspector_i| model_inspector_i.clazz.name == group.name }
|
16
16
|
raise "No inspector by that name: #{group.name}" unless model_inspector
|
17
17
|
|
18
18
|
model_names(model_inspector).each { |translation| yielder << translation }
|
@@ -12,7 +12,7 @@ class AwesomeTranslations::Handlers::ValidationsHandler < AwesomeTranslations::H
|
|
12
12
|
|
13
13
|
def translations_for_group(group)
|
14
14
|
ArrayEnumerator.new do |yielder|
|
15
|
-
model_inspector = AwesomeTranslations::ModelInspector.model_classes.find { |
|
15
|
+
model_inspector = AwesomeTranslations::ModelInspector.model_classes.find { |model_inspector_i| model_inspector_i.clazz.name == group.name }
|
16
16
|
raise "No inspector by that name: #{group.name}" unless model_inspector
|
17
17
|
|
18
18
|
model_inspector.clazz._validators.each do |attribute_name, validators|
|
@@ -23,11 +23,11 @@ class AwesomeTranslations::Handlers::ValidationsHandler < AwesomeTranslations::H
|
|
23
23
|
translations_for_format_validator(validator, model_inspector, attribute_name, yielder)
|
24
24
|
elsif validator.is_a?(ActiveRecord::Validations::UniquenessValidator)
|
25
25
|
translations_for_uniqueness_validator(validator, model_inspector, attribute_name, yielder)
|
26
|
-
elsif validator.class.name == "ActiveRecord::Validations::PresenceValidator"
|
26
|
+
elsif validator.class.name == "ActiveRecord::Validations::PresenceValidator" # rubocop:disable Style/ClassEqualityComparison:
|
27
27
|
translations_for_presence_validator(validator, model_inspector, attribute_name, yielder)
|
28
|
-
elsif validator.class.name == "EmailValidator"
|
28
|
+
elsif validator.class.name == "EmailValidator" # rubocop:disable Style/ClassEqualityComparison:
|
29
29
|
translations_for_email_validator(validator, model_inspector, attribute_name, yielder)
|
30
|
-
elsif validator.class.name == "ActiveModel::Validations::ConfirmationValidator"
|
30
|
+
elsif validator.class.name == "ActiveModel::Validations::ConfirmationValidator" # rubocop:disable Style/ClassEqualityComparison:
|
31
31
|
translations_for_confirmation_validator(validator, model_inspector, attribute_name, yielder)
|
32
32
|
else
|
33
33
|
Rails.logger.error "Unhandeled validator: #{validator.class.name}"
|
@@ -2,6 +2,7 @@ class AwesomeTranslations::ModelInspector
|
|
2
2
|
autoload :Attribute, "#{File.dirname(__FILE__)}/model_inspector/attribute"
|
3
3
|
|
4
4
|
attr_reader :clazz
|
5
|
+
|
5
6
|
cattr_accessor :models_loaded
|
6
7
|
|
7
8
|
# Yields a model-inspector for each model found in the application.
|
@@ -16,6 +17,7 @@ class AwesomeTranslations::ModelInspector
|
|
16
17
|
ArrayEnumerator.new do |yielder|
|
17
18
|
find_subclasses(ActiveRecord::Base) do |model_inspector|
|
18
19
|
next if !model_inspector.clazz.name || @skip.include?(model_inspector.clazz.name)
|
20
|
+
|
19
21
|
yielder << model_inspector
|
20
22
|
end
|
21
23
|
end
|
@@ -33,15 +35,14 @@ class AwesomeTranslations::ModelInspector
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
def paperclip_attachments
|
37
|
-
return unless ::Kernel.const_defined?(
|
38
|
-
|
39
|
-
|
40
|
-
end
|
38
|
+
def paperclip_attachments(&blk)
|
39
|
+
return unless ::Kernel.const_defined?(:Paperclip)
|
40
|
+
|
41
|
+
Paperclip::AttachmentRegistry.names_for(@clazz, &blk)
|
41
42
|
end
|
42
43
|
|
43
44
|
def money_attributes
|
44
|
-
return if !::Kernel.const_defined?(
|
45
|
+
return if !::Kernel.const_defined?(:Money) || !@clazz.respond_to?(:monetized_attributes)
|
45
46
|
|
46
47
|
@clazz.monetized_attributes.each do |attribute|
|
47
48
|
yield attribute[0].to_s
|
@@ -49,7 +50,7 @@ class AwesomeTranslations::ModelInspector
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def globalize_attributes
|
52
|
-
return if !::Kernel.const_defined?(
|
53
|
+
return if !::Kernel.const_defined?(:Globalize) || !@clazz.respond_to?(:translated_attribute_names)
|
53
54
|
|
54
55
|
@clazz.translated_attribute_names.each do |attribute|
|
55
56
|
yield attribute.to_s
|
@@ -73,10 +74,8 @@ class AwesomeTranslations::ModelInspector
|
|
73
74
|
end
|
74
75
|
|
75
76
|
# TODO: Maybe this should yield a ModelInspector::Relationship instead?
|
76
|
-
def relationships
|
77
|
-
@clazz.reflections.each
|
78
|
-
yield key, reflection
|
79
|
-
end
|
77
|
+
def relationships(&blk)
|
78
|
+
@clazz.reflections.each(&blk)
|
80
79
|
end
|
81
80
|
|
82
81
|
def attribute_key(attribute_name)
|
@@ -93,10 +92,11 @@ class AwesomeTranslations::ModelInspector
|
|
93
92
|
|
94
93
|
def self.find_subclasses(clazz, &blk)
|
95
94
|
return if @scanned[clazz.name]
|
95
|
+
|
96
96
|
@scanned[clazz.name] = true
|
97
97
|
|
98
98
|
clazz.subclasses.each do |subclass|
|
99
|
-
|
99
|
+
yield ::AwesomeTranslations::ModelInspector.new(subclass)
|
100
100
|
find_subclasses(subclass, &blk)
|
101
101
|
end
|
102
102
|
end
|
@@ -121,14 +121,20 @@ class AwesomeTranslations::ModelInspector
|
|
121
121
|
|
122
122
|
# Loads models for the given app-directory (Rails-root or engine).
|
123
123
|
def self.load_models_for(root)
|
124
|
-
Dir.glob("#{root}/app/models/**/*.rb") do |model_path|
|
124
|
+
Dir.glob("#{root}/app/models/**/*.rb").sort.each do |model_path|
|
125
|
+
next if active_storage_path?(model_path)
|
126
|
+
|
125
127
|
begin
|
126
128
|
require model_path
|
127
|
-
rescue => e
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
rescue StandardError => e
|
130
|
+
warn "Could not load model in #{model_path}"
|
131
|
+
warn e.inspect
|
132
|
+
warn e.backtrace
|
131
133
|
end
|
132
134
|
end
|
133
135
|
end
|
136
|
+
|
137
|
+
def self.active_storage_path?(model_path)
|
138
|
+
model_path.match?(/\/gems\/activestorage-([\d.]+)\//)
|
139
|
+
end
|
134
140
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module AwesomeTranslations::ObjectExtensions
|
2
|
-
def t(key, *args, &blk)
|
3
|
-
AwesomeTranslations::GlobalTranslator.translate(key, caller_number: 1, translation_args: args, &blk)
|
2
|
+
def t(key, *args, **opts, &blk)
|
3
|
+
AwesomeTranslations::GlobalTranslator.translate(key, caller_number: 1, translation_args: args, translation_opts: opts, &blk)
|
4
4
|
end
|
5
5
|
end
|
@@ -34,17 +34,17 @@ class AwesomeTranslations::TranslationMigrator
|
|
34
34
|
|
35
35
|
if @new_path
|
36
36
|
FileUtils.mkdir_p(File.dirname(@new_path))
|
37
|
-
File.
|
37
|
+
File.write(@new_path, YAML.dump(new_translations_hash))
|
38
38
|
end
|
39
39
|
|
40
40
|
if translations_hash.empty?
|
41
41
|
I18n.load_path.delete(@old_path)
|
42
42
|
File.unlink(@old_path)
|
43
43
|
else
|
44
|
-
File.
|
44
|
+
File.write(@old_path, YAML.dump(translations_hash))
|
45
45
|
end
|
46
46
|
|
47
|
-
@translation_value.
|
47
|
+
@translation_value.update!(file_path: @new_path) if @new_path
|
48
48
|
end
|
49
49
|
|
50
50
|
private
|
data/lib/awesome_translations.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
namespace :awesome_translations do
|
7
7
|
task "install" => :environment do
|
8
|
-
yml_root =
|
8
|
+
yml_root = Rails.root.join("config/locales/awesome_translations")
|
9
9
|
|
10
10
|
dirs = [
|
11
11
|
yml_root,
|
@@ -22,7 +22,4 @@ namespace :awesome_translations do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
|
-
task "update" => :environment do
|
27
|
-
end
|
28
25
|
end
|
@@ -3,10 +3,10 @@ require "spec_helper"
|
|
3
3
|
describe AwesomeTranslations::GroupsController do
|
4
4
|
routes { AwesomeTranslations::Engine.routes }
|
5
5
|
|
6
|
-
let(:model_locales_path) { Rails.root.join("config
|
6
|
+
let(:model_locales_path) { Rails.root.join("config/locales/awesome_translations/models").to_s }
|
7
7
|
let(:user_yml_path) { "#{model_locales_path}/user/da.yml" }
|
8
8
|
let(:role_yml_path) { "#{model_locales_path}/role/da.yml" }
|
9
|
-
let(:date_time_path) { Rails.root.join("config
|
9
|
+
let(:date_time_path) { Rails.root.join("config/locales/awesome_translations/date_time/da.yml").to_s }
|
10
10
|
|
11
11
|
before do
|
12
12
|
AwesomeTranslations::CacheDatabaseGenerator.current.cache_translations
|
@@ -22,7 +22,7 @@ describe AwesomeTranslations::GroupsController do
|
|
22
22
|
|
23
23
|
describe "#update" do
|
24
24
|
it "updates translations" do
|
25
|
-
expect(I18n.load_path).
|
25
|
+
expect(I18n.load_path).not_to include model_locales_path
|
26
26
|
|
27
27
|
put :update, params: {handler_id: "model_handler", id: "User", t: {
|
28
28
|
"activerecord.attributes.user.password" => {"da" => "Adgangskode", "de" => "Kenwort", "en" => "Password"}
|
@@ -47,10 +47,10 @@ describe AwesomeTranslations::GroupsController do
|
|
47
47
|
.joins(:translation_key)
|
48
48
|
.find_by(translation_keys: {key: key_to_update}, locale: "de")
|
49
49
|
|
50
|
-
expect(da_translation_value).
|
50
|
+
expect(da_translation_value).not_to eq nil
|
51
51
|
expect(da_translation_value.value).to eq "Rolle"
|
52
52
|
|
53
|
-
expect(de_translation_value).
|
53
|
+
expect(de_translation_value).not_to eq nil
|
54
54
|
expect(de_translation_value.value).to eq "Die type"
|
55
55
|
|
56
56
|
expect(I18n.load_path).to include role_yml_path
|
@@ -12,7 +12,7 @@ describe AwesomeTranslations::HandlersController do
|
|
12
12
|
describe "#index" do
|
13
13
|
it "renders the page" do
|
14
14
|
get :index
|
15
|
-
expect(response).to
|
15
|
+
expect(response).to be_successful
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,7 +20,7 @@ describe AwesomeTranslations::HandlersController do
|
|
20
20
|
it "renders the page" do
|
21
21
|
AwesomeTranslations::CacheDatabaseGenerator.current.cache_translations
|
22
22
|
get :show, params: {id: "model_handler"}
|
23
|
-
expect(response).to
|
23
|
+
expect(response).to be_successful
|
24
24
|
end
|
25
25
|
|
26
26
|
it "filters with missing translations" do
|
@@ -31,8 +31,8 @@ describe AwesomeTranslations::HandlersController do
|
|
31
31
|
groups = assigns(:groups)
|
32
32
|
|
33
33
|
expect(all_groups.length).to be > groups.length
|
34
|
-
expect(groups.length).to eq
|
35
|
-
expect(response).to
|
34
|
+
expect(groups.length).to eq 5
|
35
|
+
expect(response).to be_successful
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
data/spec/dummy/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
2
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
3
|
|
4
|
-
require File.expand_path("
|
4
|
+
require File.expand_path("config/application", __dir__)
|
5
5
|
|
6
6
|
Dummy::Application.load_tasks
|
@@ -5,15 +5,11 @@ class ApplicationController < ActionController::Base
|
|
5
5
|
# For APIs, you may want to use :null_session instead.
|
6
6
|
protect_from_forgery with: :exception
|
7
7
|
|
8
|
-
|
8
|
+
around_action :with_locale
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
I18n.locale = session[:locale]
|
15
|
-
else
|
16
|
-
I18n.locale = :en
|
17
|
-
end
|
12
|
+
def with_locale(&blk)
|
13
|
+
I18n.with_locale(session[:locale] || :en, &blk)
|
18
14
|
end
|
19
15
|
end
|
data/spec/dummy/bin/bundle
CHANGED
data/spec/dummy/bin/rails
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path("
|
1
|
+
require File.expand_path("boot", __dir__)
|
2
2
|
|
3
3
|
# Pick the frameworks you want:
|
4
4
|
require "active_record/railtie"
|
@@ -24,7 +24,12 @@ class Dummy::Application < Rails::Application
|
|
24
24
|
# config.time_zone = 'Central Time (US & Canada)'
|
25
25
|
|
26
26
|
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
27
|
-
config.i18n.load_path += Dir[Rails.root.join("config
|
27
|
+
config.i18n.load_path += Dir[Rails.root.join("config/locales/**/*.{rb,yml}").to_s]
|
28
28
|
config.i18n.available_locales = [:da, :de, :en]
|
29
29
|
config.i18n.default_locale = :en
|
30
|
+
|
31
|
+
config.assets.precompile += %w[
|
32
|
+
awesome_translations/application.css
|
33
|
+
awesome_translations/application.js
|
34
|
+
]
|
30
35
|
end
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Set up gems listed in the Gemfile.
|
2
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("
|
2
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
|
3
3
|
|
4
4
|
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
5
|
-
$LOAD_PATH.unshift File.expand_path("
|
5
|
+
$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
|
data/spec/dummy/config.ru
CHANGED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT sqlite_version(*)[0m
|
2
|
+
[1m[35m (0.1ms)[0m [1m[34mSELECT sqlite_version(*)[0m
|
3
|
+
[1m[35m (0.1ms)[0m [1m[35mDROP TABLE IF EXISTS "roles"[0m
|
4
|
+
[1m[35m (5.0ms)[0m [1m[35mCREATE TABLE "roles" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" integer, "role" varchar, "price_cents" integer)[0m
|
5
|
+
[1m[35m (2.9ms)[0m [1m[35mCREATE INDEX "index_roles_on_user_id" ON "roles" ("user_id")[0m
|
6
|
+
[1m[35m (0.1ms)[0m [1m[35mDROP TABLE IF EXISTS "users"[0m
|
7
|
+
[1m[35m (2.8ms)[0m [1m[35mCREATE TABLE "users" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar, "password" varchar, "age" integer)[0m
|
8
|
+
[1m[35m (2.8ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)[0m
|
9
|
+
[1m[35m (0.1ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
10
|
+
[1m[35m (2.4ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20150607110245)[0m
|
11
|
+
[1m[35m (1.9ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
12
|
+
(20141018081559),
|
13
|
+
(20141018081640);
|
14
|
+
|
15
|
+
[0m
|
16
|
+
[1m[35m (2.4ms)[0m [1m[35mCREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL)[0m
|
17
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.1ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ?[0m [["key", "environment"], ["LIMIT", 1]]
|
18
|
+
[1m[36mTRANSACTION (0.0ms)[0m [1m[36mbegin transaction[0m
|
19
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.1ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?)[0m [["key", "environment"], ["value", "development"], ["created_at", "2021-12-30 16:01:09.444330"], ["updated_at", "2021-12-30 16:01:09.444330"]]
|
20
|
+
[1m[36mTRANSACTION (1.9ms)[0m [1m[36mcommit transaction[0m
|
21
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.1ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ?[0m [["key", "environment"], ["LIMIT", 1]]
|
22
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.1ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ?[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
23
|
+
[1m[36mTRANSACTION (0.0ms)[0m [1m[36mbegin transaction[0m
|
24
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.1ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?)[0m [["key", "schema_sha1"], ["value", "2fb15a187a8db3fd34877067601f82a165001b33"], ["created_at", "2021-12-30 16:01:09.448757"], ["updated_at", "2021-12-30 16:01:09.448757"]]
|
25
|
+
[1m[36mTRANSACTION (1.8ms)[0m [1m[36mcommit transaction[0m
|
26
|
+
[1m[35m (0.1ms)[0m [1m[34mSELECT sqlite_version(*)[0m
|
27
|
+
[1m[35m (0.1ms)[0m [1m[35mDROP TABLE IF EXISTS "roles"[0m
|
28
|
+
[1m[35m (2.5ms)[0m [1m[35mCREATE TABLE "roles" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" integer, "role" varchar, "price_cents" integer)[0m
|
29
|
+
[1m[35m (2.3ms)[0m [1m[35mCREATE INDEX "index_roles_on_user_id" ON "roles" ("user_id")[0m
|
30
|
+
[1m[35m (0.1ms)[0m [1m[35mDROP TABLE IF EXISTS "users"[0m
|
31
|
+
[1m[35m (2.6ms)[0m [1m[35mCREATE TABLE "users" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar, "password" varchar, "age" integer)[0m
|
32
|
+
[1m[35m (2.3ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)[0m
|
33
|
+
[1m[35m (0.1ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
34
|
+
[1m[35m (1.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20150607110245)[0m
|
35
|
+
[1m[35m (1.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
36
|
+
(20141018081559),
|
37
|
+
(20141018081640);
|
38
|
+
|
39
|
+
[0m
|
40
|
+
[1m[35m (2.4ms)[0m [1m[35mCREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL)[0m
|
41
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.1ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ?[0m [["key", "environment"], ["LIMIT", 1]]
|
42
|
+
[1m[36mTRANSACTION (0.0ms)[0m [1m[36mbegin transaction[0m
|
43
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.1ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?)[0m [["key", "environment"], ["value", "development"], ["created_at", "2021-12-30 16:01:09.471093"], ["updated_at", "2021-12-30 16:01:09.471093"]]
|
44
|
+
[1m[36mTRANSACTION (1.7ms)[0m [1m[36mcommit transaction[0m
|
45
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.1ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ?[0m [["key", "environment"], ["LIMIT", 1]]
|
46
|
+
[1m[36mTRANSACTION (0.0ms)[0m [1m[36mbegin transaction[0m
|
47
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.2ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = ?, "updated_at" = ? WHERE "ar_internal_metadata"."key" = ?[0m [["value", "test"], ["updated_at", "2021-12-30 16:01:09.474305"], ["key", "environment"]]
|
48
|
+
[1m[36mTRANSACTION (1.7ms)[0m [1m[36mcommit transaction[0m
|
49
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.1ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ?[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
50
|
+
[1m[36mTRANSACTION (0.0ms)[0m [1m[36mbegin transaction[0m
|
51
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.2ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?)[0m [["key", "schema_sha1"], ["value", "2fb15a187a8db3fd34877067601f82a165001b33"], ["created_at", "2021-12-30 16:01:09.477396"], ["updated_at", "2021-12-30 16:01:09.477396"]]
|
52
|
+
[1m[36mTRANSACTION (1.8ms)[0m [1m[36mcommit transaction[0m
|