i18n_generators 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/History.txt +6 -0
  2. data/README.rdoc +8 -11
  3. data/Rakefile +8 -0
  4. data/i18n_generators.gemspec +4 -0
  5. data/lib/generators/i18n/i18n_generator.rb +2 -2
  6. data/lib/generators/i18n_translation/i18n_translation_generator.rb +69 -41
  7. data/lib/generators/i18n_translation/lib/yaml.rb +4 -4
  8. data/lib/i18n_generators/version.rb +1 -1
  9. data/spec/i18n_locale_command_spec.rb +34 -26
  10. data/spec/i18n_translation_command_spec.rb +6 -10
  11. data/spec/spec_helper.rb +6 -1
  12. data/spec/translator_spec.rb +11 -18
  13. data/spec/yaml_spec.rb +5 -4
  14. metadata +49 -35
  15. data/generators/i18n/USAGE +0 -11
  16. data/generators/i18n/i18n_generator.rb +0 -88
  17. data/generators/i18n/lib/yaml.rb +0 -187
  18. data/generators/i18n/templates/base.yml +0 -0
  19. data/generators/i18n/templates/i18n_config.rb +0 -4
  20. data/generators/i18n/templates/translation.yml +0 -1
  21. data/generators/i18n_locale/USAGE +0 -10
  22. data/generators/i18n_locale/i18n_locale_command.rb +0 -141
  23. data/generators/i18n_locale/i18n_locale_generator.rb +0 -8
  24. data/generators/i18n_locale/lib/cldr.rb +0 -138
  25. data/generators/i18n_scaffold/i18n_scaffold_generator.rb +0 -2
  26. data/generators/i18n_scaffold/templates/controller.rb +0 -85
  27. data/generators/i18n_scaffold/templates/functional_test.rb +0 -45
  28. data/generators/i18n_scaffold/templates/helper.rb +0 -2
  29. data/generators/i18n_scaffold/templates/helper_test.rb +0 -4
  30. data/generators/i18n_scaffold/templates/layout.html.erb +0 -17
  31. data/generators/i18n_scaffold/templates/style.css +0 -54
  32. data/generators/i18n_scaffold/templates/view_edit.html.erb +0 -18
  33. data/generators/i18n_scaffold/templates/view_index.html.erb +0 -24
  34. data/generators/i18n_scaffold/templates/view_new.html.erb +0 -17
  35. data/generators/i18n_scaffold/templates/view_show.html.erb +0 -10
  36. data/generators/i18n_translation/USAGE +0 -8
  37. data/generators/i18n_translation/i18n_translation_command.rb +0 -124
  38. data/generators/i18n_translation/i18n_translation_generator.rb +0 -8
  39. data/generators/i18n_translation/lib/erb_executer.rb +0 -30
  40. data/generators/i18n_translation/lib/recording_backend.rb +0 -15
  41. data/generators/i18n_translation/lib/through_ryoku.rb +0 -7
  42. data/generators/i18n_translation/lib/translator.rb +0 -27
  43. data/spec/cldr_spec.rb +0 -54
data/spec/yaml_spec.rb CHANGED
@@ -1,5 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
- require File.join(File.dirname(__FILE__), '../lib/generators/i18n_translation/lib/yaml')
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+ require 'generators/i18n_translation/lib/yaml'
3
4
 
4
5
  describe I27r::YamlDocument do
5
6
  context 'when loading an existing file' do
@@ -68,7 +69,7 @@ ja:
68
69
  numbers:
69
70
  one: "いち" #g
70
71
  two: "に"
71
- three: "さん" #g
72
+ three: さん #g
72
73
 
73
74
  aaa:
74
75
  foo: "ふー"
@@ -82,12 +83,12 @@ YAML
82
83
  subject { @yaml['ja', 'aho', 'hage'] }
83
84
  it { should == 'hige' }
84
85
  end
85
-
86
86
  end
87
87
  end
88
88
 
89
89
  context 'when loading an existing file with alias' do
90
90
  before do
91
+ pending
91
92
  @yaml_string = <<YAML
92
93
  ja:
93
94
  activerecord:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-11 00:00:00.000000000 Z
