Permalink
Browse files

Make i18n scope configurable

Signed-off-by: Ben Johnson <bjohnson@binarylogic.com>
  • Loading branch information...
1 parent e8b3ee7 commit 14dc9a764c716f59602d10aa5364be8f9fc38b8a @m4n m4n committed with Sep 9, 2009
Showing with 28 additions and 3 deletions.
  1. +15 −3 lib/authlogic/i18n.rb
  2. +13 −0 test/i18n_test.rb
View
18 lib/authlogic/i18n.rb
@@ -47,17 +47,29 @@ module Authlogic
# email: email
# password: password
# remember_me: remember me
- class I18n
+ module I18n
+ @@scope = :authlogic
+
class << self
+ # Returns the current scope. Defaults to :authlogic
+ def scope
+ @@scope
+ end
+
+ # Sets the current scope. Used to set a custom scope.
+ def scope=(scope)
+ @@scope = scope
+ end
+
# All message translation is passed to this method. The first argument is the key for the message. The second is options, see the rails I18n library for a list of options used.
def t(key, options = {})
if defined?(::I18n)
- ::I18n.t(key, options.merge(:scope => :authlogic))
+ ::I18n.t(key, options.merge(:scope => I18n.scope))
else
options[:default]
end
end
alias_method :translate, :t
end
end
-end
+end
View
13 test/i18n_test.rb
@@ -0,0 +1,13 @@
+require File.dirname(__FILE__) + '/test_helper.rb'
+
+class I18nTest < ActiveSupport::TestCase
+ def test_uses_authlogic_as_scope_by_default
+ assert_equal :authlogic, Authlogic::I18n.scope
+ end
+
+ def test_can_set_scope
+ assert_nothing_raised{ Authlogic::I18n.scope = [:a, :b] }
+ assert_equal [:a, :b], Authlogic::I18n.scope
+ Authlogic::I18n.scope = :authlogic
+ end
+end

0 comments on commit 14dc9a7

Please sign in to comment.