svenfuchs-i18n 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/i18n.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "i18n"
3
- s.version = "0.1.1"
4
- s.date = "2008-10-26"
3
+ s.version = "0.1.2"
4
+ s.date = "2009-01-09"
5
5
  s.summary = "Internationalization support for Ruby"
6
6
  s.email = "rails-i18n@googlegroups.com"
7
7
  s.homepage = "http://rails-i18n.org"
@@ -69,6 +69,12 @@ module I18n
69
69
  @initialized ||= false
70
70
  end
71
71
 
72
+ # Returns an array of locales for which translations are available
73
+ def available_locales
74
+ init_translations unless initialized?
75
+ translations.keys
76
+ end
77
+
72
78
  def reload!
73
79
  @initialized = false
74
80
  @translations = nil
@@ -76,7 +82,7 @@ module I18n
76
82
 
77
83
  protected
78
84
  def init_translations
79
- load_translations(*I18n.load_path)
85
+ load_translations(*I18n.load_path.flatten)
80
86
  @initialized = true
81
87
  end
82
88
 
data/lib/i18n.rb CHANGED
@@ -45,6 +45,11 @@ module I18n
45
45
  Thread.current[:locale] = locale
46
46
  end
47
47
 
48
+ # Returns an array of locales for which translations are available
49
+ def available_locales
50
+ backend.available_locales
51
+ end
52
+
48
53
  # Sets the exception handler.
49
54
  def exception_handler=(exception_handler)
50
55
  @@exception_handler = exception_handler
@@ -124,6 +124,16 @@ class I18nSimpleBackendTranslationsTest < Test::Unit::TestCase
124
124
  end
125
125
  end
126
126
 
127
+ class I18nSimpleBackendAvailableLocalesTest < Test::Unit::TestCase
128
+ def test_available_locales
129
+ @backend = I18n::Backend::Simple.new
130
+ @backend.store_translations 'de', :foo => 'bar'
131
+ @backend.store_translations 'en', :foo => 'foo'
132
+
133
+ assert_equal ['de', 'en'], @backend.available_locales.map{|locale| locale.to_s }.sort
134
+ end
135
+ end
136
+
127
137
  class I18nSimpleBackendTranslateTest < Test::Unit::TestCase
128
138
  include I18nSimpleBackendTestSetup
129
139
 
@@ -472,6 +482,30 @@ class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
472
482
  end
473
483
  end
474
484
 
485
+ class I18nSimpleBackendLoadPathTest < Test::Unit::TestCase
486
+ include I18nSimpleBackendTestSetup
487
+
488
+ def teardown
489
+ I18n.load_path = []
490
+ end
491
+
492
+ def test_nested_load_paths_do_not_break_locale_loading
493
+ @backend = I18n::Backend::Simple.new
494
+ I18n.load_path = [[File.dirname(__FILE__) + '/locale/en.yml']]
495
+ assert_nil backend_get_translations
496
+ assert_nothing_raised { @backend.send :init_translations }
497
+ assert_not_nil backend_get_translations
498
+ end
499
+
500
+ def test_adding_arrays_of_filenames_to_load_path_do_not_break_locale_loading
501
+ @backend = I18n::Backend::Simple.new
502
+ I18n.load_path << Dir[File.dirname(__FILE__) + '/locale/*.{rb,yml}']
503
+ assert_nil backend_get_translations
504
+ assert_nothing_raised { @backend.send :init_translations }
505
+ assert_not_nil backend_get_translations
506
+ end
507
+ end
508
+
475
509
  class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase
476
510
  include I18nSimpleBackendTestSetup
477
511
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svenfuchs-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2008-10-26 00:00:00 -07:00
16
+ date: 2009-01-09 00:00:00 -08:00
17
17
  default_executable:
18
18
  dependencies: []
19
19