From 56fb512398c879ad46149d3a223787a6d1f93534 Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Sat, 3 Jan 2009 13:47:27 +0300 Subject: [PATCH] Add I18n l/localize and t/translate methods to ActiveRecord models --- activerecord/lib/active_record.rb | 1 + activerecord/lib/active_record/base.rb | 1 + activerecord/lib/active_record/translation.rb | 13 +++++++++++++ activerecord/test/cases/i18n_test.rb | 22 +++++++++++++++++++++- 4 files changed, 36 insertions(+), 1 deletions(-) create mode 100644 activerecord/lib/active_record/translation.rb diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index 390c005..31aa488 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -65,6 +65,7 @@ module ActiveRecord autoload :TestCase, 'active_record/test_case' autoload :Timestamp, 'active_record/timestamp' autoload :Transactions, 'active_record/transactions' + autoload :Translation, 'active_record/translation' autoload :Validations, 'active_record/validations' module Locking diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index cca012e..e1b2c56 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -3092,6 +3092,7 @@ module ActiveRecord #:nodoc: include Callbacks, Observing, Timestamp include Associations, AssociationPreload, NamedScope include Aggregations, Transactions, Reflection, Calculations, Serialization + include Translation end end diff --git a/activerecord/lib/active_record/translation.rb b/activerecord/lib/active_record/translation.rb new file mode 100644 index 0000000..44363ea --- /dev/null +++ b/activerecord/lib/active_record/translation.rb @@ -0,0 +1,13 @@ +module ActiveRecord + module Translation + def translate(*args) + I18n.translate *args + end + alias :t :translate + + def localize(*args) + I18n.localize *args + end + alias :l :localize + end +end \ No newline at end of file diff --git a/activerecord/test/cases/i18n_test.rb b/activerecord/test/cases/i18n_test.rb index b1db662..7a03967 100644 --- a/activerecord/test/cases/i18n_test.rb +++ b/activerecord/test/cases/i18n_test.rb @@ -3,7 +3,6 @@ require 'models/topic' require 'models/reply' class ActiveRecordI18nTests < Test::Unit::TestCase - def setup I18n.backend = I18n::Backend::Simple.new end @@ -39,3 +38,24 @@ class ActiveRecordI18nTests < Test::Unit::TestCase end end +class ActiveRecordTranslationTests < Test::Unit::TestCase + def setup + @topic = Topic.new + end + + def test_responds_to_t + assert @topic.respond_to?(:t) + end + + def test_responds_to_translate + assert @topic.respond_to?(:translate) + end + + def test_responds_to_l + assert @topic.respond_to?(:l) + end + + def test_responds_to_localize + assert @topic.respond_to?(:localize) + end +end \ No newline at end of file -- 1.6.1