i18n-generators 1.1.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.
Files changed (54) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +3 -0
  3. data/History.txt +143 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +74 -0
  6. data/Rakefile +2 -0
  7. data/generators/i18n/USAGE +11 -0
  8. data/generators/i18n/i18n_generator.rb +88 -0
  9. data/generators/i18n/lib/yaml.rb +187 -0
  10. data/generators/i18n/templates/base.yml +0 -0
  11. data/generators/i18n/templates/i18n_config.rb +4 -0
  12. data/generators/i18n/templates/translation.yml +1 -0
  13. data/generators/i18n_locale/USAGE +10 -0
  14. data/generators/i18n_locale/i18n_locale_command.rb +141 -0
  15. data/generators/i18n_locale/i18n_locale_generator.rb +8 -0
  16. data/generators/i18n_locale/lib/cldr.rb +138 -0
  17. data/generators/i18n_scaffold/i18n_scaffold_generator.rb +2 -0
  18. data/generators/i18n_scaffold/templates/controller.rb +85 -0
  19. data/generators/i18n_scaffold/templates/functional_test.rb +45 -0
  20. data/generators/i18n_scaffold/templates/helper.rb +2 -0
  21. data/generators/i18n_scaffold/templates/helper_test.rb +4 -0
  22. data/generators/i18n_scaffold/templates/layout.html.erb +17 -0
  23. data/generators/i18n_scaffold/templates/style.css +54 -0
  24. data/generators/i18n_scaffold/templates/view_edit.html.erb +18 -0
  25. data/generators/i18n_scaffold/templates/view_index.html.erb +24 -0
  26. data/generators/i18n_scaffold/templates/view_new.html.erb +17 -0
  27. data/generators/i18n_scaffold/templates/view_show.html.erb +10 -0
  28. data/generators/i18n_translation/USAGE +8 -0
  29. data/generators/i18n_translation/i18n_translation_command.rb +124 -0
  30. data/generators/i18n_translation/i18n_translation_generator.rb +8 -0
  31. data/generators/i18n_translation/lib/erb_executer.rb +30 -0
  32. data/generators/i18n_translation/lib/recording_backend.rb +15 -0
  33. data/generators/i18n_translation/lib/through_ryoku.rb +7 -0
  34. data/generators/i18n_translation/lib/translator.rb +27 -0
  35. data/i18n-generators.gemspec +26 -0
  36. data/lib/generators/i18n/all/USAGE +12 -0
  37. data/lib/generators/i18n/all/i18n_generator.rb +19 -0
  38. data/lib/generators/i18n/locale/USAGE +10 -0
  39. data/lib/generators/i18n/locale/locale_generator.rb +49 -0
  40. data/lib/generators/i18n/translation/USAGE +8 -0
  41. data/lib/generators/i18n/translation/lib/translator.rb +59 -0
  42. data/lib/generators/i18n/translation/lib/yaml.rb +137 -0
  43. data/lib/generators/i18n/translation/lib/yaml_waml.rb +35 -0
  44. data/lib/generators/i18n/translation/translation_generator.rb +108 -0
  45. data/lib/i18n_generators/version.rb +3 -0
  46. data/spec/cldr_spec.rb +54 -0
  47. data/spec/data/cldr/ja.html +3112 -0
  48. data/spec/data/yml/active_record/en-US.yml +54 -0
  49. data/spec/i18n_locale_command_spec.rb +63 -0
  50. data/spec/i18n_translation_command_spec.rb +24 -0
  51. data/spec/spec_helper.rb +10 -0
  52. data/spec/translator_spec.rb +46 -0
  53. data/spec/yaml_spec.rb +123 -0
  54. metadata +122 -0
