bullet_train 1.0.30 → 1.0.31
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/helpers/account/locale_helper.rb +34 -2
- data/lib/bullet_train/resolver.rb +20 -1
- data/lib/bullet_train/version.rb +1 -1
- data/lib/tasks/bullet_train_tasks.rake +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2967f0b80a95786b9a7e0816284db63ed4b149a644b1c050df1904a56df7947f
|
4
|
+
data.tar.gz: 92ac669e6fb6091e32772a8281207b35bb034a4481649971c4682e74486734dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63ade82241aab3d3ca9267e8217ef604bde7f1142b25e63b21d1a95c93b0fa914ec51ee0f869c9b1080500e5b15a79317eefe369c91edd8db81dedf01bd37d46
|
7
|
+
data.tar.gz: c241470aa225ea03179125b2ac640ef34a8958058e2ae5457d3b1ca37de560d05808b15568b6bee2755e5fb6a44ef9b3fcc135b7160e5c77a797e6ccea76c07d
|
@@ -35,11 +35,43 @@ module Account::LocaleHelper
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def t(key, options = {})
|
38
|
+
# When bundled Ruby gems provide a lot of translations, it can be difficult to figure out which strings in the
|
39
|
+
# application are coming from where. To help with this, you can add `?debug=true` to any URL and we'll output
|
40
|
+
# any rendered strings and their translation keys on the console.
|
41
|
+
unless Rails.env.production?
|
42
|
+
if params[:log_locales] || params[:show_locales]
|
43
|
+
# Often times we're only receiving partial keys like `.section`, so this is a crazy hack to trick I18n.t into
|
44
|
+
# telling us what the full key ended up being.
|
45
|
+
begin
|
46
|
+
super(key + "💣", options.except(:default))
|
47
|
+
rescue I18n::MissingTranslationData => exception
|
48
|
+
full_key = exception.message.rpartition(" ").last.gsub("💣", "")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
38
53
|
if account_controller?
|
39
|
-
#
|
54
|
+
# Give preference to the options they've passed in.
|
40
55
|
options = models_locales(@child_object, @parent_object).merge(options)
|
41
56
|
end
|
42
|
-
|
57
|
+
|
58
|
+
result = super(key, options)
|
59
|
+
|
60
|
+
unless Rails.env.production?
|
61
|
+
if params[:log_locales]
|
62
|
+
if result == options[:default]
|
63
|
+
puts "🌐 #{full_key}: Not found? Result matched default: \"#{result}\"".yellow
|
64
|
+
else
|
65
|
+
puts "🌐 #{full_key}: \"#{result}\"".green
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if params[:show_locales]
|
70
|
+
return full_key
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
return result
|
43
75
|
end
|
44
76
|
|
45
77
|
# like 't', but if the key isn't found, it returns nil.
|
@@ -2,6 +2,8 @@ require 'io/wait'
|
|
2
2
|
|
3
3
|
module BulletTrain
|
4
4
|
class Resolver
|
5
|
+
include I18n::Backend::Flatten
|
6
|
+
|
5
7
|
def initialize(needle)
|
6
8
|
@needle = needle
|
7
9
|
end
|
@@ -89,7 +91,7 @@ module BulletTrain
|
|
89
91
|
package_name: nil,
|
90
92
|
}
|
91
93
|
|
92
|
-
result[:absolute_path] = class_path || partial_path || file_path
|
94
|
+
result[:absolute_path] = class_path || partial_path || locale_path || file_path
|
93
95
|
|
94
96
|
if result[:absolute_path]
|
95
97
|
base_path = "bullet_train" + result[:absolute_path].split("/bullet_train").last
|
@@ -144,5 +146,22 @@ module BulletTrain
|
|
144
146
|
# We don't have to do anything here... the absolute path is what we're passed, and we just pass it back.
|
145
147
|
@needle
|
146
148
|
end
|
149
|
+
|
150
|
+
def locale_path
|
151
|
+
# This is a complete list of translation files provided by this app or any linked Bullet Train packages.
|
152
|
+
(["#{Rails.root.to_s}/config/locales"] + `find ./tmp/gems/*`.lines.map(&:strip).map { |link| File.readlink(link) + "/config/locales" }).each do |locale_source|
|
153
|
+
if File.exist?(locale_source)
|
154
|
+
`find -L #{locale_source} | grep ".yml"`.lines.map(&:strip).each do |file_path|
|
155
|
+
yaml = YAML.load_file(file_path, aliases: true)
|
156
|
+
translations = flatten_translations(nil, yaml, nil, false)
|
157
|
+
if translations[@needle.to_sym].present?
|
158
|
+
return file_path
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
return nil
|
165
|
+
end
|
147
166
|
end
|
148
167
|
end
|
data/lib/bullet_train/version.rb
CHANGED