amatsuda-i18n_generators 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
data/History.txt
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
== 0.6.0
|
2
|
+
|
3
|
+
* bugfixes:
|
4
|
+
* Could not load cldr data with short locale names
|
5
|
+
* major enhancements:
|
6
|
+
* Include AR association names in model attributes translation
|
7
|
+
* Add 'generated' comment mark (#g) for generated lines in YAML (thanks to t-wada-senpai, Shimura-san, Toyofuku-san, Sezutsu-san and oukayuka-san!)
|
8
|
+
* Add --include-timestamps option and change default bahaviour not to include timestamp columns in translation YAML
|
9
|
+
* Add blank line between each blocks (thanks to Sawayanagi-san!)
|
10
|
+
* enhancements:
|
11
|
+
* Avoid generating blank locale file
|
12
|
+
* Change GitHub fetch URL from blob/master/...?raw=true to raw/master
|
13
|
+
|
1
14
|
== 0.5.0
|
2
15
|
|
3
16
|
* bugfixes:
|
@@ -4,7 +4,7 @@ require 'rails_generator/commands'
|
|
4
4
|
require 'gettext'
|
5
5
|
|
6
6
|
class I18nGenerator < Rails::Generator::NamedBase
|
7
|
-
attr_reader :locale_name, :cldr, :translator, :generate_translation_only, :generate_locale_only
|
7
|
+
attr_reader :locale_name, :cldr, :translator, :generate_translation_only, :generate_locale_only, :include_timestamps
|
8
8
|
|
9
9
|
def initialize(runtime_args, runtime_options = {})
|
10
10
|
if options[:scaffold]
|
@@ -29,6 +29,7 @@ class I18nGenerator < Rails::Generator::NamedBase
|
|
29
29
|
lang = @locale_name.sub(/-.*$/, '')
|
30
30
|
@translator = Translator.new lang
|
31
31
|
end
|
32
|
+
@include_timestamps = true if options[:include_timestamps]
|
32
33
|
end
|
33
34
|
|
34
35
|
def manifest
|
@@ -59,8 +60,9 @@ class I18nGenerator < Rails::Generator::NamedBase
|
|
59
60
|
opt.separator 'Options:'
|
60
61
|
opt.on('--translation',
|
61
62
|
'Generate translations for all models with their attributes and all translation keys in the view files.') {|v| options[:generate_translation_only] = v}
|
62
|
-
opt.on('--locale',
|
63
|
-
|
63
|
+
opt.on('--locale', 'Generate locale files.') {|v| options[:generate_locale_only] = v}
|
64
|
+
opt.on('--include-timestamps', 'Include timestamp columns in the YAML translation.') {|v| options[:include_timestamps] = v}
|
65
|
+
opt.on('--include-timestamp', 'Include timestamp columns in the YAML translation.') {|v| options[:include_timestamps] = v}
|
64
66
|
end
|
65
67
|
|
66
68
|
private
|
data/generators/i18n/lib/yaml.rb
CHANGED
@@ -52,7 +52,7 @@ module I18nLocaleGeneratorModule
|
|
52
52
|
else
|
53
53
|
%Q["#{self.value}"]
|
54
54
|
end
|
55
|
-
"#{' ' * self.indent_level}#{self.key}: #{v}"
|
55
|
+
"#{' ' * self.indent_level}#{self.key}: #{v} #g" # g is for 'generated'!
|
56
56
|
else
|
57
57
|
@text
|
58
58
|
end
|
@@ -144,8 +144,11 @@ module I18nLocaleGeneratorModule
|
|
144
144
|
@current_line
|
145
145
|
end
|
146
146
|
|
147
|
-
def to_s
|
147
|
+
def to_s(add_blank_line = false)
|
148
|
+
previous_indent_level = 0
|
148
149
|
@lines.inject('') do |ret, n|
|
150
|
+
ret << "\n" if add_blank_line && (n.indent_level < previous_indent_level) && !n.text.blank? && !ret.ends_with?("\n\n")
|
151
|
+
previous_indent_level = n.indent_level
|
149
152
|
ret << n.text + "\n"
|
150
153
|
end
|
151
154
|
end
|
@@ -25,7 +25,7 @@ module I18nGenerator::Generator
|
|
25
25
|
|
26
26
|
def fetch_from_rails_i18n_repository
|
27
27
|
file('i18n:base.yml', "config/locales/#{locale_name}.yml") do |f|
|
28
|
-
OpenURI.open_uri("http://github.com/svenfuchs/rails-i18n/
|
28
|
+
OpenURI.open_uri("http://github.com/svenfuchs/rails-i18n/raw/master/rails/locale/#{locale_name}.yml").read
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -98,9 +98,10 @@ module I18nLocaleGeneratorModule
|
|
98
98
|
|
99
99
|
private
|
100
100
|
def summaries
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
returning [load_cldr_data(@locale_name.tr('-', '_'))] do |s|
|
102
|
+
if @locale_name =~ /^[a-zA-Z]{2}[-_][a-zA-Z]{2}$/
|
103
|
+
s << load_cldr_data(@locale_name.to(1))
|
104
|
+
end
|
104
105
|
end
|
105
106
|
end
|
106
107
|
memoize :summaries
|
@@ -24,7 +24,9 @@ module I18nGenerator::Generator
|
|
24
24
|
translation_keys = []
|
25
25
|
translation_keys += models.map {|m| "activerecord.models.#{m.english_name}"}
|
26
26
|
models.each do |model|
|
27
|
-
|
27
|
+
cols = model.content_columns + model.reflect_on_all_associations
|
28
|
+
cols.delete_if {|c| %w[created_at updated_at].include? c.name} unless self.include_timestamps
|
29
|
+
translation_keys += cols.map {|c| "activerecord.attributes.#{model.english_name}.#{c.name}"}
|
28
30
|
end
|
29
31
|
logger.debug "#{models.size} models found."
|
30
32
|
|
@@ -39,13 +41,17 @@ module I18nGenerator::Generator
|
|
39
41
|
(translation_keys += I18n.backend.keys).uniq!
|
40
42
|
I18n.backend = original_backend
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
if translation_keys.blank?
|
45
|
+
logger.info "No translation keys found. Skipped generating translation_#{locale_name}.yml file."
|
46
|
+
else
|
47
|
+
# translate all keys and generate the YAML file
|
48
|
+
now = Time.now
|
49
|
+
translations = translate_all(translation_keys)
|
50
|
+
logger.debug "took #{Time.now - now} secs to translate."
|
46
51
|
|
47
|
-
|
48
|
-
|
52
|
+
yaml = generate_yaml(locale_name, translations)
|
53
|
+
template 'i18n:translation.yml', "config/locales/translation_#{locale_name}.yml", :assigns => {:locale_name => locale_name, :translations => yaml.to_s(true)}
|
54
|
+
end
|
49
55
|
end
|
50
56
|
|
51
57
|
private
|
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.
|
4
|
+
version: 0.6.0
|
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: 2009-
|
12
|
+
date: 2009-03-18 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|