gettext_rails 2.0.0 → 2.0.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 (48) hide show
  1. data/ChangeLog +9 -0
  2. data/README.rdoc +3 -7
  3. data/Rakefile +4 -4
  4. data/lib/gettext_rails/action_mailer.rb +1 -1
  5. data/lib/gettext_rails/action_view/active_record_helper.rb +8 -3
  6. data/lib/gettext_rails/version.rb +1 -2
  7. data/sample/app/controllers/application_controller.rb +6 -4
  8. data/test/Rakefile +1 -0
  9. data/test/app/controllers/articles_controller.rb +0 -16
  10. data/test/app/controllers/users_controller.rb +6 -6
  11. data/test/app/views/users/error_message.html.erb +50 -0
  12. data/test/app/views/users/{custom_error_message_fr.html.erb → error_message_fr.html.erb} +0 -8
  13. data/test/config/environment.rb +0 -1
  14. data/test/config/routes.rb +1 -6
  15. data/test/locale/ja/LC_MESSAGES/rails_test.mo +0 -0
  16. data/test/po/ja/rails_test.po +4 -4
  17. data/test/public/index.html +1 -3
  18. data/test/test/functional/articles_controller_test.rb +0 -16
  19. data/test/test/functional/users_controller_test.rb +10 -22
  20. data/test/test/result/en/error_message.html +46 -0
  21. data/test/test/result/fr/error_message.html +16 -0
  22. data/test/test/result/ja/error_message.html +46 -0
  23. metadata +14 -50
  24. data/replace.rb +0 -21
  25. data/sample/db/development.sqlite3 +0 -0
  26. data/sample/db/production.sqlite3 +0 -0
  27. data/sample/db/test.sqlite3 +0 -0
  28. data/sample/log/development.log +0 -635
  29. data/sample/log/production.log +0 -79475
  30. data/sample/log/test.log +0 -1592
  31. data/sample/test/result/en/list.html +0 -69
  32. data/test/app/views/articles/change_title_error_messages_for.html.erb +0 -15
  33. data/test/app/views/articles/multi_error_messages_for.html.erb +0 -19
  34. data/test/app/views/users/custom_error_message.html.erb +0 -13
  35. data/test/db/development.sqlite3 +0 -0
  36. data/test/db/test.sqlite3 +0 -0
  37. data/test/log/development.log +0 -1284
  38. data/test/log/test.log +0 -5595
  39. data/test/test/result/en/change_title_error_messages_for.html +0 -89
  40. data/test/test/result/en/custom_error_message.html +0 -84
  41. data/test/test/result/en/custom_error_message_with_plural.html +0 -84
  42. data/test/test/result/en/multi_error_messages_for.html +0 -155
  43. data/test/test/result/fr/custom_error_message.html +0 -84
  44. data/test/test/result/fr/custom_error_message_with_plural.html +0 -84
  45. data/test/test/result/ja/change_title_error_messages_for.html +0 -89
  46. data/test/test/result/ja/custom_error_message.html +0 -84
  47. data/test/test/result/ja/custom_error_message_with_plural.html +0 -84
  48. data/test/test/result/ja/multi_error_messages_for.html +0 -155
data/ChangeLog CHANGED
@@ -1,3 +1,12 @@
1
+ = gettext_rails-2.0.1 (2009-04-18)
2
+ * Fix bugs
3
+ * ActionMailer didn't work. [Reported by Simone Carletti]
4
+ * error_messages_for doesn't have compatibility with original method. [by
5
+ Adam Ilan]
6
+
7
+ Thanks to:
8
+ Simone Carletti, Adam Ilan
9
+
1
10
  = gettext_rails-2.0.0 (2009-03-22)
2
11
 
3
12
  * Support Rails-2.3.2.
data/README.rdoc CHANGED
@@ -30,17 +30,12 @@ using Ruby-GetText-Package.
30
30
  (sudo/su on POSIX system)
31
31
  gem uninstall gettext
32
32
 
33
- #from github (edge/unstable)
33
+ #from github (edge/unstable) (not supported yet)
34
34
  (sudo/su on POSIX system)
