Commit f7de17d244a6d4adebc6f7eb8f84fad0500957cf

Authored by Antonio Terceiro
1 parent c7aa896d

Being able to temporarily change the locale

(ActionItem1640)
Showing 2 changed files with 13 additions and 0 deletions   Show diff stats
lib/noosfero.rb
... ... @@ -27,6 +27,12 @@ module Noosfero
27 27 yield(key, locales[key])
28 28 end
29 29 end
  30 + def with_locale(locale)
  31 + orig_locale = FastGettext.locale
  32 + FastGettext.set_locale(locale)
  33 + yield
  34 + FastGettext.set_locale(orig_locale)
  35 + end
30 36 end
31 37  
32 38 def self.identifier_format
... ...
test/unit/noosfero_test.rb
... ... @@ -49,4 +49,11 @@ class NoosferoTest < Test::Unit::TestCase
49 49 assert_match /^#{Noosfero.identifier_format}$/, '129812startingwithnumber'
50 50 end
51 51  
  52 + should 'change locale temporarily' do
  53 + Noosfero.with_locale('pt') do
  54 + assert_equal 'pt', FastGettext.locale
  55 + end
  56 + assert_equal 'en', FastGettext.locale
  57 + end
  58 +
52 59 end
... ...