everythingbehind-i18n 0.1.1 → 0.1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/i18n.gemspec CHANGED
@@ -1,13 +1,13 @@
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.1.1"
4
+ s.date = "2008-12-16"
5
5
  s.summary = "Internationalization support for Ruby"
6
6
  s.email = "rails-i18n@googlegroups.com"
7
7
  s.homepage = "http://rails-i18n.org"
8
8
  s.description = "Add Internationalization support to your Ruby application."
9
9
  s.has_rdoc = false
10
- s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Matt Aimonetti', 'Stephan Soller', 'Saimon Moore']
10
+ s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Matt Aimonetti', 'Stephan Soller', 'Saimon Moore', 'Ben Sales', 'Tom Lea']
11
11
  s.files = [
12
12
  'i18n.gemspec',
13
13
  'lib/i18n/backend/simple.rb',
@@ -74,7 +74,7 @@ module I18n
74
74
  @translations = nil
75
75
  end
76
76
 
77
- def locales
77
+ def available_locales
78
78
  translations.keys
79
79
  end
80
80
 
@@ -223,14 +223,19 @@ module I18n
223
223
  # Walks a given tree of hashes, returning an array of possible walks through the tree.
224
224
  # flatten_hash_tree_keys({:a => { :b => 3, :c => 4 } }) # => [ [:a, :b], [:a, :c] ]
225
225
  def flatten_hash_tree_keys(tree)
226
- tree.map{|key, value|
227
- case value
228
- when Hash
229
- flatten_hash_tree_keys(value).map{|normalised_subtree| [key] + [normalised_subtree] }
230
- else
231
- [key]
232
- end
233
- }
226
+ if tree.is_a? Hash
227
+ result = []
228
+ tree.each{|key, value|
229
+ if flattened_subtree = flatten_hash_tree_keys(value)
230
+ flattened_subtree.each do |set|
231
+ result.push([key, *set])
232
+ end
233
+ else
234
+ result.push([key])
235
+ end
236
+ }
237
+ result
238
+ end
234
239
  end
235
240
  end
236
241
  end
@@ -2,7 +2,7 @@ module I18n
2
2
  module TestHelper
3
3
  def assert_all_locales_have_translations_available_to_the_default_locale(message = "All translations should be available in all locales")
4
4
  default_locale = I18n.default_locale.to_sym
5
- locales_to_check = I18n.locales - [default_locale]
5
+ locales_to_check = I18n.available_locales - [default_locale]
6
6
 
7
7
  required_translations = I18n.available_translations(default_locale)
8
8
 
@@ -11,7 +11,7 @@ module I18n
11
11
  missing_translations = required_translations - defined_translations
12
12
 
13
13
  if missing_translations.any?
14
- missing_translations_for_output = [*missing_translations.map{|a| " * #{a.join('.')}" }].join("\n")
14
+ missing_translations_for_output = missing_translations.map{|parts| " * #{parts.join('.')}" }.join("\n")
15
15
  raise Test::Unit::AssertionFailedError.new("#{message} - Missing translations for #{target_locale.inspect}:\n#{missing_translations_for_output}")
16
16
  end
17
17
  end
data/lib/i18n.rb CHANGED
@@ -47,8 +47,8 @@ module I18n
47
47
  end
48
48
 
49
49
  # Returns an array of availiable locales
50
- def locales
51
- backend.locales
50
+ def available_locales
51
+ backend.available_locales
52
52
  end
53
53
 
54
54
  # Lists all available translation keys (including scopes) for a given locale
data/test/i18n_test.rb CHANGED
@@ -62,8 +62,8 @@ class I18nTest < Test::Unit::TestCase
62
62
  end
63
63
 
64
64
  def test_delegates_locales_to_backend
65
- I18n.backend.expects(:locales)
66
- I18n.locales
65
+ I18n.backend.expects(:available_locales)
66
+ I18n.available_locales
67
67
  end
68
68
 
69
69
  def test_delegates_translate_to_backend
@@ -127,4 +127,10 @@ class I18nTest < Test::Unit::TestCase
127
127
  def test_localize_object_raises_argument_error
128
128
  assert_raises(I18n::ArgumentError) { I18n.l Object.new }
129
129
  end
130
+
131
+ def test_should_return_nested_scopes_as_arrays_of_keys_when_looking_for_available_translations
132
+ elements = I18n.available_translations(:'en')
133
+ assert elements.any?{|v| v == [:currency, :format, :separator] }, "Expected #{elements.inspect} to contain [:currency, :format, :separator]"
134
+ assert elements.any?{|v| v == [:currency, :format, :delimiter] }, "Expected #{elements.inspect} to contain [:currency, :format, :delimiter]"
135
+ end
130
136
  end
@@ -1,10 +1,19 @@
1
+ # encoding: utf-8
2
+ $:.unshift "lib"
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'mocha'
7
+ require 'i18n'
8
+ require 'time'
9
+ require 'yaml'
1
10
 
2
11
  class EqualLocalesTestHelperTest < Test::Unit::TestCase
3
12
  include I18n::TestHelper
4
-
13
+
5
14
  def setup
6
15
  I18n.reload!
7
-
16
+
8
17
  I18n.backend.store_translations :'en', {
9
18
  :foo => "Bar",
10
19
  :nested => {
@@ -23,16 +32,31 @@ class EqualLocalesTestHelperTest < Test::Unit::TestCase
23
32
  :foo => "Barrrr!"
24
33
  }
25
34
  end
26
-
35
+
27
36
  def test_should_not_raise_a_test_failure
28
37
  assert_nothing_raised() { assert_all_locales_have_translations_available_to_the_default_locale }
29
38
  end
39
+
40
+ def test_should_show_deeply_nested_translation_keys_correctly
41
+ I18n.backend.store_translations :'en', {
42
+ :nested => {
43
+ :translations => {
44
+ :should => {
45
+ :work => "Well"
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ e = assert_raise(Test::Unit::AssertionFailedError) { assert_all_locales_have_translations_available_to_the_default_locale }
52
+ assert_match %r/ * nested.translations.should.work$/, e.message
53
+ end
30
54
  end
31
55
 
32
56
 
33
57
  class UnequalLocalesTestHelperTest < Test::Unit::TestCase
34
58
  include I18n::TestHelper
35
-
59
+
36
60
  def setup
37
61
  I18n.reload!
38
62
 
@@ -47,7 +71,7 @@ class UnequalLocalesTestHelperTest < Test::Unit::TestCase
47
71
  }
48
72
  }
49
73
  end
50
-
74
+
51
75
  def test_should_raise_a_test_failure_for_none_matching_nested_keys
52
76
  e = assert_raise(Test::Unit::AssertionFailedError) { assert_all_locales_have_translations_available_to_the_default_locale }
53
77
  assert_match %r/Missing translations for :pirate/, e.message
@@ -109,9 +109,9 @@ class I18nSimpleBackendTranslationsTest < Test::Unit::TestCase
109
109
  def test_list_of_locales
110
110
  @backend.store_translations :'en', :foo => {:bar => 'bar'}
111
111
  @backend.store_translations :'fr', :foo => {:bar => 'baz'}
112
- assert_equal 2, @backend.locales.length
113
- assert @backend.locales.include?(:en)
114
- assert @backend.locales.include?(:fr)
112
+ assert_equal 2, @backend.available_locales.length
113
+ assert @backend.available_locales.include?(:en)
114
+ assert @backend.available_locales.include?(:fr)
115
115
  end
116
116
 
117
117
  def test_store_translations_deep_merges_translations
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everythingbehind-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
@@ -9,11 +9,13 @@ authors:
9
9
  - Matt Aimonetti
10
10
  - Stephan Soller
11
11
  - Saimon Moore
12
+ - Ben Sales
13
+ - Tom Lea
12
14
  autorequire:
13
15
  bindir: bin
14
16
  cert_chain: []
15
17
 
16
- date: 2008-10-26 00:00:00 -07:00
18
+ date: 2008-12-16 00:00:00 -08:00
17
19
  default_executable:
18
20
  dependencies: []
19
21