amatsuda-i18n_generators 0.4.1 → 0.5.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.
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ == 0.5.0
2
+
3
+ * bugfixes:
4
+ * Could not fetch the locale files via GitHub (GitHub changed the URL?)
5
+ * major enhancements:
6
+ * Ruby 1.9 ready!
7
+ * Never connect to CLDR site when the locale file found in Sven's rails-i18n repository
8
+ * enhancements:
9
+ * Use Ruby 1.9 built-in JSON parser if Ruby 1.9
10
+
1
11
  == 0.4.1
2
12
 
3
13
  * bugfixes:
@@ -66,7 +66,7 @@ class I18nGenerator < Rails::Generator::NamedBase
66
66
  private
67
67
  def defined_in_rails_i18n_repository?
68
68
  begin
69
- uri = "http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/#{locale_name}.yml"
69
+ uri = "http://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/#{locale_name}.yml"
70
70
  OpenURI.open_uri(uri) do |res|
71
71
  (res.base_uri.to_s == uri) && (res.status == %w[200 OK])
72
72
  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/tree/master/rails/locale/#{locale_name}.yml?raw=true").read
28
+ OpenURI.open_uri("http://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/#{locale_name}.yml?raw=true").read
29
29
  end
30
30
  end
31
31
 
@@ -1,15 +1,14 @@
1
+ # encoding: utf-8
1
2
  $KCODE = 'U'
2
3
 
3
4
  require 'open-uri'
4
5
 
5
6
  module I18nLocaleGeneratorModule
6
7
  class CldrDocument
8
+ extend ActiveSupport::Memoizable
9
+
7
10
  def initialize(locale_name)
8
11
  @locale_name = locale_name
9
- @summaries = [load_cldr_data(locale_name.tr('-', '_'))]
10
- if locale_name =~ /^[a-zA-Z]{2}[-_][a-zA-Z]{2}$/
11
- @summaries << load_cldr_data(locale_name.to(1))
12
- end
13
12
  end
14
13
 
15
14
  def lookup(path)
@@ -98,6 +97,14 @@ module I18nLocaleGeneratorModule
98
97
  end
99
98
 
100
99
  private
100
+ def summaries
101
+ s = [load_cldr_data(@locale_name.tr('-', '_'))]
102
+ if @locale_name =~ /^[a-zA-Z]{2}[-_][a-zA-Z]{2}$/
103
+ s << load_cldr_data(@locale_name.to(1))
104
+ end
105
+ end
106
+ memoize :summaries
107
+
101
108
  def load_cldr_data(locale_name)
102
109
  cldr = begin
103
110
  OpenURI.open_uri("http://www.unicode.org/cldr/data/charts/summary/#{locale_name}.html").read
@@ -105,13 +112,15 @@ module I18nLocaleGeneratorModule
105
112
  puts "WARNING: Couldn't find locale data for #{locale_name} on the web."
106
113
  ''
107
114
  end
108
- cldr.split("\n").grep(/^<tr>/).delete_if {|r| r =~ /^<tr><td>\d*<\/td><td class='[gn]'>names<\/td>/}
115
+ lines = cldr.split("\n").grep(/^<tr>/)
116
+ lines.delete_if {|r| r =~ /^<tr><td>\d*<\/td><td class='[gn]'>names<\/td>/}
117
+ 'Ruby 1.9'.respond_to?(:force_encoding) ? lines.map {|l| l.force_encoding 'UTF-8'} : lines
109
118
  end
110
119
 
111
120
  def search(n1, n2, g)
112
121
  pattern = Regexp.new /<tr><td>\d*<\/td><td class='[ng]'>#{Regexp.quote(n1)}<\/td><td class='[ng]'>#{Regexp.quote(n2)}<\/td><td class='[ng]'>#{Regexp.quote(g)}<\/td>/
113
122
  extract_pattern = /<td class='v'>(?:<span.*?>)?(.*?)(?:<\/span>)?<\/td><td>/