12
+ date: 2012-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
16
- requirement: &70329611412400 !ruby/object:Gem::Requirement
16
+ requirement: &2164523840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,51 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70329611412400
24
+ version_requirements: *2164523840
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &2164538720 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2164538720
36
+ - !ruby/object:Gem::Dependency
37
+ name: rails
38
+ requirement: &2164538120 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2164538120
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &2164537160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2164537160
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &2164536700 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2164536700
25
69
  description: A Rails generator plugin & gem that generates Rails I18n locale files
26
70
  for almost every known locale.
27
71
  email:
@@ -37,34 +81,6 @@ files:
37
81
  - MIT-LICENSE
38
82
  - README.rdoc
39
83
  - Rakefile
40
- - generators/i18n/USAGE
41
- - generators/i18n/i18n_generator.rb
42
- - generators/i18n/lib/yaml.rb
43
- - generators/i18n/templates/base.yml
44
- - generators/i18n/templates/i18n_config.rb
45
- - generators/i18n/templates/translation.yml
46
- - generators/i18n_locale/USAGE
47
- - generators/i18n_locale/i18n_locale_command.rb
48
- - generators/i18n_locale/i18n_locale_generator.rb
49
- - generators/i18n_locale/lib/cldr.rb
50
- - generators/i18n_scaffold/i18n_scaffold_generator.rb
51
- - generators/i18n_scaffold/templates/controller.rb
52
- - generators/i18n_scaffold/templates/functional_test.rb
53
- - generators/i18n_scaffold/templates/helper.rb
54
- - generators/i18n_scaffold/templates/helper_test.rb
55
- - generators/i18n_scaffold/templates/layout.html.erb
56
- - generators/i18n_scaffold/templates/style.css
57
- - generators/i18n_scaffold/templates/view_edit.html.erb
58
- - generators/i18n_scaffold/templates/view_index.html.erb
59
- - generators/i18n_scaffold/templates/view_new.html.erb
60
- - generators/i18n_scaffold/templates/view_show.html.erb
61
- - generators/i18n_translation/USAGE
62
- - generators/i18n_translation/i18n_translation_command.rb
63
- - generators/i18n_translation/i18n_translation_generator.rb
64
- - generators/i18n_translation/lib/erb_executer.rb
65
- - generators/i18n_translation/lib/recording_backend.rb
66
- - generators/i18n_translation/lib/through_ryoku.rb
67
- - generators/i18n_translation/lib/translator.rb
68
84
  - i18n_generators.gemspec
69
85
  - lib/generators/i18n/USAGE
70
86
  - lib/generators/i18n/i18n_generator.rb
@@ -76,7 +92,6 @@ files:
76
92
  - lib/generators/i18n_translation/lib/yaml.rb
77
93
  - lib/generators/i18n_translation/lib/yaml_waml.rb
78
94
  - lib/i18n_generators/version.rb
79
- - spec/cldr_spec.rb
80
95
  - spec/data/cldr/ja.html
81
96
  - spec/data/yml/active_record/en-US.yml
82
97
  - spec/i18n_locale_command_spec.rb
@@ -105,12 +120,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
120
  version: '0'
106
121
  requirements: []
107
122
  rubyforge_project: i18n_generators
108
- rubygems_version: 1.8.10
123
+ rubygems_version: 1.8.17
109
124
  signing_key:
110
125
  specification_version: 3
111
126
  summary: Generates I18n locale files for Rails 3 and Rails 2
112
127
  test_files:
113
- - spec/cldr_spec.rb
114
128
  - spec/data/cldr/ja.html
115
129
  - spec/data/yml/active_record/en-US.yml
116
130
  - spec/i18n_locale_command_spec.rb