35
- gem install gettext
36
- gem install gettext_activerecord
37
- gem install gettext_rails
38
- gem install mutoh-gettext_rails -s http://gems.github.com/
35
+ #gem install mutoh-gettext_rails -s http://gems.github.com/
39
36
 
40
37
  #from rubyforge (stable)
41
38
  (sudo/su on POSIX system)
42
- gem install gettext
43
- gem install gettext_activerecord
44
39
  gem install gettext_rails
45
40
 
46
41
  == Usage
@@ -89,6 +84,7 @@ end
89
84
  See {Ruby-GetText-Package HOWTO for Ruby on Rails}[http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html] for more details.
90
85
 
91
86
  == Support matrix
87
+ * gettext_rails-2.0.1 - rails-2.3.2
92
88
  * gettext_rails-2.0.0 - rails-2.3.2
93
89
 
94
90
  == License
data/Rakefile CHANGED
@@ -71,8 +71,8 @@ spec = Gem::Specification.new do |s|
71
71
  s.homepage = 'http://gettext.rubyforge.org/'
72
72
  s.rubyforge_project = "gettext"
73
73
  s.files = FileList['**/*'].to_a.select{|v| v !~ /pkg|git/}
74
- s.add_dependency('gettext_activerecord', '>= 2.0.0')
75
- s.add_dependency('locale_rails', '>= 2.0.0')
74
+ s.add_dependency('gettext_activerecord', '>= 2.0.1')
75
+ s.add_dependency('locale_rails', '>= 2.0.1')
76
76
  s.add_dependency('rails', '>= 2.3.2')
77
77
  s.require_path = 'lib'
78
78
  s.has_rdoc = true
@@ -94,13 +94,13 @@ Rake::RDocTask.new { |rdoc|
94
94
  rdoc.rdoc_dir = 'doc'
95
95
  rdoc.title = "gettext_rails API Reference"
96
96
  rdoc.options << '--line-numbers' << '--inline-source'
97
- rdoc.rdoc_files.include('README', 'ChangeLog')
97
+ rdoc.rdoc_files.include('README.rdoc', 'ChangeLog')
98
98
  rdoc.rdoc_files.include('lib/**/*.rb')
99
99
  rdoc.template = allison if allison.size > 0
100
100
  }
101
101
 
102
102
  desc "Publish the release files to RubyForge."
103
- task :release => [ :package ] do
103
+ task :release => [:makemo, :package ] do
104
104
  require 'rubyforge'
105
105
 
106
106
  rubyforge = RubyForge.new
@@ -27,7 +27,7 @@ if defined? ActionMailer
27
27
  end
28
28
 
29
29
  def create_with_gettext!(*arg) #:nodoc:
30
- create_bang_without_gettext(*arg)
30
+ create_without_gettext!(*arg)
31
31
  if Locale.get.language == "ja"
32
32
  require 'nkf'
33
33
  @mail.subject = base64(@mail.subject)
@@ -66,6 +66,9 @@ module ActionView #:nodoc:
66
66
  if key.kind_of? Symbol
67
67
  msgids = @@error_message_headers[key]
68
68
  else
69
+ key << key[0] if (key.is_a?(Array) && key.length==1)
70
+ key = [key, key] if key.is_a? String
71
+
69
72
  msgids = key
70
73
  end
71
74
 
@@ -79,14 +82,15 @@ module ActionView #:nodoc:
79
82
  end
80
83
 
81
84
  end
85
+
82
86
  def error_messages_for_with_gettext_rails(*params) #:nodoc:
83
87
  models = params.select{|param| ! param.kind_of? Hash}
84
88
  options = params.extract_options!.symbolize_keys
85
89
 
86
- header_message = options[:header_message] || options[:message_title] || :header
87
- message = options[:message] || options[:message_explanation] || :body
90
+ header_message = (options.has_key?(:header_message) || options.has_key?(:message_title)) ? (options[:header_message] || options[:message_title]) : (:header)
91
+ message = (options.has_key?(:message) || options.has_key?(:message_explanation)) ? (options[:message] || options[:message_explanation]) : (:body)
88
92
 