114
- @summaries.each do |summary|
123
+ summaries.each do |summary|
115
124
  _, value = *extract_pattern.match(summary.grep(pattern).first)
116
125
  return value unless value.nil?
117
126
  end
@@ -29,7 +29,7 @@ module I18nGenerator::Generator
29
29
  logger.debug "#{models.size} models found."
30
30
 
31
31
  # pick all translated keywords from view files
32
- original_backend = I18n.backend
32
+ original_backend = I18n.backend.dup
33
33
  I18n.backend = RecordingBackend.new
34
34
 
35
35
  Dir["#{RAILS_ROOT}/app/views/**/*.erb"].each do |f|
@@ -11,23 +11,19 @@ module I18nTranslationGeneratorModule
11
11
  include ActionView::Helpers::TranslationHelper
12
12
  include I18nTranslationGeneratorModule::ThroughRyoku
13
13
 
14
- nil.class_eval do
15
- def method_missing(method, *args, &block); nil; end
16
- end
17
-
18
14
  fname = '#{filename}'
19
15
  erb = nil
20
16
  File.open(fname) {|f| erb = ERB.new(f.read, nil, '-') }
21
17
  erb.def_method(self, 'execute', fname)
22
18
  end
23
19
  EOS
20
+ nil.class_eval {def method_missing(method, *args, &block); nil; end}
24
21
  m.const_get('Executer').new.execute { }
25
- nil.class_eval do
26
- undef :method_missing
27
- end
28
22
  rescue => e
29
23
  p e
30
24
  # do nothing
25
+ ensure
26
+ nil.class_eval {undef :method_missing} if nil.respond_to? :method_missing
31
27
  end
32
28
  end
33
29
  end
@@ -8,7 +8,7 @@ module I18nTranslationGeneratorModule
8
8
 
9
9
  def translate(locale, key, options = {})
10
10
  # @keys << key.to_sym
11
- @keys << (Array(options[:scope]) + [key]).map.flatten.join('.')
11
+ @keys << (Array(options[:scope]) + [key]).flatten.join('.')
12
12
  end
13
13
  alias :t :translate
14
14
  end
@@ -1,4 +1,5 @@
1
1
  require 'open-uri'
2
+ require 'json' if RUBY_VERSION >= '1.9'
2
3
 
3
4
  module I18nTranslationGeneratorModule
4
5
  class Translator
@@ -11,7 +12,11 @@ module I18nTranslationGeneratorModule
11
12
  begin
12
13
  w = CGI.escape ActiveSupport::Inflector.humanize(word)
13
14
  json = OpenURI.open_uri("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=#{w}&langpair=en%7C#{@lang}").read
14
- result = ActiveSupport::JSON.decode(json)
15
+ result = if RUBY_VERSION >= '1.9'
16
+ ::JSON.parse json
17
+ else
18
+ ActiveSupport::JSON.decode(json)
19
+ end
15
20
  result['responseStatus'] == 200 ? (@cache[word] = result['responseData']['translatedText']) : word
16
21
  rescue => e
17
22
  puts %Q[failed to translate "#{word}" into "#{@lang}" language.]
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.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-21 00:00:00 -08:00
12
+ date: 2009-02-15 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gettext
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -21,7 +22,7 @@ dependencies:
21
22
  - !ruby/object:Gem::Version
22
23
  version: "0"
23
24
  version:
24
- description: A Rails generator plugin & gem that generates Rails 2.2 I18n locale files for almost every known locale.
25
+ description: A Rails generator plugin & gem that generates Rails 2.2 and 2.3 I18n locale files for almost every known locale.
25
26
  email: ronnie@dio.jp
26
27
  executables: []
27
28
 
@@ -94,6 +95,6 @@ rubyforge_project:
94
95
  rubygems_version: 1.2.0
95
96
  signing_key:
96
97
  specification_version: 2
97
- summary: Generates I18n locale files for Rails 2.2
98
+ summary: Generates I18n locale files for Rails 2.2 and 2.3
98
99
  test_files: []
99
100