thedarkone-i18n 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/CHANGELOG.textile +57 -0
  2. data/README.textile +43 -9
  3. data/Rakefile +21 -0
  4. data/VERSION +1 -0
  5. data/lib/i18n.rb +87 -16
  6. data/lib/i18n/backend/base.rb +251 -0
  7. data/lib/i18n/backend/cache.rb +71 -0
  8. data/lib/i18n/backend/chain.rb +64 -0
  9. data/lib/i18n/backend/fallbacks.rb +53 -0
  10. data/lib/i18n/backend/fast.rb +53 -22
  11. data/lib/i18n/backend/fast/interpolation_compiler.rb +84 -0
  12. data/lib/i18n/backend/gettext.rb +65 -0
  13. data/lib/i18n/backend/lazy_reloading.rb +60 -0
  14. data/lib/i18n/backend/pluralization.rb +56 -0
  15. data/lib/i18n/backend/simple.rb +17 -240
  16. data/lib/i18n/exceptions.rb +13 -5
  17. data/lib/i18n/gettext.rb +25 -0
  18. data/lib/i18n/helpers/gettext.rb +35 -0
  19. data/lib/i18n/locale/fallbacks.rb +100 -0
  20. data/lib/i18n/locale/tag.rb +27 -0
  21. data/lib/i18n/locale/tag/parents.rb +24 -0
  22. data/lib/i18n/locale/tag/rfc4646.rb +78 -0
  23. data/lib/i18n/locale/tag/simple.rb +44 -0
  24. data/test/all.rb +5 -7
  25. data/test/api/basics.rb +15 -0
  26. data/test/api/interpolation.rb +85 -0
  27. data/test/api/lambda.rb +52 -0
  28. data/test/api/link.rb +47 -0
  29. data/test/api/localization/date.rb +65 -0
  30. data/test/api/localization/date_time.rb +63 -0
  31. data/test/api/localization/lambda.rb +26 -0
  32. data/test/api/localization/time.rb +63 -0
  33. data/test/api/pluralization.rb +37 -0
  34. data/test/api/translation.rb +51 -0
  35. data/test/backend/cache/cache_test.rb +57 -0
  36. data/test/backend/chain/api_test.rb +80 -0
  37. data/test/backend/chain/chain_test.rb +64 -0
  38. data/test/backend/fallbacks/api_test.rb +79 -0
  39. data/test/backend/fallbacks/fallbacks_test.rb +29 -0
  40. data/test/backend/fast/all.rb +5 -0
  41. data/test/backend/fast/api_test.rb +91 -0
  42. data/test/backend/fast/interpolation_compiler_test.rb +84 -0
  43. data/test/backend/fast/lookup_test.rb +24 -0
  44. data/test/backend/fast/setup.rb +22 -0
  45. data/test/backend/fast/translations_test.rb +89 -0
  46. data/test/backend/lazy_reloading/reloading_test.rb +67 -0
  47. data/test/backend/pluralization/api_test.rb +81 -0
  48. data/test/backend/pluralization/pluralization_test.rb +39 -0
  49. data/test/backend/simple/all.rb +5 -0
  50. data/test/backend/simple/api_test.rb +90 -0
  51. data/test/backend/simple/lookup_test.rb +24 -0
  52. data/test/backend/simple/setup.rb +151 -0
  53. data/test/backend/simple/translations_test.rb +89 -0
  54. data/test/fixtures/locales/de.po +61 -0
  55. data/test/fixtures/locales/en.rb +3 -0
  56. data/test/fixtures/locales/en.yml +3 -0
  57. data/test/fixtures/locales/plurals.rb +112 -0
  58. data/test/gettext/api_test.rb +78 -0
  59. data/test/gettext/backend_test.rb +35 -0
  60. data/test/i18n_exceptions_test.rb +6 -25
  61. data/test/i18n_load_path_test.rb +23 -0
  62. data/test/i18n_test.rb +56 -18
  63. data/test/locale/fallbacks_test.rb +128 -0
  64. data/test/locale/tag/rfc4646_test.rb +147 -0
  65. data/test/locale/tag/simple_test.rb +35 -0
  66. data/test/test_helper.rb +72 -0
  67. data/test/with_options.rb +34 -0
  68. metadata +109 -19
  69. data/i18n.gemspec +0 -31
  70. data/lib/i18n/backend/fast/pluralization_compiler.rb +0 -50
  71. data/test/backend_test.rb +0 -633
  72. data/test/fast_backend_test.rb +0 -34
  73. data/test/locale/en.rb +0 -1
  74. data/test/locale/en.yml +0 -3
  75. data/test/pluralization_compiler_test.rb +0 -35
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
6
+ include Tests::Backend::Simple::Setup::Base
7
+
8
+ def test_load_translations_with_unknown_file_type_raises_exception
9
+ assert_raises(I18n::UnknownFileType) { I18n.backend.load_translations "#{locales_dir}/en.xml" }
10
+ end
11
+
12
+ def test_load_translations_with_ruby_file_type_does_not_raise_exception
13
+ assert_nothing_raised { I18n.backend.load_translations "#{locales_dir}/en.rb" }
14
+ end
15
+
16
+ def test_load_rb_loads_data_from_ruby_file
17
+ data = I18n.backend.send :load_rb, "#{locales_dir}/en.rb"
18
+ assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
19
+ end
20
+
21
+ def test_load_rb_loads_data_from_yaml_file
22
+ data = I18n.backend.send :load_yml, "#{locales_dir}/en.yml"
23
+ assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
24
+ end
25
+
26
+ def test_load_translations_loads_from_different_file_formats
27
+ I18n.backend = I18n::Backend::Simple.new
28
+ I18n.backend.load_translations "#{locales_dir}/en.rb", "#{locales_dir}/en.yml"
29
+ expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
30
+ assert_equal expected, backend_get_translations
31
+ end
32
+ end
33
+
34
+ class I18nSimpleBackendStoreTranslationsTest < Test::Unit::TestCase
35
+ include Tests::Backend::Simple::Setup::Base
36
+
37
+ def test_store_translations_adds_translations # no, really :-)
38
+ I18n.backend.store_translations :'en', :foo => 'bar'
39
+ assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
40
+ end
41
+
42
+ def test_store_translations_deep_merges_translations
43
+ I18n.backend.store_translations :'en', :foo => {:bar => 'bar'}
44
+ I18n.backend.store_translations :'en', :foo => {:baz => 'baz'}
45
+ assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
46
+ end
47
+
48
+ def test_store_translations_forces_locale_to_sym
49
+ I18n.backend.store_translations 'en', :foo => 'bar'
50
+ assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
51
+ end
52
+
53
+ def test_store_translations_converts_keys_to_symbols
54
+ # backend_reset_translations!
55
+ I18n.backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
56
+ assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
57
+ end
58
+
59
+ def test_deep_symbolize_keys_works
60
+ result = I18n.backend.send :deep_symbolize_keys, 'foo' => {'bar' => {'baz' => 'bar'}}
61
+ expected = {:foo => {:bar => {:baz => 'bar'}}}
62
+ assert_equal expected, result
63
+ end
64
+ end
65
+
66
+ class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase
67
+ include Tests::Backend::Simple::Setup::Base
68
+
69
+ def setup
70
+ I18n.backend = I18n::Backend::Simple.new
71
+ I18n.load_path = [locales_dir + '/en.yml']
72
+ assert_nil backend_get_translations
73
+ I18n.backend.send :init_translations
74
+ end
75
+
76
+ def test_setup
77
+ assert_not_nil backend_get_translations
78
+ end
79
+
80
+ def test_reload_translations_unloads_translations
81
+ I18n.backend.reload!
82
+ assert_nil backend_get_translations
83
+ end
84
+
85
+ def test_reload_translations_uninitializes_translations
86
+ I18n.backend.reload!
87
+ assert_equal I18n.backend.initialized?, false
88
+ end
89
+ end
@@ -0,0 +1,61 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: version 0.0.1\n"
10
+ "POT-Creation-Date: 2009-02-26 19:50+0100\n"
11
+ "PO-Revision-Date: 2009-02-18 14:53+0100\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=UTF-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18
+
19
+ # #: app/helpers/translation_helper.rb:3
20
+ # msgid "%{relative_time} ago"
21
+ # msgstr "vor %{relative_time}"
22
+
23
+ #: app/views/cars/show.html.erb:5
24
+ msgid "Axis"
25
+ msgid_plural "Axis"
26
+ msgstr[0] "Achse"
27
+ msgstr[1] "Achsen"
28
+
29
+ #: app/controllers/cars_controller.rb:47
30
+ msgid "Car was successfully created."
31
+ msgstr "Auto wurde erfolgreich gespeichert"
32
+
33
+ #: app/controllers/cars_controller.rb:64
34
+ msgid "Car was successfully updated."
35
+ msgstr "Auto wurde erfolgreich aktualisiert"
36
+
37
+ #: app/views/cars/show.html.erb:1 locale/model_attributes.rb:3
38
+ msgid "Car|Model"
39
+ msgstr "Modell"
40
+
41
+ #: app/views/cars/show.html.erb:3 locale/model_attributes.rb:4
42
+ msgid "Car|Wheels count"
43
+ msgstr "Räderzahl"
44
+
45
+ #: app/views/cars/show.html.erb:7
46
+ msgid "Created"
47
+ msgstr "Erstellt"
48
+
49
+ #: app/views/cars/show.html.erb:9
50
+ msgid "Month"
51
+ msgstr "Monat"
52
+
53
+ #: locale/model_attributes.rb:2
54
+ msgid "car"
55
+ msgstr "Auto"
56
+
57
+ #: locale/testlog_phrases.rb:2
58
+ msgid "this is a dynamic translation which was found thorugh gettext_test_log!"
59
+ msgstr ""
60
+ "Dies ist eine dynamische Übersetzung, die durch gettext_test_log "
61
+ "gefunden wurde!"
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ { :en => { :fuh => { :bah => "bas" } } }
@@ -0,0 +1,3 @@
1
+ en:
2
+ foo:
3
+ bar: baz
@@ -0,0 +1,112 @@
1
+ # encoding: utf-8
2
+
3
+ {
4
+ :af => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
5
+ :am => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
6
+ :ar => { :i18n => { :pluralize => lambda { |n| n == 0 ? :zero : n == 1 ? :one : n == 2 ? :two : (3..10).include?(n % 100) ? :few : (11..99).include?(n % 100) ? :many : :other } } },
7
+ :az => { :i18n => { :pluralize => lambda { |n| :other } } },
8
+ :be => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
9
+ :bg => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
10
+ :bh => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
11
+ :bn => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
12
+ :bo => { :i18n => { :pluralize => lambda { |n| :other } } },
13
+ :bs => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
14
+ :ca => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
15
+ :cs => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : (2..4).include?(n) ? :few : :other } } },
16
+ :cy => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : n == 8 || n == 11 ? :many : :other } } },
17
+ :da => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
18
+ :de => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
19
+ :dz => { :i18n => { :pluralize => lambda { |n| :other } } },
20
+ :el => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
21
+ :en => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
22
+ :eo => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
23
+ :es => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
24
+ :et => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
25
+ :eu => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
26
+ :fa => { :i18n => { :pluralize => lambda { |n| :other } } },
27
+ :fi => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
28
+ :fil => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
29
+ :fo => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
30
+ :fr => { :i18n => { :pluralize => lambda { |n| n && n != 2 ? :one : :other } } },
31
+ :fur => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
32
+ :fy => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
33
+ :ga => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
34
+ :gl => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
35
+ :gu => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
36
+ :guw => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
37
+ :ha => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
38
+ :he => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
39
+ :hi => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
40
+ :hr => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
41
+ :hu => { :i18n => { :pluralize => lambda { |n| :other } } },
42
+ :id => { :i18n => { :pluralize => lambda { |n| :other } } },
43
+ :is => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
44
+ :it => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
45
+ :iw => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
46
+ :ja => { :i18n => { :pluralize => lambda { |n| :other } } },
47
+ :jv => { :i18n => { :pluralize => lambda { |n| :other } } },
48
+ :ka => { :i18n => { :pluralize => lambda { |n| :other } } },
49
+ :km => { :i18n => { :pluralize => lambda { |n| :other } } },
50
+ :kn => { :i18n => { :pluralize => lambda { |n| :other } } },
51
+ :ko => { :i18n => { :pluralize => lambda { |n| :other } } },
52
+ :ku => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
53
+ :lb => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
54
+ :ln => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
55
+ :lt => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && !(11..19).include?(n % 100) ? :one : (2..9).include?(n % 10) && !(11..19).include?(n % 100) ? :few : :other } } },
56
+ :lv => { :i18n => { :pluralize => lambda { |n| n == 0 ? :zero : n % 10 == 1 && n % 100 != 11 ? :one : :other } } },
57
+ :mg => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
58
+ :mk => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 ? :one : :other } } },
59
+ :ml => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
60
+ :mn => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
61
+ :mo => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } },
62
+ :mr => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
63
+ :ms => { :i18n => { :pluralize => lambda { |n| :other } } },
64
+ :mt => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 0 || (2..10).include?(n % 100) ? :few : (11..19).include?(n % 100) ? :many : :other } } },
65
+ :my => { :i18n => { :pluralize => lambda { |n| :other } } },
66
+ :nah => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
67
+ :nb => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
68
+ :ne => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
69
+ :nl => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
70
+ :nn => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
71
+ :no => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
72
+ :nso => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
73
+ :om => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
74
+ :or => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
75
+ :pa => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
76
+ :pap => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
77
+ :pl => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) && !(22..24).include?(n % 100) ? :few : :other } } },
78
+ :ps => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
79
+ :pt => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
80
+ :"pt-PT" => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
81
+ :ro => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } },
82
+ :ru => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
83
+ :se => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
84
+ :sh => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
85
+ :sk => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : (2..4).include?(n) ? :few : :other } } },
86
+ :sl => { :i18n => { :pluralize => lambda { |n| n % 100 == 1 ? :one : n % 100 == 2 ? :two : (3..4).include?(n % 100) ? :few : :other } } },
87
+ :sma => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
88
+ :smi => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
89
+ :smj => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
90
+ :smn => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
91
+ :sms => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
92
+ :so => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
93
+ :sq => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
94
+ :sr => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
95
+ :sv => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
96
+ :sw => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
97
+ :ta => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
98
+ :te => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
99
+ :th => { :i18n => { :pluralize => lambda { |n| :other } } },
100
+ :ti => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
101
+ :tk => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
102
+ :tl => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
103
+ :to => { :i18n => { :pluralize => lambda { |n| :other } } },
104
+ :tr => { :i18n => { :pluralize => lambda { |n| :other } } },
105
+ :uk => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
106
+ :ur => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
107
+ :vi => { :i18n => { :pluralize => lambda { |n| :other } } },
108
+ :wa => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
109
+ :yo => { :i18n => { :pluralize => lambda { |n| :other } } },
110
+ :zh => { :i18n => { :pluralize => lambda { |n| :other } } },
111
+ :zu => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } }
112
+ }
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
4
+ require 'i18n/backend/gettext'
5
+ require 'i18n/helpers/gettext'
6
+
7
+ include I18n::Helpers::Gettext
8
+
9
+ class I18nGettextApiTest < Test::Unit::TestCase
10
+ def setup
11
+ I18n.locale = :en
12
+ I18n.backend.store_translations :de, {
13
+ 'Hi Gettext!' => 'Hallo Gettext!',
14
+ 'Sentence 1. Sentence 2.' => 'Satz 1. Satz 2.',
15
+ "An apple#{I18n::Gettext::PLURAL_SEPARATOR}{{count}} apples" => { :one => 'Ein Apfel', :other => '{{count}} Äpfel' },
16
+ :special => { 'An apple' => { :one => 'Ein spezieller Apfel', :other => '{{count}} spezielle Äpfel' } },
17
+ :foo => { :bar => { :baz => 'baz-de' } }
18
+ }
19
+ end
20
+
21
+ def test_helper_uses_msg_as_default
22
+ assert_equal 'Hi Gettext!', _('Hi Gettext!')
23
+ end
24
+
25
+ def test_helper_uses_msg_as_key
26
+ I18n.locale = :de
27
+ assert_equal 'Hallo Gettext!', _('Hi Gettext!')
28
+ end
29
+
30
+ def test_helper_uses_msg_containing_dots_as_default
31
+ assert_equal 'Sentence 1. Sentence 2.', _('Sentence 1. Sentence 2.')
32
+ end
33
+
34
+ def test_helper_uses_msg_containing_dots_as_key
35
+ I18n.locale = :de
36
+ assert_equal 'Satz 1. Satz 2.', _('Sentence 1. Sentence 2.')
37
+ end
38
+
39
+ def test_sgettext_defaults_to_the_last_token_of_a_scoped_msgid
40
+ assert_equal 'baz', sgettext('foo|bar|baz')
41
+ end
42
+
43
+ def test_sgettext_looks_up_a_scoped_translation
44
+ I18n.locale = :de
45
+ assert_equal 'baz-de', sgettext('foo|bar|baz')
46
+ end
47
+
48
+ def test_pgettext_defaults_to_msgid
49
+ assert_equal 'baz', pgettext('foo|bar', 'baz', '|')
50
+ end
51
+
52
+ def test_pgettext_looks_up_a_scoped_translation
53
+ I18n.locale = :de
54
+ assert_equal 'baz-de', pgettext('foo|bar', 'baz', '|')
55
+ end
56
+
57
+ def test_ngettext_looks_up_msg_id_as_default_singular
58
+ assert_equal 'An apple', ngettext('An apple', '{{count}} apples', 1)
59
+ end
60
+
61
+ def test_ngettext_looks_up_msg_id_plural_as_default_plural
62
+ assert_equal '2 apples', ngettext('An apple', '{{count}} apples', 2)
63
+ end
64
+
65
+ def test_ngettext_looks_up_msg_id_as_singular
66
+ I18n.locale = :de
67
+ assert_equal 'Ein Apfel', ngettext('An apple', '{{count}} apples', 1)
68
+ end
69
+
70
+ def test_ngettext_looks_up_msg_id_as_singular
71
+ I18n.locale = :de
72
+ assert_equal '2 Äpfel', ngettext('An apple', '{{count}} apples', 2)
73
+ end
74
+
75
+ def test_nsgettext_looks_up_msg_id_as_default_singular
76
+ assert_equal 'A special apple', nsgettext('special|A special apple', '{{count}} special apples', 1, '|')
77
+ end
78
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
4
+ require 'i18n/backend/gettext'
5
+ require 'i18n/helpers/gettext'
6
+
7
+ include I18n::Helpers::Gettext
8
+
9
+ class I18nGettextBackendTest < Test::Unit::TestCase
10
+ def setup
11
+ I18n.locale = :en
12
+ I18n.load_path = [locales_dir + '/de.po']
13
+ I18n.backend.meta_class.send(:include, I18n::Backend::Gettext)
14
+ end
15
+
16
+ def teardown
17
+ I18n.load_path = nil
18
+ I18n.backend = nil
19
+ end
20
+
21
+ def test_backend_loads_po_file
22
+ I18n.backend.send(:init_translations)
23
+ assert I18n.backend.send(:translations)[:de][:"Axis\001Axis"]
24
+ end
25
+
26
+ def test_looks_up_translation
27
+ I18n.locale = :de
28
+ assert_equal 'Auto', _('car')
29
+ end
30
+
31
+ def test_pluralizes_entry
32
+ I18n.locale = :de
33
+ assert_equal 'Achsen', ngettext('Axis', 'Axis', 2)
34
+ end
35
+ end
@@ -1,12 +1,8 @@
1
- $:.unshift "lib"
1
+ # encoding: utf-8
2
2
 
