Commit f7de17d244a6d4adebc6f7eb8f84fad0500957cf
1 parent
c7aa896d
Exists in
master
and in
29 other branches
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,6 +27,12 @@ module Noosfero | ||
27 | yield(key, locales[key]) | 27 | yield(key, locales[key]) |
28 | end | 28 | end |
29 | end | 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 | end | 36 | end |
31 | 37 | ||
32 | def self.identifier_format | 38 | def self.identifier_format |
test/unit/noosfero_test.rb
@@ -49,4 +49,11 @@ class NoosferoTest < Test::Unit::TestCase | @@ -49,4 +49,11 @@ class NoosferoTest < Test::Unit::TestCase | ||
49 | assert_match /^#{Noosfero.identifier_format}$/, '129812startingwithnumber' | 49 | assert_match /^#{Noosfero.identifier_format}$/, '129812startingwithnumber' |
50 | end | 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 | end | 59 | end |