Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Rails3 i18n #204

Merged
2 commits merged into from

2 participants

@benmanns

Hey Ben (Johnson),

In Rails 3, Model.human_name has been deprecated in favor of Model.model_name.human. In my projects I translate the Session name from "User session" to "Session". However, because the Model.model_name.human method requires some more methods in the class it's acting on (i18n_scope and lookup_ancestors), the new method wasn't working with Authlogic.

I have added tests for both the deprecated method and the Rails 3 method and have added code to make the latter pass.

Let me know if you want me to change anything. I've tried to keep everything the same syntactically so as not to mash coding styles.

Ben (Manns)

@jjb
jjb commented

hi-- i'm going to try to maintain the One True Rails 3 Fork :) please send your pull request to https://github.com/jjb/authlogic

@ghost ghost merged commit 006f25a into binarylogic:master
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
8 lib/authlogic/session/active_record_trickery.rb
@@ -46,6 +46,14 @@ def model_name
::ActiveSupport::ModelName.new(self.to_s)
end
end
+
+ def i18n_scope
+ I18n.scope
+ end
+
+ def lookup_ancestors
+ ancestors.select { |x| x.respond_to?(:model_name) }
+ end
end
module InstanceMethods
View
10 test/session_test/active_record_trickery_test.rb
@@ -19,6 +19,16 @@ def test_self_and_descendents_from_active_record
def test_self_and_descendants_from_active_record
assert_equal [UserSession], UserSession.self_and_descendants_from_active_record
end
+
+ def test_i18n_of_human_name
+ I18n.backend.store_translations 'en', :authlogic => {:models => {:user_session => "MySession" } }
+ assert_equal "MySession", UserSession.human_name
+ end
+
+ def test_i18n_of_model_name_human
+ I18n.backend.store_translations 'en', :authlogic => {:models => {:user_session => "MySession" } }
+ assert_equal "MySession", UserSession.model_name.human
+ end
end
class InstanceMethodsTest < ActiveSupport::TestCase
Something went wrong with that request. Please try again.