89
- object = options.delete(:object)
93
+ object = options[:object]
90
94
  if object
91
95
  objects = [object].flatten
92
96
  else
@@ -97,6 +101,7 @@ module ActionView #:nodoc:
97
101
  options[:object_name] ||= params.first
98
102
  normalized_model = options[:object_name].to_s.gsub('_', ' ')
99
103
 
104
+ #accept nil's as messages to hide message
100
105
  options[:header_message] = L10n.error_message(header_message, normalized_model, count)
101
106
  options[:message] = L10n.error_message(message, normalized_model, count)
102
107
 
@@ -1,4 +1,3 @@
1
- #! /usr/bin/ruby
2
1
  =begin
3
2
  version - version information of Ruby-GetText-Package
4
3
 
@@ -10,5 +9,5 @@
10
9
 
11
10
  module GetTextRails
12
11
  RAILS_VERSION = "2.3.2"
13
- VERSION = "2.0.0"
12
+ VERSION = "2.0.1"
14
13
  end
@@ -18,16 +18,18 @@ class ApplicationController < ActionController::Base
18
18
 
19
19
  I18n.supported_locales = Dir[ File.join(RAILS_ROOT, 'locale/*') ].collect{|v| File.basename(v)}
20
20
 
21
- =begin
22
21
  # You can set callback methods. These methods are called on the each WWW request.
23
- def before_init_gettext(cgi)
22
+ =begin
23
+ def sample_before_init_gettext
24
24
  p "before_init_gettext"
25
+ set_locale "zh" # Set locale forcely.
25
26
  end
26
- def after_init_gettext(cgi)
27
+ before_init_gettext :sample_before_init_gettext
28
+ def sample_after_init_gettext
27
29
  p "after_init_gettext"
28
30
  end
31
+ after_init_gettext :sample_after_init_gettext
29
32
  =end
30
-
31
33
  =begin
32
34
  # you can redefined the title/explanation of the top of the error message.
33
35
  ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_title(N_("An error is occured on %{record}"), N_("%{num} errors are occured on %{record}"))
data/test/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
+ $LOAD_PATH.unshift "../lib"
4
5
  $LOAD_PATH.unshift "../../lib"
5
6
  require(File.join(File.dirname(__FILE__), 'config', 'boot'))
6
7
 
@@ -95,20 +95,4 @@ class ArticlesController < ApplicationController
95
95
  format.xml { head :ok }
96
96
  end
97
97
  end
98
-
99
- def multi_error_messages_for
100
- @user = User.new
101
- @user.lastupdate = Date.new(2007, 4, 1)
102
- @article = Article.new
103
- @article.lastupdate = Date.new(2007, 4, 1)
104
- @user.valid?
105
- @article.valid?
106
- end
107
-
108
- def change_title_error_messages_for
109
- @article = Article.new
110
- @article.lastupdate = Date.new(2007, 4, 1)
111
- @article.valid?
112
- end
113
-
114
98
  end
@@ -1,14 +1,14 @@
1
1
  class UsersController < ApplicationController
2
- def custom_error_message
2
+ def error_message
3
3
  @user = User.new
4
4
  @user.name = "foo"
5
- unless params[:plural]
6
- @user.lastupdate = "2007-01-01"
7
- end
8
- @user.valid?
9
5
  @user.lastupdate = "2007-01-01"
10
- end
6
+ @user.valid?
11
7
 
8
+ @article = Article.new
9
+ @article.valid?
10
+ end
11
+
12
12
  def distance_of_time_in_words
13
13
  end
14
14
 
