i18n_generators 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/History.txt +104 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +104 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/generators/i18n/USAGE +13 -0
- data/generators/i18n/i18n_generator.rb +85 -0
- data/generators/i18n/lib/yaml.rb +187 -0
- data/generators/i18n/templates/base.yml +0 -0
- data/generators/i18n/templates/i18n_config.rb +5 -0
- data/generators/i18n/templates/translation.yml +1 -0
- data/generators/i18n_locale/USAGE +12 -0
- data/generators/i18n_locale/i18n_locale_command.rb +135 -0
- data/generators/i18n_locale/i18n_locale_generator.rb +9 -0
- data/generators/i18n_locale/lib/cldr.rb +139 -0
- data/generators/i18n_scaffold/i18n_scaffold_generator.rb +3 -0
- data/generators/i18n_scaffold/templates/controller.rb +85 -0
- data/generators/i18n_scaffold/templates/functional_test.rb +45 -0
- data/generators/i18n_scaffold/templates/helper.rb +2 -0
- data/generators/i18n_scaffold/templates/helper_test.rb +4 -0
- data/generators/i18n_scaffold/templates/layout.html.erb +17 -0
- data/generators/i18n_scaffold/templates/style.css +54 -0
- data/generators/i18n_scaffold/templates/view_edit.html.erb +18 -0
- data/generators/i18n_scaffold/templates/view_index.html.erb +24 -0
- data/generators/i18n_scaffold/templates/view_new.html.erb +17 -0
- data/generators/i18n_scaffold/templates/view_show.html.erb +10 -0
- data/generators/i18n_translation/USAGE +9 -0
- data/generators/i18n_translation/i18n_translation_command.rb +121 -0
- data/generators/i18n_translation/i18n_translation_generator.rb +9 -0
- data/generators/i18n_translation/lib/erb_executer.rb +31 -0
- data/generators/i18n_translation/lib/recording_backend.rb +16 -0
- data/generators/i18n_translation/lib/through_ryoku.rb +8 -0
- data/generators/i18n_translation/lib/translator.rb +28 -0
- data/i18n_generators.gemspec +87 -0
- data/spec/cldr_spec.rb +54 -0
- data/spec/data/cldr/ja.html +3112 -0
- data/spec/data/yml/active_record/en-US.yml +54 -0
- data/spec/i18n_locale_command_spec.rb +63 -0
- data/spec/i18n_translation_command_spec.rb +24 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/translator_spec.rb +46 -0
- data/spec/yaml_spec.rb +59 -0
- metadata +114 -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
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
2
|
+
# from the project root directory.
|
3
|
+
require 'rubygems'
|
4
|
+
require 'spec'
|
5
|
+
require 'activesupport'
|
6
|
+
|
7
|
+
Spec::Runner.configure do |config|
|
8
|
+
# == Fixtures
|
9
|
+
#
|
10
|
+
# You can declare fixtures for each example_group like this:
|
11
|
+
# describe "...." do
|
12
|
+
# fixtures :table_a, :table_b
|
13
|
+
#
|
14
|
+
# Alternatively, if you prefer to declare them only once, you can
|
15
|
+
# do so right here. Just uncomment the next line and replace the fixture
|
16
|
+
# names with your fixtures.
|
17
|
+
#
|
18
|
+
# config.global_fixtures = :table_a, :table_b
|
19
|
+
#
|
20
|
+
# If you declare global fixtures, be aware that they will be declared
|
21
|
+
# for all of your examples, even those that don't use them.
|
22
|
+
#
|
23
|
+
# You can also declare which fixtures to use (for example fixtures for test/fixtures):
|
24
|
+
#
|
25
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
26
|
+
#
|
27
|
+
# == Mock Framework
|
28
|
+
#
|
29
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
30
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
31
|
+
#
|
32
|
+
# config.mock_with :mocha
|
33
|
+
# config.mock_with :flexmock
|
34
|
+
# config.mock_with :rr
|
35
|
+
#
|
36
|
+
# == Notes
|
37
|
+
#
|
38
|
+
# For more information take a look at Spec::Example::Configuration and Spec::Runner
|
39
|
+
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,59 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
require File.join(File.dirname(__FILE__), '/../generators/i18n/lib/yaml')
|
3
|
+
|
4
|
+
include I18nLocaleGeneratorModule
|
5
|
+
|
6
|
+
describe 'Yaml' do
|
7
|
+
before :each do
|
8
|
+
@yaml = YamlDocument.new File.join(File.dirname(__FILE__), 'data/yml/active_record/en-US.yml'), 'ja'
|
9
|
+
end
|
10
|
+
|
11
|
+
describe YamlDocument do
|
12
|
+
it 'should return the top level node with the square bracket method' do
|
13
|
+
node = @yaml['ja']
|
14
|
+
node.should be_an_instance_of(Node)
|
15
|
+
node.key.should == 'ja'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should generate a path string on the top node' do
|
19
|
+
@yaml['ja'].path.should == '/ja'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Node do
|
24
|
+
before do
|
25
|
+
@node = Node.new @yaml, 100, 'foo: bar'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return a key string from input text' do
|
29
|
+
@node.key.should == 'foo'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return a value string from input text' do
|
33
|
+
@node.value.should == 'bar'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should generate a path string on any node' do
|
37
|
+
@yaml['ja']['activerecord']['errors']['messages'].path.should == '/ja/activerecord/errors/messages'
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '[] method' do
|
41
|
+
describe 'when a child with the specified key exists' do
|
42
|
+
it 'should return a child which has the specified key'
|
43
|
+
|
44
|
+
it 'should not modify the YAML contents'
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'when a child with the specified key exists' do
|
48
|
+
it 'should return a new node with the specified key'
|
49
|
+
|
50
|
+
it 'should append the created node under the current node'
|
51
|
+
|
52
|
+
it 'should append the created line to the YAML document'
|
53
|
+
|
54
|
+
it 'should increment the line number of the succeeding lines of the newly added line'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n_generators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 63
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Akira Matsuda
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-26 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: A Rails generator plugin & gem that generates Rails 2.2 and 2.3 I18n locale files for almost every known locale.
|
23
|
+
email: ronnie@dio.jp
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- History.txt
|
33
|
+
- MIT-LICENSE
|
34
|
+
- README.rdoc
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- generators/i18n/USAGE
|
38
|
+
- generators/i18n/i18n_generator.rb
|
39
|
+
- generators/i18n/lib/yaml.rb
|
40
|
+
- generators/i18n/templates/base.yml
|
41
|
+
- generators/i18n/templates/i18n_config.rb
|
42
|
+
- generators/i18n/templates/translation.yml
|
43
|
+
- generators/i18n_locale/USAGE
|
44
|
+
- generators/i18n_locale/i18n_locale_command.rb
|
45
|
+
- generators/i18n_locale/i18n_locale_generator.rb
|
46
|
+
- generators/i18n_locale/lib/cldr.rb
|
47
|
+
- generators/i18n_scaffold/i18n_scaffold_generator.rb
|
48
|
+
- generators/i18n_scaffold/templates/controller.rb
|
49
|
+
- generators/i18n_scaffold/templates/functional_test.rb
|
50
|
+
- generators/i18n_scaffold/templates/helper.rb
|
51
|
+
- generators/i18n_scaffold/templates/helper_test.rb
|
52
|
+
- generators/i18n_scaffold/templates/layout.html.erb
|
53
|
+
- generators/i18n_scaffold/templates/style.css
|
54
|
+
- generators/i18n_scaffold/templates/view_edit.html.erb
|
55
|
+
- generators/i18n_scaffold/templates/view_index.html.erb
|
56
|
+
- generators/i18n_scaffold/templates/view_new.html.erb
|
57
|
+
- generators/i18n_scaffold/templates/view_show.html.erb
|
58
|
+
- generators/i18n_translation/USAGE
|
59
|
+
- generators/i18n_translation/i18n_translation_command.rb
|
60
|
+
- generators/i18n_translation/i18n_translation_generator.rb
|
61
|
+
- generators/i18n_translation/lib/erb_executer.rb
|
62
|
+
- generators/i18n_translation/lib/recording_backend.rb
|
63
|
+
- generators/i18n_translation/lib/through_ryoku.rb
|
64
|
+
- generators/i18n_translation/lib/translator.rb
|
65
|
+
- i18n_generators.gemspec
|
66
|
+
- spec/cldr_spec.rb
|
67
|
+
- spec/data/cldr/ja.html
|
68
|
+
- spec/data/yml/active_record/en-US.yml
|
69
|
+
- spec/i18n_locale_command_spec.rb
|
70
|
+
- spec/i18n_translation_command_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
- spec/translator_spec.rb
|
73
|
+
- spec/yaml_spec.rb
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: http://github.com/amatsuda/i18n_generators/
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options:
|
80
|
+
- --charset=UTF-8
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.3.7
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Generates I18n locale files for Rails 2.2 and 2.3
|
108
|
+
test_files:
|
109
|
+
- spec/cldr_spec.rb
|
110
|
+
- spec/i18n_locale_command_spec.rb
|
111
|
+
- spec/i18n_translation_command_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/translator_spec.rb
|
114
|
+
- spec/yaml_spec.rb
|