@@ -1,11 +0,0 @@
1
- Description:
2
- Generates a config file and locale files and a model/attributes translation file for Rails 2.x i18n.
3
-
4
- Example:
5
- ./script/generate i18n locale_name (ja, de-AT, etc.)
6
-
7
- This will create:
8
- config/locales/ja.yml
9
- config/locales/translation_ja.yml
10
- And update:
11
- config/environment.rb
@@ -1,88 +0,0 @@
1
- require 'net/https'
2
- require 'rubygems'
3
- require 'rails_generator'
4
- require 'rails_generator/commands'
5
-
6
- class I18nGenerator < Rails::Generator::NamedBase
7
- attr_reader :locale_name, :cldr, :translator, :generate_translation_only, :generate_locale_only, :include_timestamps
8
-
9
- def initialize(runtime_args, runtime_options = {})
10
- if options[:scaffold]
11
- #TODO invoke scaffold generator
12
- puts 'please use generate i18n_scaffold command'
13
- exit
14
- end
15
-
16
- super
17
- unless name =~ /^[a-zA-Z]{2}([-_][a-zA-Z]{2})?$/
18
- puts 'ERROR: Wrong locale format. Please input in ?? or ??-?? format.'
19
- exit
20
- end
21
- @locale_name = name.length == 5 ? "#{name[0..1].downcase}-#{name[3..4].upcase}" : "#{name[0..1].downcase}"
22
-
23
- unless options[:generate_translation_only]
24
- gem 'gettext', '<2'
25
- require 'gettext'
26
- @cldr = CldrDocument.new @locale_name
27
- GetText.bindtextdomain 'rails'
28
- GetText.locale = @locale_name
29
- end
30
- unless options[:generate_locale_only]
31
- lang = @locale_name.sub(/-.*$/, '')
32
- @translator = Translator.new lang
33
- end
34
- @include_timestamps = true if options[:include_timestamps]
35
- end
36
-
37
- def manifest
38
- record do |m|
39
- m.directory 'config/locales'
40
- unless options[:generate_translation_only]
41
- logger.debug 'updating environment.rb ...'
42
- m.generate_configuration
43
- if defined_in_rails_i18n_repository?
44
- logger.debug "fetching #{locale_name}.yml from rails-i18n repository..."
45
- m.fetch_from_rails_i18n_repository
46
- else
47
- logger.debug "generating #{locale_name} YAML files for Rails..."
48
- m.active_support_yaml
49
- m.active_record_yaml
50
- m.action_view_yaml
51
- end
52
- end
53
- unless options[:generate_locale_only]
54
- m.translation_yaml
55
- end
56
- end
57
- end
58
-
59
- protected
60
- def add_options!(opt)
61
- opt.separator ''
62
- opt.separator 'Options:'
63
- opt.on('--translation',
64
- 'Generate translations for all models with their attributes and all translation keys in the view files.') {|v| options[:generate_translation_only] = v}
65
- opt.on('--locale', 'Generate locale files.') {|v| options[:generate_locale_only] = v}
66
- opt.on('--include-timestamps', 'Include timestamp columns in the YAML translation.') {|v| options[:include_timestamps] = v}
67
- opt.on('--include-timestamp', 'Include timestamp columns in the YAML translation.') {|v| options[:include_timestamps] = v}
68
- end
69
-
70
- private
71
- def defined_in_rails_i18n_repository?
72
- begin
73
- uri = URI.parse "https://github.com/svenfuchs/rails-i18n/raw/master/rails/locale/#{locale_name}.yml"
74
- http = Net::HTTP.new uri.host, uri.port
75
- http.use_ssl = true
76
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
77
- req = Net::HTTP::Get.new uri.request_uri
78
- res = http.request req
79
- res.code == '200'
80
- rescue
81
- false
82
- end
83
- end
84
- end
85
-
86
- require File.join(File.dirname(__FILE__), '../i18n_locale/i18n_locale_command')
87
- require File.join(File.dirname(__FILE__), '../i18n_translation/i18n_translation_command')
88
- Rails::Generator::Commands::Create.send :include, I18nGenerator::Generator::Commands::Create
@@ -1,187 +0,0 @@
1
- require 'yaml'
2
-
3
- module I18nLocaleGeneratorModule
4
- class Node
5
- attr_reader :document, :indent_level
6
- attr_accessor :line
7
-
8
- def initialize(parent, line_index, text)
9
- @document, @line, @text = parent.document, line_index, text.to_s
10
- @text =~ /(^\s*)/
11
- @indent_level = $1.nil? ? 0 : $1.size
12
- @yaml = YAML.load(@text.to_s + ' ')
13
- end
14
-
15
- def parent
16
- @parent ||= document.parent_of self
17
- end
18
-
19
- def children
20
- @children ||= document.children_of(self)
21
- end
22
- alias :nodes :children
23
-
24
- def [](node_name)
25
- if node = nodes.detect {|n| n.key.to_s == node_name.to_s}
26
- node
27
- else
28
- nodes.add "#{' ' * (@indent_level + 2)}#{node_name}: "
29
- nodes.last
30
- end
31
- end
32
-
33
- def key
34
- @yaml.is_a?(Hash) ? @yaml.keys.first : nil
35
- end
36
-
37
- def value
38
- @yaml.is_a?(Hash) ? @yaml.values.first : nil
39
- end
40
-
41
- def value=(val)
42
- if @yaml[self.key] != val
43
- @yaml[self.key] = val
44
- @changed = true
45
- end
46
- end
47
-
48
- def text
49
- if @changed
50
- v = if self.value.is_a?(Array)
51
- "[#{self.value * ', '}]"
52
- else
53
- %Q["#{self.value}"]
54
- end
55
- "#{' ' * self.indent_level}#{self.key}: #{v} #g" # g is for 'generated'!
56
- else
57
- @text
58
- end
59
- end
60
- alias :to_s :text
61
-
62
- def changed?
63
- @changed
64
- end
65
-
66
- def is_blank_or_comment?
67
- @text.sub(/#.*$/, '').gsub(/\s/, '').empty?
68
- end
69
-
70
- def path
71
- @path ||= "#{self.parent.path}/#{self.key}"
72
- end
73
-
74
- def descendant_nodes(&block)
75
- yield self if self.value
76
- self.children.each {|child| child.descendant_nodes(&block)} if self.children
77
- end
78
-
79
- def <=>(other)
80
- self.line <=> other.line
81
- end
82
- end
83
-
84
- class YamlDocument < Node
85
- attr_accessor :lines
86
- alias :nodes :lines
87
-
88
- def initialize(yml_path, locale_name)
89
- @locale_name, @lines, @current_line, @indent_level = locale_name, Nodes.new(self), -1, -2
90
- if File.exists? yml_path
91
- File.open(yml_path) do |file|
92
- file.each_with_index do |line_text, i|
93
- n = Node.new(self, i, line_text.chomp)
94
- @lines << ((((n.key == 'en-US') || (n.key == 'en')) && n.value.blank?) ? Node.new(self, i, "#{locale_name}:") : n)
95
- end
96
- @lines.delete_at(-1) if @lines[-1].text.blank?
97
- end
98
- end
99
- end
100
-
101
- def next
102
- return false if @lines.size == 0
103
- @current_line += 1
104
- return false if @current_line >= @lines.size
105
- @lines[@current_line].is_blank_or_comment? ? self.next : @lines[@current_line]
106
- end
107
-
108
- def prev
109
- return false if @current_line == 0
110
- @current_line -= 1
111
- @lines[@current_line].is_blank_or_comment? ? self.prev : @lines[@current_line]
112
- end
113
-
114
- def parent_of(child)
115
- @current_line = child.line
116
- while n = self.prev
117
- return n if n.indent_level == child.indent_level - 2
118
- end
119
- self
120
- end
121
-
122
- def children_of(parent)
123
- nodes = Nodes.new(parent)
124
- @current_line = parent.line
125
- while n = self.next
126
- if n.indent_level < parent.indent_level + 2
127
- break
128
- elsif n.indent_level == parent.indent_level + 2
129
- nodes << n
130
- end
131
- end
132
- nodes
133
- end
134
-
135
- def document
136
- self
137
- end
138
-
139
- def path
140
- ''
141
- end
142
-
143
- def line
144
- @current_line
145
- end
146
-
147
- def to_s(add_blank_line = false)
148
- previous_indent_level = 0
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
152
- ret << (n.text ? n.text.rstrip : '') + "\n"
153
- end
154
- end
155
- end
156
-
157
- class Nodes < Array
158
- def initialize(parent)
159
- super()
160
- @parent = parent
161
- end
162
-
163
- def [](index)
164
- if index.is_a?(String) || index.is_a?(Symbol)
165
- return self.detect {|node| node.key == index} || add(index)
166
- end
167
- super
168
- end
169
-
170
- def last_leaf
171
- c = @parent
172
- loop do
173
- return c if c.children.blank?
174
- c = c.children.last
175
- end
176
- end
177
-
178
- def add(node_name)
179
- target_line = self.last_leaf.line + 1
180
- @parent.document.nodes.each {|n| n.line += 1 if n.line >= target_line}
181
- node = Node.new(@parent, target_line, node_name)
182
- @parent.document.lines << node
183
- @parent.document.lines.sort!
184
- self << node unless @parent.is_a? YamlDocument
185
- end
186
- end
187
- end