@@ -0,0 +1,50 @@
1
+ <h2>Singular message</h2>
2
+ <%= error_messages_for 'user' %>
3
+
4
+ <h2>Plural messages</h2>
5
+ <%= error_messages_for 'article' %>
6
+
7
+ <h2>Multi object</h2>
8
+ <%= error_messages_for 'article', 'user' %>
9
+
10
+ <h2>Multi object with :object_name</h2>
11
+ <%= error_messages_for 'article', 'user', :object_name => _("Contents") %>
12
+
13
+ <h2>Multi object with :object</h2>
14
+ <%= error_messages_for :object => [@article, @user] %>
15
+
16
+ <h2>Change header with gettext options</h2>
17
+ <%= error_messages_for 'user', {
18
+ :message_title => Nn_("Singular Custom Error message %{record}: %{num}", "Plural Custom Error message %{record}: %{num}"),
19
+ :message_explanation => Nn_("Singular Custom Error explanation %{num}", "Plural Custom Error explanation %{num}")
20
+ } %>
21
+
22
+ <h2>Same result with Rails options</h2>
23
+ <%= error_messages_for 'user', {
24
+ :header_message => Nn_("Singular Custom Error message %{record}: %{num}", "Plural Custom Error message %{record}: %{num}"),
25
+ :message => Nn_("Singular Custom Error explanation %{num}", "Plural Custom Error explanation %{num}")
26
+ } %>
27
+
28
+ <h2>nil header</h2>
29
+ <%= error_messages_for 'user', {
30
+ :header_message => nil,
31
+ :message => Nn_("Singular Custom Error explanation %{num}", "Plural Custom Error explanation %{num}")
32
+ } %>
33
+
34
+ <h2>nil message</h2>
35
+ <%= error_messages_for 'user', {
36
+ :header_message => Nn_("Singular Custom Error message %{record}: %{num}", "Plural Custom Error message %{record}: %{num}"),
37
+ :message => nil
38
+ } %>
39
+
40
+ <h2>nil header message and nil message</h2>
41
+ <%= error_messages_for 'user', {
42
+ :header_message => nil,
43
+ :message => nil
44
+ } %>
45
+
46
+ <h2>String header message</h2>
47
+ <%= error_messages_for 'user', {
48
+ :header_message => "String Header Message",
49
+ :message => "String Message"
50
+ } %>
@@ -3,11 +3,3 @@
3
3
  :message_explanation => Nn_("French: Singular Custom Error explanation %{num}", "French: Plural Custom Error explanation %{num}")
4
4
  } %>
5
5
 
6
- <!--[form:article]-->
7
- <p><label for="user_name"><%= _("Name") %></label><br/>
8
- <%= text_field 'user', 'name' %></p>
9
-
10
- <p><label for="user_lastupdate"><%= _("Lastupdate") %></label><br/>
11
- <%= date_select 'user', 'lastupdate' %></p>
12
- <!--[eoform:article]-->
13
-
@@ -42,4 +42,3 @@ Rails::Initializer.run do |config|
42
42
  config.gem "gettext_activerecord"
43
43
  config.gem "gettext_rails"
44
44
  end
45
-
@@ -1,10 +1,5 @@
1
1
  ActionController::Routing::Routes.draw do |map|
2
- # map.resources :articles
3
-
4
- map.resources :articles, :collection => {:multi_error_messages_for => :get,
5
- :change_title_error_messages_for => :get,
6
- :distance_of_time_in_words => :get,
7
- }
2
+ map.resources :articles
8
3
 
9
4
  map.connect ':controller/:action/:id'
10
5
  map.connect ':controller/:action/:id.:format'
@@ -97,8 +97,8 @@ msgstr[1] "複数形カスタムエラーメッセージ (%{record}: %{num})"
97
97
  #: app/views/users/custom_error_message_fr.html.erb:3
98
98
  msgid "French: Singular Custom Error explanation %{num}"
99
99
  msgid_plural "French: Plural Custom Error explanation %{num}"
100
- msgstr[0] "単数形カスタムエラーメッセージ (%{num})"
101
- msgstr[1] "複数形カスタムエラーメッセージ (%{num})"
100
+ msgstr[0] "単数形カスタムエラー説明 (%{num})"
101
+ msgstr[1] "複数形カスタムエラー説明 (%{num})"
102
102
 
103
103
  #: app/views/users/custom_error_message_fr.html.erb:7
104
104
  #: app/views/users/custom_error_message.html.erb:7
@@ -124,8 +124,8 @@ msgstr[1] "複数形カスタムエラーメッセージ (%{record}: %{num})"
124
124
  #: app/views/users/custom_error_message.html.erb:3