3
- require 'rubygems'
4
- require 'test/unit'
5
- require 'mocha'
6
- require 'i18n'
7
- require 'active_support'
3
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
8
4
 
9
- module I18nExceptionsTest
5
+ class I18nExceptionsTest < Test::Unit::TestCase
10
6
  def test_invalid_locale_stores_locale
11
7
  force_invalid_locale
12
8
  rescue I18n::ArgumentError => e
@@ -48,16 +44,17 @@ module I18nExceptionsTest
48
44
  end
49
45
 
50
46
  def test_missing_interpolation_argument_stores_key_and_string
47
+ assert_raises(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
51
48
  force_missing_interpolation_argument
52
49
  rescue I18n::ArgumentError => e
53
- assert_equal :bar, e.key
50
+ # assert_equal :bar, e.key
54
51
  assert_equal "{{bar}}", e.string
55
52
  end
56
53
 
57
54
  def test_missing_interpolation_argument_message
58
55
  force_missing_interpolation_argument
59
56
  rescue I18n::ArgumentError => e
60
- assert_equal 'interpolation argument :bar missing in "{{bar}}"', e.message
57
+ assert_equal 'missing interpolation argument in "{{bar}}" ({:baz=>"baz"} given)', e.message
61
58
  end
62
59
 
63
60
  def test_reserved_interpolation_key_stores_key_and_string
@@ -97,20 +94,4 @@ module I18nExceptionsTest
97
94
  I18n.backend.store_translations 'de', :foo => "{{scope}}"
98
95
  I18n.backend.translate 'de', :foo, :baz => 'baz'
99
96
  end
100
- end
101
-
102
- class I18nSimpleBackendExceptionsTest < Test::Unit::TestCase
103
- include I18nExceptionsTest
104
-
105
- def setup
106
- I18n.backend = I18n::Backend::Simple.new
107
- end
108
- end
109
-
110
- class I18nFastBackendExceptionsTest < Test::Unit::TestCase
111
- include I18nExceptionsTest
112
-
113
- def setup
114
- I18n.backend = I18n::Backend::Fast.new
115
- end
116
97
  end