Skip to content

Commit

Permalink
added available_locales (returns an array of locales for which transl…
Browse files Browse the repository at this point in the history
…ations are available)
  • Loading branch information
Sven Fuchs committed Jan 8, 2009
1 parent d473a06 commit 411f8fe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/i18n.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/i18n/backend/simple.rb
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/simple_backend_test.rb
Expand Up @@ -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

Expand Down

0 comments on commit 411f8fe

Please sign in to comment.