125
125
  msgid "Singular Custom Error explanation %{num}"
126
126
  msgid_plural "Plural Custom Error explanation %{num}"
127
- msgstr[0] "単数形カスタムエラーメッセージ (%{num})"
128
- msgstr[1] "複数形カスタムエラーメッセージ (%{num})"
127
+ msgstr[0] "単数形カスタムエラー説明 (%{num})"
128
+ msgstr[1] "複数形カスタムエラー説明 (%{num})"
129
129
 
130
130
  #: app/views/articles/edit.html.erb:1
131
131
  msgid "Editing article"
@@ -10,9 +10,7 @@
10
10
  <h2>General tests</h1>
11
11
  <dl>
12
12
  <li><a href="/articles">Articles CRUD Test</a></li>
13
- <li><a href="/articles/multi_error_messages_for">Multi Error messages</a></li>
14
- <li><a href="/articles/change_title_error_messages_for">Custom Title messages</a></li>
15
- <li><a href="/users/custom_error_message">Custom error message</a></li>
13
+ <li><a href="/users/error_message">error_message_for tests</a></li>
16
14
  <li><a href="/users/distance_of_time_in_words">Distance of time in words</a></li>
17
15
  </dl>
18
16
  <h2>ActionMailer tests</h1>
@@ -50,22 +50,6 @@ class ArticlesControllerTest < ActionController::TestCase
50
50
  assert_html("en/create_error.html")
51
51
  end
52
52
 
53
- test "should be shown multi error messages" do
54
- post :multi_error_messages_for, :article => {:article_title => "", :article_description => "", :user_name => ""}, :lang => "ja"
55
- assert_html("ja/multi_error_messages_for.html")
56
-
57
- post :multi_error_messages_for, :article => {:article_title => "", :article_description => "", :user_name => ""}, :lang => "en"
58
- assert_html("en/multi_error_messages_for.html")
59
- end
60
-
61
- test "should be shown with custom error message title" do
62
- get :change_title_error_messages_for, :lang => "ja"
63
- assert_html("ja/change_title_error_messages_for.html")
64
-
65
- get :change_title_error_messages_for, :lang => "en"
66
- assert_html("en/change_title_error_messages_for.html")
67
- end
68
-
69
53
  test "should show article" do
70
54
  get :show, :id => 1, :lang => "ja"
71
55
 
@@ -1,33 +1,21 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class UsersControllerTest < ActionController::TestCase
4
- test "should get custom_error_message" do
5
- get :custom_error_message, :lang => "ja"
6
- assert_html("ja/custom_error_message.html")
4
+ test "should get error_message" do
5
+ get :error_message, :lang => "ja"
6
+ assert_html("ja/error_message.html")
7
7
  assert_response :success
8
8
 
9
- get :custom_error_message, :lang => "en"
10
- assert_html("en/custom_error_message.html")
9
+ get :error_message, :lang => "en"
10
+ assert_html("en/error_message.html")
11
11
 
12
12
  # not match
13
- get :custom_error_message, :lang => "kr"
14
- assert_html("en/custom_error_message.html")
13
+ get :error_message, :lang => "kr"
14
+ assert_html("en/error_message.html")
15
15
 
16
- # custom_error_message_fr.html.erb
17
- get :custom_error_message, :lang => "fr"
18
- assert_html("fr/custom_error_message.html")
19
- end
20
-
21
- test "should get custom plural error_messages" do
22
- get :custom_error_message, :lang => "ja", :plural => "true"
23
- assert_html("ja/custom_error_message_with_plural.html")
24
- assert_response :success
25
-
26
- get :custom_error_message, :lang => "en", :plural => "true"
27
- assert_html("en/custom_error_message_with_plural.html")
28
-
29
- get :custom_error_message, :lang => "fr", :plural => "true"
30
- assert_html("fr/custom_error_message_with_plural.html")
16
+ # error_message_fr.html.erb
17
+ get :error_message, :lang => "fr"
18
+ assert_html("fr/error_message.html")
31
19
  end
32
20
 
33
21
  test "should get localized distance_of_time_in_words" do
