Skip to content
Browse files

added available_locales (returns an array of locales for which transl…

…ations are available)
  • Loading branch information...
1 parent d473a06 commit 411f8fe7c8f3f89e9b6b921fa62ed66cb92f3af4 @svenfuchs committed Jan 8, 2009
Showing with 21 additions and 0 deletions.
  1. +5 −0 lib/i18n.rb
  2. +6 −0 lib/i18n/backend/simple.rb
  3. +10 −0 test/simple_backend_test.rb
View
5 lib/i18n.rb
@@ -45,6 +45,11 @@ def locale=(locale)
Thread.current[:locale] = locale
end
+ # Returns an array of locales for which translations are available
+ def available_locales
+ backend.available_locales
+ end
+
# Sets the exception handler.
def exception_handler=(exception_handler)
@@exception_handler = exception_handler
View
6 lib/i18n/backend/simple.rb
@@ -69,6 +69,12 @@ def initialized?
@initialized ||= false
end
+ # Returns an array of locales for which translations are available
+ def available_locales
+ init_translations unless initialized?
+ translations.keys
+ end
+
def reload!
@initialized = false
@translations = nil
View
10 test/simple_backend_test.rb
@@ -124,6 +124,16 @@ def test_store_translations_converts_keys_to_symbols
end
end
+class I18nSimpleBackendAvailableLocalesTest < Test::Unit::TestCase
+ def test_available_locales
+ @backend = I18n::Backend::Simple.new
+ @backend.store_translations 'de', :foo => 'bar'
+ @backend.store_translations 'en', :foo => 'foo'
+
+ assert_equal ['de', 'en'], @backend.available_locales.map{|locale| locale.to_s }.sort
+ end
+end
+
class I18nSimpleBackendTranslateTest < Test::Unit::TestCase
include I18nSimpleBackendTestSetup

0 comments on commit 411f8fe

Please sign in to comment.
Something went wrong with that request. Please try again.