amatsuda-i18n_generators 0.3.0 → 0.3.1
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.
@@ -10,6 +10,8 @@ module I18nGenerator::Generator
|
|
10
10
|
module Create
|
11
11
|
def translation_yaml
|
12
12
|
I18n.locale = locale_name
|
13
|
+
threads = []
|
14
|
+
now = Time.now
|
13
15
|
models = model_filenames.map do |model_name|
|
14
16
|
model = begin
|
15
17
|
m = model_name.camelize.constantize
|
@@ -18,28 +20,33 @@ module I18nGenerator::Generator
|
|
18
20
|
rescue
|
19
21
|
next
|
20
22
|
end
|
21
|
-
|
23
|
+
threads << Thread.new do
|
24
|
+
Thread.pass
|
25
|
+
registered_t_name = I18n.t("activerecord.models.#{model_name}", :default => model_name, :locale => locale_name)
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
model.class_eval <<-END
|
28
|
+
def self.english_name
|
29
|
+
"#{model_name}"
|
30
|
+
end
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
END
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
END
|
32
|
+
def self.translated_name
|
33
|
+
"#{registered_t_name != model_name ? registered_t_name : self.translator.translate(model_name)}"
|
34
|
+
end
|
35
|
+
END
|
36
|
+
model.content_columns.each do |col|
|
37
|
+
next if %w[created_at updated_at].include? col.name
|
38
|
+
registered_t_name = I18n.t("activerecord.attributes.#{model_name}.#{col.name}", :default => col.name, :locale => locale_name)
|
39
|
+
col.class_eval <<-END
|
40
|
+
def translated_name
|
41
|
+
"#{registered_t_name != col.name ? registered_t_name : self.translator.translate(col.name)}"
|
42
|
+
end
|
43
|
+
END
|
44
|
+
end
|
40
45
|
end
|
41
46
|
model
|
42
47
|
end.compact
|
48
|
+
threads.each {|t| t.join}
|
49
|
+
logger.debug "took #{Time.now - now} secs to translate #{models.count} models."
|
43
50
|
# pick all translated keywords from view files
|
44
51
|
I18n.backend = RecordingBackend.new
|
45
52
|
|
@@ -49,7 +56,10 @@ END
|
|
49
56
|
keys_in_view = I18n.backend.keys
|
50
57
|
keys_in_view -= models.map {|m| m.english_name.to_sym}
|
51
58
|
keys_in_view -= models.inject([]) {|a, m| a + m.content_columns.map {|c| "#{m.english_name}.#{c.name}".to_sym}}
|
52
|
-
|
59
|
+
now = Time.now
|
60
|
+
translated_hash = translate_all keys_in_view
|
61
|
+
logger.debug "took #{Time.now - now} secs to translate #{keys_in_view.count} words."
|
62
|
+
generate_yaml(locale_name, models, translated_hash)
|
53
63
|
end
|
54
64
|
|
55
65
|
private
|
@@ -62,6 +72,20 @@ END
|
|
62
72
|
def generate_yaml(locale_name, models, translations)
|
63
73
|
template 'i18n:translation.yml', "config/locales/translation_#{locale_name}.yml", :assigns => {:locale_name => locale_name, :models => models, :translations => translations}
|
64
74
|
end
|
75
|
+
|
76
|
+
# receives an array of keys and returns :key => :translation hash
|
77
|
+
def translate_all(keys)
|
78
|
+
threads = []
|
79
|
+
ret = keys.inject({}) do |hash, key|
|
80
|
+
threads << Thread.new do
|
81
|
+
Thread.pass
|
82
|
+
hash[key] = translator.translate key
|
83
|
+
end
|
84
|
+
hash
|
85
|
+
end
|
86
|
+
threads.each {|t| t.join}
|
87
|
+
ret
|
88
|
+
end
|
65
89
|
end
|
66
90
|
end
|
67
91
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amatsuda-i18n_generators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-08 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|