@@ -0,0 +1,46 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
4
+ <title>Ruby-GetText-Package Test Application</title>
5
+ <link href="/stylesheets/scaffold.css" media="screen" rel="Stylesheet" type="text/css" />
6
+ </head>
7
+ <body>
8
+ <p style="color: green"></p>
9
+
10
+ <h2>Singular message</h2>
11
+ <div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this user from being saved</h2><p>There was a problem with the following field:</p><ul><li>Name is too short (minimum is 10 characters)</li></ul></div>
12
+
13
+ <h2>Plural messages</h2>
14
+ <div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this article from being saved</h2><p>There were problems with the following fields:</p><ul><li>Title can't be blank</li><li>Description is too short (minimum is 3 characters)</li></ul></div>
15
+
16
+ <h2>Multi object</h2>
17
+ <div class="errorExplanation" id="errorExplanation"><h2>3 errors prohibited this article from being saved</h2><p>There were problems with the following fields:</p><ul><li>Title can't be blank</li><li>Description is too short (minimum is 3 characters)</li><li>Name is too short (minimum is 10 characters)</li></ul></div>
18
+
19
+ <h2>Multi object with :object_name</h2>
20
+ <div class="errorExplanation" id="errorExplanation"><h2>3 errors prohibited this Contents from being saved</h2><p>There were problems with the following fields:</p><ul><li>Title can't be blank</li><li>Description is too short (minimum is 3 characters)</li><li>Name is too short (minimum is 10 characters)</li></ul></div>
21
+
22
+ <h2>Multi object with :object</h2>
23
+ <div class="errorExplanation" id="errorExplanation"><h2>3 errors prohibited this from being saved</h2><p>There were problems with the following fields:</p><ul><li>Title can't be blank</li><li>Description is too short (minimum is 3 characters)</li><li>Name is too short (minimum is 10 characters)</li></ul></div>
24
+
25
+ <h2>Change header with gettext options</h2>
26
+ <div class="errorExplanation" id="errorExplanation"><h2>Singular Custom Error message user: 1</h2><p>Singular Custom Error explanation 1</p><ul><li>Name is too short (minimum is 10 characters)</li></ul></div>
27
+
28
+ <h2>Same result with Rails options</h2>
29
+ <div class="errorExplanation" id="errorExplanation"><h2>Singular Custom Error message user: 1</h2><p>Singular Custom Error explanation 1</p><ul><li>Name is too short (minimum is 10 characters)</li></ul></div>
30
+
31
+ <h2>nil header</h2>
32
+ <div class="errorExplanation" id="errorExplanation"><p>Singular Custom Error explanation 1</p><ul><li>Name is too short (minimum is 10 characters)</li></ul></div>
33
+
34
+ <h2>nil message</h2>
35
+ <div class="errorExplanation" id="errorExplanation"><h2>Singular Custom Error message user: 1</h2><ul><li>Name is too short (minimum is 10 characters)</li></ul></div>
36
+
37
+ <h2>nil header message and nil message</h2>
38
+ <div class="errorExplanation" id="errorExplanation"><ul><li>Name is too short (minimum is 10 characters)</li></ul></div>
39
+
40
+ <h2>String header message</h2>
41
+ <div class="errorExplanation" id="errorExplanation"><h2>String Header Message</h2><p>String Message</p><ul><li>Name is too short (minimum is 10 characters)</li></ul></div>
42
+
43
+
44
+ <a href="/">Back to Top</a>
45
+ </body>
46
+ </html>
@@ -0,0 +1,16 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
4
+ <title>Ruby-GetText-Package Test Application</title>
5
+ <link href="/stylesheets/scaffold.css" media="screen" rel="Stylesheet" type="text/css" />
6
+ </head>
7
+ <body>
8
+ <p style="color: green"></p>
9
+
10
+ <div class="errorExplanation" id="errorExplanation"><h2>French: Singular Custom Error message user: 1</h2><p>French: Singular Custom Error explanation 1</p><ul><li>Name est trop court (min. 10 caractères)</li></ul></div>
11
+
12
+
13
+
14
+ <a href="/">Back to Top</a>
15
+ </body>
16
+ </html>