@@ -0,0 +1,54 @@
1
+ en-US:
2
+ activerecord:
3
+ errors:
4
+ # The values :model, :attribute and :value are always available for interpolation
5
+ # The value :count is available when applicable. Can be used for pluralization.
6
+ messages:
7
+ inclusion: "is not included in the list"
8
+ exclusion: "is reserved"
9
+ invalid: "is invalid"
10
+ confirmation: "doesn't match confirmation"
11
+ accepted: "must be accepted"
12
+ empty: "can't be empty"
13
+ blank: "can't be blank"
14
+ too_long: "is too long (maximum is {{count}} characters)"
15
+ too_short: "is too short (minimum is {{count}} characters)"
16
+ wrong_length: "is the wrong length (should be {{count}} characters)"
17
+ taken: "has already been taken"
18
+ not_a_number: "is not a number"
19
+ greater_than: "must be greater than {{count}}"
20
+ greater_than_or_equal_to: "must be greater than or equal to {{count}}"
21
+ equal_to: "must be equal to {{count}}"
22
+ less_than: "must be less than {{count}}"
23
+ less_than_or_equal_to: "must be less than or equal to {{count}}"
24
+ odd: "must be odd"
25
+ even: "must be even"
26
+ # Append your own errors here or at the model/attributes scope.
27
+
28
+ # You can define own errors for models or model attributes.
29
+ # The values :model, :attribute and :value are always available for interpolation.
30
+ #
31
+ # For example,
32
+ # models:
33
+ # user:
34
+ # blank: "This is a custom blank message for {{model}}: {{attribute}}"
35
+ # attributes:
36
+ # login:
37
+ # blank: "This is a custom blank message for User login"
38
+ # Will define custom blank validation message for User model and
39
+ # custom blank validation message for login attribute of User model.
40
+ models:
41
+
42
+ # Translate model names. Used in Model.human_name().
43
+ #models:
44
+ # For example,
45
+ # user: "Dude"
46
+ # will translate User model name to "Dude"
47
+
48
+ # Translate model attribute names. Used in Model.human_attribute_name(attribute).
49
+ #attributes:
50
+ # For example,
51
+ # user:
52
+ # login: "Handle"
53
+ # will translate User attribute "login" as "Handle"
54
+
@@ -0,0 +1,63 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+ require File.join(File.dirname(__FILE__), '/../generators/i18n_locale/i18n_locale_command')
3
+
4
+ describe I18nGenerator::Generator::Commands::Create do
5
+ before do
6
+ (@command = Object.new).extend I18nGenerator::Generator::Commands::Create
7
+ @command.stub!(:locale_name).and_return('ja')
8
+ end
9
+
10
+ describe 'add_locale_config' do
11
+ describe 'when i18n.default_locale is configured in environment.rb' do
12
+ before do
13
+ @config = "
14
+ Rails::Initializer.run do |config|
15
+ config.i18n.default_locale = :de
16
+ end"
17
+ end
18
+
19
+ it 'rewrites the existing default_locale to locale_name value' do
20
+ @command.send(:add_locale_config, @config).should == "
21
+ Rails::Initializer.run do |config|
22
+ config.i18n.default_locale = 'ja'
23
+ end"
24
+ end
25
+ end
26
+
27
+ describe 'when i18n.default_locale config is commented in environment.rb' do
28
+ before do
29
+ @config = "
30
+ Rails::Initializer.run do |config|
31
+ # config.i18n.default_locale = :de
32
+ end"
33
+ end
34
+
35
+ it 'uncomments the existing commented i18n config and sets locale_name value' do
36
+ @command.send(:add_locale_config, @config).should == "
37
+ Rails::Initializer.run do |config|
38
+ config.i18n.default_locale = 'ja'
39
+ end"
40
+ end
41
+ end
42
+
43
+ describe 'when i18n.default_locale is not written in environment.rb' do
44
+ before do
45
+ @config = "
46
+ Rails::Initializer.run do |config|
47
+ something goes here.
48
+ bla bla bla...
49
+ end"
50
+ end
51
+
52
+ it 'adds the default_locale config inside the config block and sets locale_name value' do
53
+ @command.send(:add_locale_config, @config).should == "
54
+ Rails::Initializer.run do |config|
55
+ config.i18n.default_locale = 'ja'
56
+ something goes here.
57
+ bla bla bla...
58
+ end"
59
+ end
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,24 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+ require File.join(File.dirname(__FILE__), '/../generators/i18n_translation/i18n_translation_command')
3
+
4
+ describe I18nGenerator::Generator::Commands::Create do
5
+ before do
6
+ (@command = Object.new).extend I18nGenerator::Generator::Commands::Create
7
+ @command.stub!(:locale_name).and_return('ja')
8
+ end
9
+
10
+ describe 'each_value' do
11
+ it 'iterates through each value' do
12
+ hash = ActiveSupport::OrderedHash.new
13
+ hash[:parent1] = ActiveSupport::OrderedHash.new
14
+ hash[:parent1][:child1] = 'child one'
15
+ hash[:parent2] = ActiveSupport::OrderedHash.new
16
+ hash[:parent2][:child2] = 'child two'
17
+ hash[:parent2][:child3] = 'child three'
18
+ @command.__send__(:each_value, [], hash) do |parents, value|
19
+ p "#{parents.join('.')} #{value}"
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,10 @@
1
+ require 'active_support/all'
2
+
3
+ # Requires supporting files with custom matchers and macros, etc,
4
+ # in ./support/ and its subdirectories.
5
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
6
+
7
+ RSpec.configure do |config|
8
+ # config.mock_with :rr
9
+ config.mock_with :rspec
10
+ end
@@ -0,0 +1,46 @@
1
+ $KCODE = 'U'
2
+
3
+ require File.join(File.dirname(__FILE__), 'spec_helper')
4
+ require File.join(File.dirname(__FILE__), '../generators/i18n_translation/lib/translator')
5
+ include I18nTranslationGeneratorModule
6
+
7
+ describe Translator do
8
+ before(:each) do
9
+ @translator = Translator.new 'ja'
10
+ end
11
+
12
+ describe 'when successfully translated' do
13
+ before do
14
+ res_200 = mock('res_200')
15
+ res_200.stub!(:read).and_return('{"responseData": {"translatedText":"こんにちは"}, "responseDetails": null, "responseStatus": 200}')
16
+ OpenURI.stub!(:open_uri).and_return(res_200)
17
+ end
18
+
19
+ it 'returns translated text' do
20
+ @translator.translate('hello').should == 'こんにちは'
21
+ end
22
+ end
23
+
24
+ describe 'when translation failed with error code' do
25
+ before do
26
+ res_500 = mock('res_500')
27
+ res_500.stub!(:read).and_return('{"responseData": {"translatedText":"こんにちは?"}, "responseDetails": null, "responseStatus": 500}')
28
+ OpenURI.stub!(:open_uri).and_return(res_500)
29
+ end
30
+
31
+ it 'returns the original text' do
32
+ @translator.translate('hello').should == 'hello'
33
+ end
34
+ end
35
+
36
+ describe 'when translation raised an error' do
37
+ before do
38
+ OpenURI.stub!(:open_uri).and_raise('ERROR!')
39
+ end
40
+
41
+ it 'returns the original text' do
42
+ @translator.translate('hello').should == 'hello'
43
+ end
44
+ end
45
+ end
46
+
data/spec/yaml_spec.rb ADDED
@@ -0,0 +1,123 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+ require File.join(File.dirname(__FILE__), '../lib/generators/i18n_translation/lib/yaml')
3
+
4
+ describe I27r::YamlDocument do
5
+ context 'when loading an existing file' do
6
+ before do
7
+ @yaml_string = <<YAML
8
+ ja:
9
+ hoge:
10
+ fuga: piyo #g
11
+ numbers:
12
+ one: "いち" #g
13
+ two: "に"
14
+
15
+ aaa:
16
+ foo: "ふー"
17
+ bar: "ばー"
18
+ YAML
19
+ @yaml = I27r::YamlDocument.new @yaml_string
20
+ end
21
+
22
+ subject { @yaml }
23
+ it { should be }
24
+
25
+ its(:to_s) { should == @yaml_string }
26
+
27
+ describe '[]' do
28
+ specify '[]' do
29
+ @yaml['ja', 'hoge', 'fuga'].should == 'piyo'
30
+ @yaml[['ja', 'hoge', 'fuga']].should == 'piyo'
31
+ end
32
+ end
33
+
34
+ describe 'find_line_by_path' do
35
+ subject { @yaml.find_line_by_path(['ja', 'hoge', 'fuga']) }
36
+ its(:value) { should == 'piyo' }
37
+ end
38
+
39
+ describe 'find_line_by_path' do
40
+ subject { @yaml.find_line_by_path(['ja', 'aho', 'hage'], -1, true) }
41
+ it { should be }
42
+ its(:key) { should == 'hage' }
43
+ its(:value) { should_not be }
44
+ end
45
+
46
+ describe '[]=' do
47
+ context 'rewriting an existing value' do
48
+ before { @yaml['ja', 'hoge', 'fuga'] = 'puyo' }
49
+ subject { @yaml['ja', 'hoge', 'fuga'] }
50
+ it { should == 'puyo' }
51
+ end
52
+
53
+ context 'an existing value without #g mark' do
54
+ before { @yaml['ja', 'hoge', 'numbers', 'two'] = 'ツー' }
55
+ subject { @yaml['ja', 'hoge', 'numbers', 'two'] }
56
+ it { should == 'に' }
57
+ end
58
+
59
+ context 'creating a new node in the middle' do
60
+ before { @yaml['ja', 'hoge', 'numbers', 'three'] = 'さん' }
61
+ subject { @yaml['ja', 'hoge', 'numbers', 'three'] }
62
+ it { should == 'さん' }
63
+ specify do
64
+ @yaml.to_s.should == <<YAML
65
+ ja:
66
+ hoge:
67
+ fuga: piyo #g
68
+ numbers:
69
+ one: "いち" #g
70
+ two: "に"
71
+ three: "さん" #g
72
+
73
+ aaa:
74
+ foo: "ふー"
75
+ bar: "ばー"
76
+ YAML
77
+ end
78
+ end
79
+
80
+ context 'creating a new node at the bottom' do
81
+ before { @yaml['ja', 'aho', 'hage'] = 'hige' }
82
+ subject { @yaml['ja', 'aho', 'hage'] }
83
+ it { should == 'hige' }
84
+ end
85
+
86
+ end
87
+ end
88
+
89
+ context 'when loading an existing file with alias' do
90
+ before do
91
+ @yaml_string = <<YAML
92
+ ja:
93
+ activerecord:
94
+ attributes:
95
+ hoge: &hoge
96
+ foo: FOO
97
+ bar: BAR
98
+ hoge2: &hoge2
99
+ hoge:
100
+ <<: *hogege
101
+ YAML
102
+ @yaml = I27r::YamlDocument.new @yaml_string
103
+ @yaml['ja', 'activerecord', 'hoge2', 'hoge'] = 'foo'
104
+ end
105
+
106
+ specify '' do
107
+ puts @yaml.to_s
108
+ end
109
+ end
110
+
111
+ context 'creating a new file' do
112
+ before do
113
+
114
+ end
115
+
116
+ specify 'that' do
117
+ yaml = I27r::YamlDocument.new
118
+ yaml['ja', 'hoge', 'fuga'] = 'piyo'
119
+ yaml['ja', 'hoge', 'foo'] = 'bar'
120
+ puts yaml
121
+ end
122
+ end
123
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n-generators
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Akira Matsuda
9
+ - Łukasz Niemier
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-01-02 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mechanize
17
+ requirement: &19369820 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *19369820
26
+ description: A Rails generator plugin & gem that generates Rails I18n locale files
27
+ for almost every known locale.
28
+ email:
29
+ - ronnie@dio.jp
30
+ - lukasz@niemier.pl
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files:
34
+ - README.rdoc
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - History.txt
39
+ - MIT-LICENSE
40
+ - README.rdoc
41
+ - Rakefile
42
+ - generators/i18n/USAGE
43
+ - generators/i18n/i18n_generator.rb
44
+ - generators/i18n/lib/yaml.rb
45
+ - generators/i18n/templates/base.yml
46
+ - generators/i18n/templates/i18n_config.rb
47
+ - generators/i18n/templates/translation.yml
48
+ - generators/i18n_locale/USAGE
49
+ - generators/i18n_locale/i18n_locale_command.rb
50
+ - generators/i18n_locale/i18n_locale_generator.rb
51
+ - generators/i18n_locale/lib/cldr.rb
52
+ - generators/i18n_scaffold/i18n_scaffold_generator.rb
53
+ - generators/i18n_scaffold/templates/controller.rb
54
+ - generators/i18n_scaffold/templates/functional_test.rb
55
+ - generators/i18n_scaffold/templates/helper.rb
56
+ - generators/i18n_scaffold/templates/helper_test.rb
57
+ - generators/i18n_scaffold/templates/layout.html.erb
58
+ - generators/i18n_scaffold/templates/style.css
59
+ - generators/i18n_scaffold/templates/view_edit.html.erb
60
+ - generators/i18n_scaffold/templates/view_index.html.erb
61
+ - generators/i18n_scaffold/templates/view_new.html.erb
62
+ - generators/i18n_scaffold/templates/view_show.html.erb
63
+ - generators/i18n_translation/USAGE
64
+ - generators/i18n_translation/i18n_translation_command.rb
65
+ - generators/i18n_translation/i18n_translation_generator.rb
66
+ - generators/i18n_translation/lib/erb_executer.rb
67
+ - generators/i18n_translation/lib/recording_backend.rb
68
+ - generators/i18n_translation/lib/through_ryoku.rb
69
+ - generators/i18n_translation/lib/translator.rb
70
+ - i18n-generators.gemspec
71
+ - lib/generators/i18n/all/USAGE
72
+ - lib/generators/i18n/all/i18n_generator.rb
73
+ - lib/generators/i18n/locale/USAGE
74
+ - lib/generators/i18n/locale/locale_generator.rb
75
+ - lib/generators/i18n/translation/USAGE
76
+ - lib/generators/i18n/translation/lib/translator.rb
77
+ - lib/generators/i18n/translation/lib/yaml.rb
78
+ - lib/generators/i18n/translation/lib/yaml_waml.rb
79
+ - lib/generators/i18n/translation/translation_generator.rb
80
+ - lib/i18n_generators/version.rb
81
+ - spec/cldr_spec.rb
82
+ - spec/data/cldr/ja.html
83
+ - spec/data/yml/active_record/en-US.yml
84
+ - spec/i18n_locale_command_spec.rb
85
+ - spec/i18n_translation_command_spec.rb
86
+ - spec/spec_helper.rb
87
+ - spec/translator_spec.rb
88
+ - spec/yaml_spec.rb
89
+ homepage: https://github.com/hauleth/i18n-generators
90
+ licenses:
91
+ - MIT
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.10
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Generates I18n locale files for Rails 3 and Rails 2
114
+ test_files:
115
+ - spec/cldr_spec.rb
116
+ - spec/data/cldr/ja.html
117
+ - spec/data/yml/active_record/en-US.yml
118
+ - spec/i18n_locale_command_spec.rb
119
+ - spec/i18n_translation_command_spec.rb
120
+ - spec/spec_helper.rb
121
+ - spec/translator_spec.rb
122
+ - spec/yaml_spec.rb