diff --git a/lib/noosfero.rb b/lib/noosfero.rb index b7fbc1e..e771fd7 100644 --- a/lib/noosfero.rb +++ b/lib/noosfero.rb @@ -27,6 +27,12 @@ module Noosfero yield(key, locales[key]) end end + def with_locale(locale) + orig_locale = FastGettext.locale + FastGettext.set_locale(locale) + yield + FastGettext.set_locale(orig_locale) + end end def self.identifier_format diff --git a/test/unit/noosfero_test.rb b/test/unit/noosfero_test.rb index 1987ff3..ffd9e5e 100644 --- a/test/unit/noosfero_test.rb +++ b/test/unit/noosfero_test.rb @@ -49,4 +49,11 @@ class NoosferoTest < Test::Unit::TestCase assert_match /^#{Noosfero.identifier_format}$/, '129812startingwithnumber' end + should 'change locale temporarily' do + Noosfero.with_locale('pt') do + assert_equal 'pt', FastGettext.locale + end + assert_equal 'en', FastGettext.locale + end + end -- libgit2 0.21.2