i18n_generators 1.2.1 → 2.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f02b7686ba68144eaab55c14f430f633e24ca3f
4
+ data.tar.gz: 65ad08fc37937c611b7e1afbb56ff36cf4a4d199
5
+ SHA512:
6
+ metadata.gz: dae9f080472d7da5b7fd6f944092b81ab5a57f5a6e56d59e74088450ad9c47ac8250f0e5aa308171d498caacb4df6823558210fcf5b7f27941951ca8a9ba4c08
7
+ data.tar.gz: ed5b7cfb0e594b85bfad0cbde0229a9df640912d379235a45fec478487241322b5bb4929978f37e076f48bb3868ae31015a598449aab2d3125bcfca1a3155d2f
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/History.txt CHANGED
@@ -1,18 +1,28 @@
1
+ == 2.0.0
2
+
3
+ * enhancements
4
+ * The GoogleTranslate is back, and everything works again now! (liuhui998)
5
+
6
+ == 1.2.1
7
+
8
+ * bugfixes:
9
+ * Rails 4 ready
10
+
1
11
  == 1.2.0
2
12
 
3
13
  * enhancements:
4
14
  * Drop Rails 2 support
5
- * Put alias to model name for non-collection reflection names (see: https://twitter.com/#!/znz/status/179109337581625344) (thanks to znz-san!)
15
+ * Put alias to model name for non-collection reflection names (see: https://twitter.com/#!/znz/status/179109337581625344) (thanks to znz)
6
16
 
7
17
  == 1.1.0
8
18
 
9
19
  * enhancements:
10
- * New translation engine (see: http://googlecode.blogspot.com/2011/05/spring-cleaning-for-some-of-our-apis.html) (thanks to agilekawabata-san!)
20
+ * New translation engine (see: http://googlecode.blogspot.com/2011/05/spring-cleaning-for-some-of-our-apis.html) (thanks to agilekawabata)
11
21
 
12
22
  == 1.0.3
13
23
 
14
24
  * bugfixes:
15
- * #4 Translation generator recursive loop in ruby 1.9 + MS-Windows (memarko)
25
+ * #4 Translation generator recursive loop in ruby 1.9 + MS-Windows (memarko)
16
26
 
17
27
  * enhancements:
18
28
  * Some Rails-3-ish cleanups
@@ -25,19 +35,19 @@
25
35
  == 1.0.1
26
36
 
27
37
  * major enhancements:
28
- * Bundle yaml_waml.rb to avoid depending on yaml_waml gem (thanks to kakutani-san!)
38
+ * Bundle yaml_waml.rb to avoid depending on yaml_waml gem (thanks to kakutani)
29
39
 
30
40
  == 1.0.0
31
41
 
32
42
  * major enhancements:
33
43
  * Rails 3
34
44
  * enhancements:
35
- * Fixing deprectaed syntax {{error}} with %{error} for i18n_scaffold (moro)
45
+ * Fixing deprectaed syntax {{error}} with %{error} for i18n_scaffold (moro)
36
46
 
37
47
  == 0.8.1
38
48
 
39
49
  * bugfixes:
40
- * Fix for pluralized translations (scambra)
50
+ * Fix for pluralized translations (scambra)
41
51
 
42
52
  == 0.8.0
43
53
 
@@ -58,9 +68,9 @@
58
68
  * Could not load cldr data with short locale names
59
69
  * major enhancements:
60
70
  * Include AR association names in model attributes translation
61
- * Add 'generated' comment mark (#g) for generated lines in YAML (thanks to t-wada-senpai, Shimura-san, Toyofuku-san, Sezutsu-san and oukayuka-san!)
71
+ * Add 'generated' comment mark (#g) for generated lines in YAML (thanks to t-wada-senpai, Shimura-san, Toyofuku-san, Sezutsu-san and oukayuka)
62
72
  * Add --include-timestamps option and change default bahaviour not to include timestamp columns in translation YAML
63
- * Add blank line between each blocks (thanks to Sawayanagi-san!)
73
+ * Add blank line between each blocks (thanks to Sawayanagi)
64
74
  * enhancements:
65
75
  * Avoid generating blank locale file
66
76
  * Change GitHub fetch URL from blob/master/...?raw=true to raw/master
@@ -78,12 +88,12 @@
78
88
  == 0.4.1
79
89
 
80
90
  * bugfixes:
81
- * i18n_translation abnormally ends when loading a view containing "-%>" (thanks to babie-san!)
91
+ * i18n_translation abnormally ends when loading a view containing "-%>" (thanks to babie)
82
92
 
83
93
  == 0.4.0
84
94
 
85
95
  * major enhancements:
86
- * translation generator now preserves any existing extra lines in the YAML file (thanks to Iain Hecker-san!)
96
+ * translation generator now preserves any existing extra lines in the YAML file (thanks to Iain Hecker)
87
97
 
88
98
  == 0.3.4
89
99
 
@@ -93,12 +103,12 @@
93
103
  == 0.3.3
94
104
 
95
105
  * bugfixes:
96
- * Did not work on Ruby 1.8.6 (thanks to akm-san!)
106
+ * Did not work on Ruby 1.8.6 (thanks to akm)
97
107
 
98
108
  == 0.3.2
99
109
 
100
110
  * bugfixes:
101
- * Trim mode in ERB didn't work on some platforms (thanks to valda-san!)
111
+ * Trim mode in ERB didn't work on some platforms (thanks to valda)
102
112
 
103
113
  == 0.3.1
104
114
 
@@ -112,15 +122,15 @@
112
122
  * Renamed the generators
113
123
  i18n_locales -> i18n_locale (i18n --locale)
114
124
  i18n_models -> i18n_translation (i18n --translation)
115
- * Handle all translate keys which appear in view files (thanks to PanosJee-san!)
125
+ * Handle all translate keys which appear in view files (thanks to PanosJee)
116
126
 
117
127
  == 0.2.0
118
128
 
119
129
  * major enhancements:
120
- * Implemented i18n_scaffold generator (thanks to Iain Hecker-san!)
130
+ * Implemented i18n_scaffold generator (thanks to Iain Hecker)
121
131
 
122
132
  * enhancements:
123
- * i18n_models generator can now deal with non AR classes which has content_columns (thanks to Iain Hecker-san!)
133
+ * i18n_models generator can now deal with non AR classes which has content_columns (thanks to Iain Hecker)
124
134
 
125
135
  == 0.1.0
126
136
 
@@ -128,7 +138,7 @@
128
138
  * Fetch locale YAML file from rails-i18n project repository first
129
139
 
130
140
  * bugfixes:
131
- * Could not recognize model names with multipie words (thanks to makoto-san!)
141
+ * Could not recognize model names with multipie words (thanks to makoto)
132
142
 
133
143
  == 0.0.8
134
144
 
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # I18n generators
2
+
3
+ A Rails plugin that generates the I18n locale files with automatic
4
+ translation. Supporting Rails 5.0, 4.2.x, 4.1.x, 4.0.x, 3.2.x, 3.1.x, 3.0.x,
5
+ 2.3.x, and 2.2.x.
6
+
7
+ Here's an example of generating a translation file (the example model is taken
8
+ from [the Rails Girls app](http://guides.railsgirls.com/app/#create-idea-scaffold)).
9
+
10
+ % rails g scaffold idea name description:text picture
11
+ % rails g i18n ja
12
+
13
+ ![translation_ja.yml](https://raw.githubusercontent.com/amatsuda/i18n_generators/414e923ae1a6450f0005b486376d084a88938a9e/assets/i18n_ja_example.png)
14
+
15
+ ## Features
16
+
17
+ This gem/plugin provides following three generator commands.
18
+
19
+ ### 1. Generate Locale Files for ActiveRecord/ActiveSupport/ActionPack/ActionView
20
+
21
+ % rails g i18n_locale ja (de-AT, pt-BR, etc.)
22
+
23
+ Downloads the .yml file for the specified locale from the official rails-i18n
24
+ repository:
25
+ https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale
26
+
27
+ Then the generator sets the application default locale to the specified
28
+ locale.
29
+
30
+ This will generate following locale file.
31
+
32
+ config/locales/ja.yml
33
+
34
+ ### 2. Generate Translation YAML File For All Models/Attributes
35
+
36
+ % rails g i18n_translation ja (de-AT, pt-BR, etc.)
37
+
38
+ This will generate following YAML file.
39
+
40
+ config/locales/translation_ja.yml
41
+
42
+ The generator scans your app/models directory, and generates a YAML file with
43
+ all the AR model names and attributes so that you don't have to write the YAML
44
+ skeleton manually. In addition, the generator tries to translate each of them
45
+ into the specified language. The generator doesn't overwrite the existing
46
+ value so that you can rerun the generator again and again.
47
+
48
+ The #g mark in the generated YAML means that the line is generated by the
49
+ generator.
50
+
51
+ ### 3. Generate All
52
+
53
+ % rails g i18n ja (de-AT, pt-BR, etc.)
54
+
55
+ Executes 1 and 2 at once.
56
+
57
+
58
+ ## Supported versions
59
+
60
+ * Ruby 2.3, 2.2.x, 2.1.x, 2.0.0, 1.9.x, 1.8.7
61
+ * Ruby on Rails 5.0, 4.2, 4.1, 4.0, 3.2, 3.1, 3.0
62
+ * Ruby on Rails 2.3, 2.2 (supported by i18n_generators < 1.2)
63
+
64
+
65
+ ## Installation
66
+
67
+ * Rails 3 or higher (with Bundler)
68
+
69
+
70
+ Add 'i18n_generators' to your Gemfile, then `bundle`. Restricting the group to
71
+ :development would be a good idea, since the generator would probably be used
72
+ only in development mode.
73
+
74
+ * Rails 2
75
+
76
+
77
+ Use 'i18n_generators' version '< 1.2'.
78
+
79
+
80
+ ## Copyright
81
+
82
+ Copyright (c) 2008 Akira Matsuda, released under the MIT license
data/Rakefile CHANGED
@@ -1,10 +1,13 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- require 'rspec/core'
5
- require 'rspec/core/rake_task'
6
- RSpec::Core::RakeTask.new(:spec) do |spec|
7
- spec.pattern = FileList['spec/**/*_spec.rb']
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.warning = true
10
+ t.verbose = true
8
11
  end
9
12
 
10
- task :default => :spec
13
+ task :default => :test
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ['Akira Matsuda']
10
10
  s.email = ['ronnie@dio.jp']
11
11
  s.homepage = 'https://github.com/amatsuda/i18n_generators'
12
- s.summary = 'Generates I18n locale files for Rails 3 and Rails 2'
13
- s.description = 'A Rails generator plugin & gem that generates Rails I18n locale files for almost every known locale.'
12
+ s.summary = 'A Rails generator that generates Rails I18n locale files with automatic translation for almost every known locale.'
13
+ s.description = 'A Rails generator that generates Rails I18n locale files with automatic translation for almost every known locale.'
14
14
 
15
15
  s.rubyforge_project = 'i18n_generators'
16
16
 
@@ -19,12 +19,11 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ['lib']
21
21
 
22
- s.extra_rdoc_files = ['README.rdoc']
23
22
  s.licenses = ['MIT']
24
23
 
25
24
  s.add_runtime_dependency 'mechanize'
26
25
  s.add_runtime_dependency 'rails', '>= 3.0.0'
27
- s.add_development_dependency 'rails'
28
- s.add_development_dependency 'rspec'
26
+ s.add_development_dependency 'test-unit'
27
+ s.add_development_dependency 'test-unit-rr'
29
28
  s.add_development_dependency 'rake'
30
29
  end
@@ -20,7 +20,7 @@ class I18nLocaleGenerator < Rails::Generators::NamedBase
20
20
  end
21
21
 
22
22
  def add_locale_config(config_contents)
23
- new_line = " config.i18n.default_locale = '#{locale_name}'"
23
+ new_line = " config.i18n.default_locale = :#{locale_name}"
24
24
  if config_contents =~ /\n *config\.i18n\.default_locale *=/
25
25
  config_contents.sub(/ *config\.i18n\.default_locale *=.*/, new_line)
26
26
  elsif config_contents =~ /\n *#? *config\.i18n\.default_locale *=/
@@ -36,6 +36,7 @@ class I18nLocaleGenerator < Rails::Generators::NamedBase
36
36
  log "fetching #{locale_name}.yml from rails-i18n repository..."
37
37
  begin
38
38
  get "https://github.com/svenfuchs/rails-i18n/raw/master/rails/locale/#{locale_name}.yml", "config/locales/#{locale_name}.yml"
39
+ I18n.load_path.unshift "config/locales/#{locale_name}.yml"
39
40
  rescue
40
41
  log "could not find #{locale_name}.yml on rails-i18n repository"
41
42
  end
@@ -1,23 +1,11 @@
1
- require 'open-uri'
2
-
3
1
  module I27r
4
2
  class TranslationError < StandardError; end
5
3
 
6
4
  module GoogleTranslate
7
5
  def _translate(word, lang)
8
6
  w = CGI.escape ActiveSupport::Inflector.humanize(word)
9
- json = OpenURI.open_uri("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=#{w}&langpair=en%7C#{lang}").read
10
- result = if RUBY_VERSION >= '1.9'
11
- require 'json'
12
- ::JSON.parse json
13
- else
14
- ActiveSupport::JSON.decode(json)
15
- end
16
- if result['responseStatus'] == 200
17
- result['responseData']['translatedText']
18
- else
19
- raise TranslationError.new result.inspect
20
- end
7
+ text = Net::HTTP.get URI("https://translate.google.com/translate_a/single?client=t&sl=en&tl=#{lang}&dt=t&q=#{w}")
8
+ text.scan(/"(.*?)"/).first.first.tap {|t| t.force_encoding(Encoding::UTF_8) if t.respond_to? :force_encoding}
21
9
  end
22
10
  end
23
11
 
@@ -33,8 +21,31 @@ module I27r
33
21
  end
34
22
  end
35
23
 
24
+ module BingTranslator
25
+ def _translate(word, lang)
26
+ require 'cgi'
27
+ require 'open-uri'
28
+
29
+ w = CGI.escape ActiveSupport::Inflector.humanize(word)
30
+ json = OpenURI.open_uri("http://api.microsofttranslator.com/v2/ajax.svc/TranslateArray?appId=%22T5y_QKkSEGi7P462fd0EwjEhB0_XGUl8PNTgQylxBYks*%22&texts=[%22#{w}%22]&from=%22en%22&to=%22#{lang}%22").read.gsub(/\A([^\[]+)/, '')
31
+
32
+ result = if RUBY_VERSION >= '1.9'
33
+ require 'json'
34
+ ::JSON.parse json
35
+ else
36
+ ActiveSupport::JSON.decode(json)
37
+ end
38
+
39
+ if result.any?
40
+ result[0]['TranslatedText']
41
+ else
42
+ raise TranslationError.new result.inspect
43
+ end
44
+ end
45
+ end
46
+
36
47
  class Translator
37
- include BabelFish
48
+ include GoogleTranslate
38
49
 
39
50
  def initialize(lang)
40
51
  @lang, @cache = lang, {}
@@ -60,7 +60,7 @@ module I27r
60
60
  end
61
61
 
62
62
  def self.load_yml_file(yml_path)
63
- if File.exists? yml_path
63
+ if File.exist? yml_path
64
64
  self.new File.read(yml_path)
65
65
  else
66
66
  self.new
@@ -1,3 +1,3 @@
1
1
  module I18nGenerators
2
- VERSION = '1.2.1'
2
+ VERSION = '2.0.0'
3
3
  end
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ require 'test_helper'
2
+ require 'generators/i18n_locale/i18n_locale_generator'
3
+
4
+ class I18nLocaleGeneratorTest < Test::Unit::TestCase
5
+ setup do
6
+ @generator = I18nLocaleGenerator.new(['ja'])
7
+ end
8
+
9
+ sub_test_case 'add_locale_config' do
10
+ test 'when i18n.default_locale is configured in environment.rb' do
11
+ config = <<-CONFIG
12
+ module Tes
13
+ class Application < Rails::Application
14
+ config.i18n.default_locale = :de
15
+ end
16
+ end
17
+ CONFIG
18
+
19
+ assert_equal <<-RESULT, @generator.send(:add_locale_config, config)
20
+ module Tes
21
+ class Application < Rails::Application
22
+ config.i18n.default_locale = :ja
23
+ end
24
+ end
25
+ RESULT
26
+ end
27
+
28
+ test 'when i18n.default_locale config is commented in environment.rb' do
29
+ config = <<-CONFIG
30
+ module Tes
31
+ class Application < Rails::Application
32
+ # config.i18n.default_locale = :de
33
+ end
34
+ end
35
+ CONFIG
36
+
37
+ assert_equal <<-RESULT, @generator.send(:add_locale_config, config)
38
+ module Tes
39
+ class Application < Rails::Application
40
+ config.i18n.default_locale = :ja
41
+ end
42
+ end
43
+ RESULT
44
+ end
45
+
46
+ test 'when i18n.default_locale is not written in environment.rb' do
47
+ config = <<-CONFIG
48
+ module Tes
49
+ class Application < Rails::Application
50
+ something goes here.
51
+ bla bla bla...
52
+ end
53
+ end
54
+ CONFIG
55
+
56
+ assert_equal <<-RESULT, @generator.send(:add_locale_config, config)
57
+ module Tes
58
+ class Application < Rails::Application
59
+ config.i18n.default_locale = :ja
60
+ something goes here.
61
+ bla bla bla...
62
+ end
63
+ end
64
+ RESULT
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+ require 'generators/i18n_translation/i18n_translation_generator'
3
+
4
+ class I18nTranslationGeneratorTest < Test::Unit::TestCase
5
+ setup do
6
+ @generator = I18nTranslationGenerator.new(['ja'])
7
+ end
8
+
9
+ test 'each_value' do
10
+ pend
11
+
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
+ subject.send(:each_value, [], hash) do |parents, value|
19
+ p "#{parents.join('.')} #{value}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rails'
4
+ require 'rails/generators'
5
+ require 'test/unit'
6
+ require 'test/unit/rr'
7
+
8
+ Rails.logger ||= Logger.new STDOUT
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ $KCODE = 'U'
3
+
4
+ require 'test_helper'
5
+ require 'generators/i18n_translation/lib/translator'
6
+
7
+ class I27r::TranslatorTest < Test::Unit::TestCase
8
+ setup do
9
+ @translator = I27r::Translator.new 'ja'
10
+ end
11
+
12
+ test 'when successfully translated' do
13
+ stub(@translator)._translate { 'こんにちは' }
14
+
15
+ assert_equal 'こんにちは', @translator.translate('hello')
16
+ end
17
+
18
+ test 'when translation failed with error code' do
19
+ stub(@translator)._translate { '' }
20
+
21
+ assert_equal 'hello', @translator.translate('hello')
22
+ end
23
+
24
+ test 'when translation raised an error' do
25
+ stub(@translator)._translate { raise 'ERROR!' }
26
+
27
+ assert_equal 'hello', @translator.translate('hello')
28
+ end
29
+ end
data/test/yaml_test.rb ADDED
@@ -0,0 +1,112 @@
1
+ # coding: utf-8
2
+ require 'test_helper'
3
+ require 'generators/i18n_translation/lib/yaml'
4
+
5
+ class I27r::YamlDocumentTest < Test::Unit::TestCase
6
+ sub_test_case 'when loading an existing file' do
7
+ setup do
8
+ @yaml_string = <<YAML
9
+ ja:
10
+ hoge:
11
+ fuga: piyo #g
12
+ numbers:
13
+ one: "いち" #g
14
+ two: "に"
15
+
16
+ aaa:
17
+ foo: "ふー"
18
+ bar: "ばー"
19
+ YAML
20
+ @yaml = I27r::YamlDocument.new @yaml_string
21
+ end
22
+
23
+ test 'it exists' do
24
+ assert_not_nil @yaml
25
+ end
26
+
27
+ test 'to_s' do
28
+ assert_equal @yaml_string, @yaml.to_s
29
+ end
30
+
31
+ test '[]' do
32
+ assert_equal 'piyo', @yaml['ja', 'hoge', 'fuga']
33
+ assert_equal 'piyo', @yaml[['ja', 'hoge', 'fuga']]
34
+ end
35
+
36
+ test 'find_line_by_path' do
37
+ assert_equal 'piyo', @yaml.find_line_by_path(['ja', 'hoge', 'fuga']).value
38
+ end
39
+
40
+ test 'find_line_by_path (-1)' do
41
+ line = @yaml.find_line_by_path(['ja', 'aho', 'hage'], -1, true)
42
+
43
+ assert_not_nil line
44
+ assert_equal 'hage', line.key
45
+ assert_nil line.value
46
+ end
47
+
48
+ sub_test_case '[]=' do
49
+ test 'rewriting an existing value' do
50
+ @yaml['ja', 'hoge', 'fuga'] = 'puyo'
51
+ assert_equal 'puyo', @yaml['ja', 'hoge', 'fuga']
52
+ end
53
+
54
+ test 'an existing value without #g mark' do
55
+ @yaml['ja', 'hoge', 'numbers', 'two'] = 'ツー'
56
+ assert_equal 'に', @yaml['ja', 'hoge', 'numbers', 'two']
57
+ end
58
+
59
+ test 'creating a new node in the middle' do
60
+ @yaml['ja', 'hoge', 'numbers', 'three'] = 'さん'
61
+ assert_equal 'さん', @yaml['ja', 'hoge', 'numbers', 'three']
62
+ assert_equal <<YAML, @yaml.to_s
63
+ ja:
64
+ hoge:
65
+ fuga: piyo #g
66
+ numbers:
67
+ one: "いち" #g
68
+ two: "に"
69
+ three: さん #g
70
+
71
+ aaa:
72
+ foo: "ふー"
73
+ bar: "ばー"
74
+ YAML
75
+ end
76
+
77
+ test 'creating a new node at the bottom' do
78
+ @yaml['ja', 'aho', 'hage'] = 'hige'
79
+ assert_equal 'hige', @yaml['ja', 'aho', 'hage']
80
+ end
81
+ end
82
+ end
83
+
84
+ test 'when loading an existing file with alias' do
85
+ pend
86
+
87
+ @yaml_string = <<YAML
88
+ ja:
89
+ activerecord:
90
+ attributes:
91
+ hoge: &hoge
92
+ foo: FOO
93
+ bar: BAR
94
+ hoge2: &hoge2
95
+ hoge:
96
+ <<: *hogege
97
+ YAML
98
+ @yaml = I27r::YamlDocument.new @yaml_string
99
+ @yaml['ja', 'activerecord', 'hoge2', 'hoge'] = 'foo'
100
+
101
+ puts @yaml.to_s
102
+ end
103
+
104
+ test 'creating a new file' do
105
+ pend
106
+
107
+ yaml = I27r::YamlDocument.new
108
+ yaml['ja', 'hoge', 'fuga'] = 'piyo'
109
+ yaml['ja', 'hoge', 'foo'] = 'bar'
110
+ puts yaml
111
+ end
112
+ end
metadata CHANGED
@@ -1,85 +1,98 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Akira Matsuda
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-07 00:00:00.000000000 Z
11
+ date: 2015-08-31 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mechanize
16
- requirement: &70124690800140 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70124690800140
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rails
27
- requirement: &70124690822220 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: 3.0.0
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70124690822220
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
36
41
  - !ruby/object:Gem::Dependency
37
- name: rails
38
- requirement: &70124690831120 !ruby/object:Gem::Requirement
39
- none: false
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>='
45
+ - - ">="
42
46
  - !ruby/object:Gem::Version
43
47
  version: '0'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *70124690831120
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
47
55
  - !ruby/object:Gem::Dependency
48
- name: rspec
49
- requirement: &70124690828200 !ruby/object:Gem::Requirement
50
- none: false
56
+ name: test-unit-rr
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ! '>='
59
+ - - ">="
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *70124690828200
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: rake
60
- requirement: &70124690827340 !ruby/object:Gem::Requirement
61
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
62
72
  requirements:
63
- - - ! '>='
73
+ - - ">="
64
74
  - !ruby/object:Gem::Version
65
75
  version: '0'
66
76
  type: :development
67
77
  prerelease: false
68
- version_requirements: *70124690827340
69
- description: A Rails generator plugin & gem that generates Rails I18n locale files
70
- for almost every known locale.
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A Rails generator that generates Rails I18n locale files with automatic
84
+ translation for almost every known locale.
71
85
  email:
72
86
  - ronnie@dio.jp
73
87
  executables: []
74
88
  extensions: []
75
- extra_rdoc_files:
76
- - README.rdoc
89
+ extra_rdoc_files: []
77
90
  files:
78
- - .gitignore
91
+ - ".gitignore"
79
92
  - Gemfile
80
93
  - History.txt
81
94
  - MIT-LICENSE
82
- - README.rdoc
95
+ - README.md
83
96
  - Rakefile
84
97
  - i18n_generators.gemspec
85
98
  - lib/generators/i18n/USAGE
@@ -92,43 +105,43 @@ files:
92
105
  - lib/generators/i18n_translation/lib/yaml.rb
93
106
  - lib/generators/i18n_translation/lib/yaml_waml.rb
94
107
  - lib/i18n_generators/version.rb
95
- - spec/data/cldr/ja.html
96
- - spec/data/yml/active_record/en-US.yml
97
- - spec/i18n_locale_command_spec.rb
98
- - spec/i18n_translation_command_spec.rb
99
- - spec/spec_helper.rb
100
- - spec/translator_spec.rb
101
- - spec/yaml_spec.rb
108
+ - test/data/cldr/ja.html
109
+ - test/data/yml/active_record/en-US.yml
110
+ - test/i18n_locale_command_test.rb
111
+ - test/i18n_translation_command_test.rb
112
+ - test/test_helper.rb
113
+ - test/translator_test.rb
114
+ - test/yaml_test.rb
102
115
  homepage: https://github.com/amatsuda/i18n_generators
103
116
  licenses:
104
117
  - MIT
118
+ metadata: {}
105
119
  post_install_message:
106
120
  rdoc_options: []
107
121
  require_paths:
108
122
  - lib
109
123
  required_ruby_version: !ruby/object:Gem::Requirement
110
- none: false
111
124
  requirements:
112
- - - ! '>='
125
+ - - ">="
113
126
  - !ruby/object:Gem::Version
114
127
  version: '0'
115
128
  required_rubygems_version: !ruby/object:Gem::Requirement
116
- none: false
117
129
  requirements:
118
- - - ! '>='
130
+ - - ">="
119
131
  - !ruby/object:Gem::Version
120
132
  version: '0'
121
133
  requirements: []
122
134
  rubyforge_project: i18n_generators
123
- rubygems_version: 1.8.16
135
+ rubygems_version: 2.4.8
124
136
  signing_key:
125
- specification_version: 3
126
- summary: Generates I18n locale files for Rails 3 and Rails 2
137
+ specification_version: 4
138
+ summary: A Rails generator that generates Rails I18n locale files with automatic translation
139
+ for almost every known locale.
127
140
  test_files:
128
- - spec/data/cldr/ja.html
129
- - spec/data/yml/active_record/en-US.yml
130
- - spec/i18n_locale_command_spec.rb
131
- - spec/i18n_translation_command_spec.rb
132
- - spec/spec_helper.rb
133
- - spec/translator_spec.rb
134
- - spec/yaml_spec.rb
141
+ - test/data/cldr/ja.html
142
+ - test/data/yml/active_record/en-US.yml
143
+ - test/i18n_locale_command_test.rb
144
+ - test/i18n_translation_command_test.rb
145
+ - test/test_helper.rb
146
+ - test/translator_test.rb
147
+ - test/yaml_test.rb
data/README.rdoc DELETED
@@ -1,63 +0,0 @@
1
- = I18n generators
2
-
3
- This gem plugin generates a set of locale files for Rails i18n feature. Supports Rails 4.0, 3.2.x, 3.1.x, 3.0.x, 2.3.x and 2.2.x.
4
-
5
- * http://github.com/amatsuda/i18n_generators
6
- * http://rubygems.org/gems/i18n_generators
7
-
8
-
9
- == FEATURES
10
-
11
- This gem/plugin provides following generate commands.
12
-
13
- === 1. Generate Locale Files for ActiveRecord/ActiveSupport/ActionPack
14
-
15
- % rails g i18n_locale ja (de-AT, pt-BR, etc.)
16
-
17
- Downloads the .yml file for the specified locale from the official rails-i18n repository:
18
- https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale
19
-
20
- Then the generater sets the application default locale to the specified locale.
21
-
22
- This will generate following locale file.
23
-
24
- config/locales/ja.yml
25
-
26
- === 2. Generate Translation YAML File For All Models/Attributes
27
-
28
- % rails g i18n_translation ja (de-AT, pt-BR, etc.)
29
-
30
- This will generate following YAML file.
31
-
32
- config/locales/translation_ja.yml
33
-
34
- The generator scans your app/models directory, and generates a YAML file with all the AR model names and attributes so that you don't have to write the YAML skeleton manually or by copy/paste.
35
- In addition, the generator tries to translate each of them into the specified language.
36
- The generator doesn't overwrite the existing value so that you can rerun the generator again and again.
37
-
38
- === 3. Generate All
39
-
40
- % rails g i18n ja (de-AT, pt-BR, etc.)
41
-
42
- Executes 1 and 2 at once.
43
-
44
-
45
- == REQUIREMENTS:
46
-
47
- * Ruby 1.8.7, 1.9, 2.0
48
- * Ruby on Rails 4.0, 3.2, 3.1, 3.0
49
- * Ruby on Rails 2.3, 2.2 (supported by i18n_generators < 1.2)
50
-
51
-
52
- == INSTALL:
53
-
54
- * Rails 3 (with Bundler)
55
-
56
- Add 'i18n_generators' to your Gemfile, then `bundle`. Restricting the group to :development would be a good idea, since the generator would probably be used only in development mode.
57
-
58
- * Rails 2
59
-
60
- Use 'i18n_generators' version '< 1.2'.
61
-
62
-
63
- Copyright (c) 2008 Akira Matsuda, released under the MIT license
@@ -1,71 +0,0 @@
1
- require 'spec_helper'
2
- require 'generators/i18n_locale/i18n_locale_generator'
3
-
4
- describe I18nLocaleGenerator do
5
- subject { I18nLocaleGenerator.new(['ja']) }
6
-
7
- describe 'add_locale_config' do
8
- describe 'when i18n.default_locale is configured in environment.rb' do
9
- before do
10
- @config = "
11
- module Tes
12
- class Application < Rails::Application
13
- config.i18n.default_locale = :de
14
- end
15
- end"
16
- end
17
-
18
- it 'rewrites the existing default_locale to locale_name value' do
19
- subject.send(:add_locale_config, @config).should == "
20
- module Tes
21
- class Application < Rails::Application
22
- config.i18n.default_locale = 'ja'
23
- end
24
- end"
25
- end
26
- end
27
-
28
- describe 'when i18n.default_locale config is commented in environment.rb' do
29
- before do
30
- @config = "
31
- module Tes
32
- class Application < Rails::Application
33
- # config.i18n.default_locale = :de
34
- end
35
- end"
36
- end
37
-
38
- it 'uncomments the existing commented i18n config and sets locale_name value' do
39
- subject.send(:add_locale_config, @config).should == "
40
- module Tes
41
- class Application < Rails::Application
42
- config.i18n.default_locale = 'ja'
43
- end
44
- end"
45
- end
46
- end
47
-
48
- describe 'when i18n.default_locale is not written in environment.rb' do
49
- before do
50
- @config = "
51
- module Tes
52
- class Application < Rails::Application
53
- something goes here.
54
- bla bla bla...
55
- end
56
- end"
57
- end
58
-
59
- it 'adds the default_locale config inside the config block and sets locale_name value' do
60
- subject.send(:add_locale_config, @config).should == "
61
- module Tes
62
- class Application < Rails::Application
63
- config.i18n.default_locale = 'ja'
64
- something goes here.
65
- bla bla bla...
66
- end
67
- end"
68
- end
69
- end
70
- end
71
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
- require 'generators/i18n_translation/i18n_translation_generator'
3
-
4
- describe I18nTranslationGenerator do
5
- subject { I18nTranslationGenerator.new(['ja']) }
6
-
7
- describe 'each_value' do
8
- xit 'iterates through each value' do
9
- hash = ActiveSupport::OrderedHash.new
10
- hash[:parent1] = ActiveSupport::OrderedHash.new
11
- hash[:parent1][:child1] = 'child one'
12
- hash[:parent2] = ActiveSupport::OrderedHash.new
13
- hash[:parent2][:child2] = 'child two'
14
- hash[:parent2][:child3] = 'child three'
15
- subject.send(:each_value, [], hash) do |parents, value|
16
- p "#{parents.join('.')} #{value}"
17
- end
18
- end
19
- end
20
- end
data/spec/spec_helper.rb DELETED
@@ -1,15 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rails'
4
- require 'rails/generators'
5
-
6
- # Requires supporting files with custom matchers and macros, etc,
7
- # in ./support/ and its subdirectories.
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
-
10
- Rails.logger ||= Logger.new STDOUT
11
-
12
- RSpec.configure do |config|
13
- # config.mock_with :rr
14
- config.mock_with :rspec
15
- end
@@ -1,39 +0,0 @@
1
- # coding: utf-8
2
- $KCODE = 'U'
3
-
4
- require 'spec_helper'
5
- require 'generators/i18n_translation/lib/translator'
6
-
7
- describe I27r::Translator do
8
- subject { I27r::Translator.new 'ja' }
9
-
10
- describe 'when successfully translated' do
11
- before do
12
- subject.stub!(:_translate).and_return('こんにちは')
13
- end
14
-
15
- it 'returns translated text' do
16
- subject.translate('hello').should == 'こんにちは'
17
- end
18
- end
19
-
20
- describe 'when translation failed with error code' do
21
- before do
22
- subject.stub!(:_translate).and_return('')
23
- end
24
-
25
- it 'returns the original text' do
26
- subject.translate('hello').should == 'hello'
27
- end
28
- end
29
-
30
- describe 'when translation raised an error' do
31
- before do
32
- subject.stub!(:_translate).and_raise('ERROR!')
33
- end
34
-
35
- it 'returns the original text' do
36
- subject.translate('hello').should == 'hello'
37
- end
38
- end
39
- end
data/spec/yaml_spec.rb DELETED
@@ -1,124 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
- require 'generators/i18n_translation/lib/yaml'
4
-
5
- describe I27r::YamlDocument do
6
- context 'when loading an existing file' do
7
- before do
8
- @yaml_string = <<YAML
9
- ja:
10
- hoge:
11
- fuga: piyo #g
12
- numbers:
13
- one: "いち" #g
14
- two: "に"
15
-
16
- aaa:
17
- foo: "ふー"
18
- bar: "ばー"
19
- YAML
20
- @yaml = I27r::YamlDocument.new @yaml_string
21
- end
22
-
23
- subject { @yaml }
24
- it { should be }
25
-
26
- its(:to_s) { should == @yaml_string }
27
-
28
- describe '[]' do
29
- specify '[]' do
30
- @yaml['ja', 'hoge', 'fuga'].should == 'piyo'
31
- @yaml[['ja', 'hoge', 'fuga']].should == 'piyo'
32
- end
33
- end
34
-
35
- describe 'find_line_by_path' do
36
- subject { @yaml.find_line_by_path(['ja', 'hoge', 'fuga']) }
37
- its(:value) { should == 'piyo' }
38
- end
39
-
40
- describe 'find_line_by_path' do
41
- subject { @yaml.find_line_by_path(['ja', 'aho', 'hage'], -1, true) }
42
- it { should be }
43
- its(:key) { should == 'hage' }
44
- its(:value) { should_not be }
45
- end
46
-
47
- describe '[]=' do
48
- context 'rewriting an existing value' do
49
- before { @yaml['ja', 'hoge', 'fuga'] = 'puyo' }
50
- subject { @yaml['ja', 'hoge', 'fuga'] }
51
- it { should == 'puyo' }
52
- end
53
-
54
- context 'an existing value without #g mark' do
55
- before { @yaml['ja', 'hoge', 'numbers', 'two'] = 'ツー' }
56
- subject { @yaml['ja', 'hoge', 'numbers', 'two'] }
57
- it { should == 'に' }
58
- end
59
-
60
- context 'creating a new node in the middle' do
61
- before { @yaml['ja', 'hoge', 'numbers', 'three'] = 'さん' }
62
- subject { @yaml['ja', 'hoge', 'numbers', 'three'] }
63
- it { should == 'さん' }
64
- specify do
65
- @yaml.to_s.should == <<YAML
66
- ja:
67
- hoge:
68
- fuga: piyo #g
69
- numbers:
70
- one: "いち" #g
71
- two: "に"
72
- three: さん #g
73
-
74
- aaa:
75
- foo: "ふー"
76
- bar: "ばー"
77
- YAML
78
- end
79
- end
80
-
81
- context 'creating a new node at the bottom' do
82
- before { @yaml['ja', 'aho', 'hage'] = 'hige' }
83
- subject { @yaml['ja', 'aho', 'hage'] }
84
- it { should == 'hige' }
85
- end
86
- end
87
- end
88
-
89
- context 'when loading an existing file with alias' do
90
- before do
91
- pending
92
- @yaml_string = <<YAML
93
- ja:
94
- activerecord:
95
- attributes:
96
- hoge: &hoge
97
- foo: FOO
98
- bar: BAR
99
- hoge2: &hoge2
100
- hoge:
101
- <<: *hogege
102
- YAML
103
- @yaml = I27r::YamlDocument.new @yaml_string
104
- @yaml['ja', 'activerecord', 'hoge2', 'hoge'] = 'foo'
105
- end
106
-
107
- specify '' do
108
- puts @yaml.to_s
109
- end
110
- end
111
-
112
- context 'creating a new file' do
113
- before do
114
-
115
- end
116
-
117
- specify 'that' do
118
- yaml = I27r::YamlDocument.new
119
- yaml['ja', 'hoge', 'fuga'] = 'piyo'
120
- yaml['ja', 'hoge', 'foo'] = 'bar'
121
- puts yaml
122
- end
123
- end
124
- end