i18n 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of i18n might be problematic. Click here for more details.

Files changed (77) hide show
  1. data/README.textile +44 -9
  2. data/Rakefile +2 -1
  3. data/VERSION +1 -1
  4. data/lib/i18n.rb +60 -15
  5. data/lib/i18n/backend.rb +14 -0
  6. data/lib/i18n/backend/active_record.rb +69 -0
  7. data/lib/i18n/backend/active_record/store_procs.rb +37 -0
  8. data/lib/i18n/backend/active_record/translation.rb +82 -0
  9. data/lib/i18n/backend/active_record_missing.rb +55 -0
  10. data/lib/i18n/backend/base.rb +235 -0
  11. data/lib/i18n/backend/cache.rb +71 -0
  12. data/lib/i18n/backend/chain.rb +74 -0
  13. data/lib/i18n/backend/fallbacks.rb +51 -0
  14. data/lib/i18n/backend/gettext.rb +75 -0
  15. data/lib/i18n/backend/helpers.rb +53 -0
  16. data/lib/i18n/backend/metadata.rb +73 -0
  17. data/lib/i18n/backend/pluralization.rb +57 -0
  18. data/lib/i18n/backend/simple.rb +15 -227
  19. data/lib/i18n/core_ext/object/meta_class.rb +5 -0
  20. data/lib/i18n/{string.rb → core_ext/string/interpolate.rb} +2 -0
  21. data/lib/i18n/exceptions.rb +2 -0
  22. data/lib/i18n/gettext.rb +25 -0
  23. data/lib/i18n/helpers.rb +5 -0
  24. data/lib/i18n/helpers/gettext.rb +64 -0
  25. data/lib/i18n/locale.rb +6 -0
  26. data/lib/i18n/locale/fallbacks.rb +98 -0
  27. data/lib/i18n/locale/tag.rb +28 -0
  28. data/lib/i18n/locale/tag/parents.rb +24 -0
  29. data/lib/i18n/locale/tag/rfc4646.rb +76 -0
  30. data/lib/i18n/locale/tag/simple.rb +41 -0
  31. data/test/all.rb +7 -2
  32. data/test/api/basics.rb +3 -1
  33. data/test/api/interpolation.rb +35 -4
  34. data/test/api/lambda.rb +5 -3
  35. data/test/api/link.rb +4 -2
  36. data/test/api/localization/date.rb +2 -0
  37. data/test/api/localization/date_time.rb +3 -1
  38. data/test/api/localization/lambda.rb +4 -2
  39. data/test/api/localization/time.rb +3 -1
  40. data/test/api/pluralization.rb +12 -15
  41. data/test/api/translation.rb +5 -3
  42. data/test/backend/active_record/active_record_test.rb +40 -0
  43. data/test/backend/active_record/all.rb +3 -0
  44. data/test/backend/active_record/api_test.rb +54 -0
  45. data/test/backend/active_record/setup.rb +166 -0
  46. data/test/backend/active_record_missing/active_record_missing_test.rb +63 -0
  47. data/test/backend/all/api_test.rb +88 -0
  48. data/test/backend/cache/cache_test.rb +69 -0
  49. data/test/backend/chain/api_test.rb +80 -0
  50. data/test/backend/chain/chain_test.rb +64 -0
  51. data/test/backend/fallbacks/api_test.rb +84 -0
  52. data/test/backend/fallbacks/fallbacks_test.rb +57 -0
  53. data/test/backend/metadata/metadata_test.rb +65 -0
  54. data/test/backend/pluralization/api_test.rb +86 -0
  55. data/test/backend/pluralization/pluralization_test.rb +43 -0
  56. data/test/backend/simple/all.rb +2 -0
  57. data/test/backend/simple/api_test.rb +27 -20
  58. data/test/backend/simple/helpers_test.rb +26 -0
  59. data/test/backend/simple/lookup_test.rb +2 -1
  60. data/test/backend/simple/{setup/localization.rb → setup.rb} +29 -11
  61. data/test/backend/simple/translations_test.rb +1 -6
  62. data/test/{string_test.rb → core_ext/string/interpolate_test.rb} +4 -2
  63. data/test/fixtures/locales/de.po +67 -0
  64. data/test/fixtures/locales/en.rb +2 -0
  65. data/test/fixtures/locales/plurals.rb +113 -0
  66. data/test/gettext/api_test.rb +204 -0
  67. data/test/gettext/backend_test.rb +84 -0
  68. data/test/i18n_exceptions_test.rb +3 -1
  69. data/test/i18n_load_path_test.rb +8 -1
  70. data/test/i18n_test.rb +30 -7
  71. data/test/locale/fallbacks_test.rb +128 -0
  72. data/test/locale/tag/rfc4646_test.rb +145 -0
  73. data/test/locale/tag/simple_test.rb +35 -0
  74. data/test/test_helper.rb +11 -5
  75. data/test/with_options.rb +2 -0
  76. metadata +75 -11
  77. data/test/backend/simple/setup/base.rb +0 -21
@@ -0,0 +1,67 @@
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!"
62
+
63
+ #: app/views/cars/nowhere_really
64
+ msgid "Car|wheel"
65
+ msgid_plural "Car|wheels"
66
+ msgstr[0] "Rad"
67
+ msgstr[1] "Räder"
@@ -1 +1,3 @@
1
+ # encoding: utf-8
2
+
1
3
  { :en => { :fuh => { :bah => "bas" } } }
@@ -0,0 +1,113 @@
1
+ # encoding: utf-8
2
+
3
+ {
4
+ :af => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
5
+ :am => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
6
+ :ar => { :i18n => { :plural => { :keys => [:zero, :one, :two, :few, :many, :other], :rule => lambda { |n| n == 0 ? :zero : n == 1 ? :one : n == 2 ? :two : [3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99].include?(n % 100) ? :many : :other } } } },
7
+ :az => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
8
+ :be => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
9
+ :bg => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
10
+ :bh => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
11
+ :bn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
12
+ :bo => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
13
+ :bs => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
14
+ :ca => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
15
+ :cs => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } },
16
+ :cy => { :i18n => { :plural => { :keys => [:one, :two, :many, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : n == 8 || n == 11 ? :many : :other } } } },
17
+ :da => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
18
+ :de => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
19
+ :dz => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
20
+ :el => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
21
+ :en => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
22
+ :eo => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
23
+ :es => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
24
+ :et => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
25
+ :eu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
26
+ :fa => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
27
+ :fi => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
28
+ :fil => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
29
+ :fo => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
30
+ :fr => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n && n != 2 ? :one : :other } } } },
31
+ :fur => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
32
+ :fy => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
33
+ :ga => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
34
+ :gl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
35
+ :gu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
36
+ :guw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
37
+ :ha => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
38
+ :he => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
39
+ :hi => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
40
+ :hr => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
41
+ :hu => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
42
+ :id => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
43
+ :is => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
44
+ :it => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
45
+ :iw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
46
+ :ja => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
47
+ :jv => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
48
+ :ka => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
49
+ :km => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
50
+ :kn => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
51
+ :ko => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
52
+ :ku => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
53
+ :lb => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
54
+ :ln => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
55
+ :lt => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n % 10 == 1 && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :one : [2, 3, 4, 5, 6, 7, 8, 9].include?(n % 10) && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :few : :other } } } },
56
+ :lv => { :i18n => { :plural => { :keys => [:zero, :one, :other], :rule => lambda { |n| n == 0 ? :zero : n % 10 == 1 && n % 100 != 11 ? :one : :other } } } },
57
+ :mg => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
58
+ :mk => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n % 10 == 1 ? :one : :other } } } },
59
+ :ml => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
60
+ :mn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
61
+ :mo => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } } },
62
+ :mr => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
63
+ :ms => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
64
+ :mt => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 || [2, 3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :many : :other } } } },
65
+ :my => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
66
+ :nah => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
67
+ :nb => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
68
+ :ne => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
69
+ :nl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
70
+ :nn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
71
+ :no => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
72
+ :nso => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
73
+ :om => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
74
+ :or => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
75
+ :pa => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
76
+ :pap => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
77
+ :pl => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) && ![22, 23, 24].include?(n % 100) ? :few : :other } } } },
78
+ :ps => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
79
+ :pt => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
80
+ :"pt-PT" => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
81
+ :ro => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } } },
82
+ :ru => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
83
+ :se => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
84
+ :sh => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
85
+ :sk => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } },
86
+ :sl => { :i18n => { :plural => { :keys => [:one, :two, :few, :other], :rule => lambda { |n| n % 100 == 1 ? :one : n % 100 == 2 ? :two : [3, 4].include?(n % 100) ? :few : :other } } } },
87
+ :sma => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
88
+ :smi => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
89
+ :smj => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
90
+ :smn => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
91
+ :sms => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
92
+ :so => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
93
+ :sq => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
94
+ :sr => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
95
+ :sv => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
96
+ :sw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
97
+ :ta => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
98
+ :te => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
99
+ :th => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
100
+ :ti => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
101
+ :tk => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
102
+ :tl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
103
+ :to => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
104
+ :tr => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
105
+ :uk => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
106
+ :ur => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
107
+ :vi => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
108
+ :wa => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
109
+ :yo => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
110
+ :zh => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
111
+ :zu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }
112
+ }
113
+
@@ -0,0 +1,204 @@
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 => { "A special apple#{I18n::Gettext::PLURAL_SEPARATOR}{{count}} special apples" => { :one => 'Ein spezieller Apfel', :other => '{{count}} spezielle Äpfel' } },
17
+ # alternative implementation
18
+ "An apple" => { :one => 'Ein Apfel', :other => '{{count}} Äpfel' },
19
+ :special => { "A special apple" => { :one => 'Ein spezieller Apfel', :other => '{{count}} spezielle Äpfel' } },
20
+ :foo => { :bar => 'bar-de' }
21
+ }
22
+ end
23
+
24
+ # gettext
25
+ def test_gettext_uses_msg_as_default
26
+ assert_equal 'Hi Gettext!', _('Hi Gettext!')
27
+ end
28
+
29
+ def test_gettext_uses_msg_as_key
30
+ I18n.locale = :de
31
+ assert_equal 'Hallo Gettext!', gettext('Hi Gettext!')
32
+ assert_equal 'Hallo Gettext!', _('Hi Gettext!')
33
+ end
34
+
35
+ def test_gettext_uses_msg_containing_dots_as_default
36
+ assert_equal 'Sentence 1. Sentence 2.', gettext('Sentence 1. Sentence 2.')
37
+ assert_equal 'Sentence 1. Sentence 2.', _('Sentence 1. Sentence 2.')
38
+ end
39
+
40
+ def test_gettext_uses_msg_containing_dots_as_key
41
+ I18n.locale = :de
42
+ assert_equal 'Satz 1. Satz 2.', gettext('Sentence 1. Sentence 2.')
43
+ assert_equal 'Satz 1. Satz 2.', _('Sentence 1. Sentence 2.')
44
+ end
45
+
46
+ # sgettext
47
+ def test_sgettext_defaults_to_the_last_token_of_a_scoped_msgid
48
+ assert_equal 'bar', sgettext('foo|bar')
49
+ assert_equal 'bar', s_('foo|bar')
50
+ end
51
+
52
+ def test_sgettext_looks_up_a_scoped_translation
53
+ I18n.locale = :de
54
+ assert_equal 'bar-de', sgettext('foo|bar')
55
+ assert_equal 'bar-de', s_('foo|bar')
56
+ end
57
+
58
+ # pgettext
59
+ def test_pgettext_defaults_to_msgid
60
+ assert_equal 'bar', pgettext('foo', 'bar')
61
+ assert_equal 'bar', p_('foo', 'bar')
62
+ end
63
+
64
+ def test_pgettext_looks_up_a_scoped_translation
65
+ I18n.locale = :de
66
+ assert_equal 'bar-de', pgettext('foo', 'bar')
67
+ assert_equal 'bar-de', p_('foo', 'bar')
68
+ end
69
+
70
+ # ngettext
71
+ def test_ngettext_looks_up_msg_id_as_default_singular
72
+ assert_equal 'An apple', ngettext('An apple', '{{count}} apples', 1)
73
+ assert_equal 'An apple', n_('An apple', '{{count}} apples', 1)
74
+ end
75
+
76
+ def test_ngettext_looks_up_msg_id_plural_as_default_plural
77
+ assert_equal '2 apples', ngettext('An apple', '{{count}} apples', 2)
78
+ assert_equal '2 apples', n_('An apple', '{{count}} apples', 2)
79
+ end
80
+
81
+ def test_ngettext_looks_up_a_singular
82
+ I18n.locale = :de
83
+ assert_equal 'Ein Apfel', ngettext('An apple', '{{count}} apples', 1)
84
+ assert_equal 'Ein Apfel', n_('An apple', '{{count}} apples', 1)
85
+ end
86
+
87
+ def test_ngettext_looks_up_a_plural
88
+ I18n.locale = :de
89
+ assert_equal '2 Äpfel', ngettext('An apple', '{{count}} apples', 2)
90
+ assert_equal '2 Äpfel', n_('An apple', '{{count}} apples', 2)
91
+ end
92
+
93
+ def test_ngettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
94
+ assert_equal 'An apple', ngettext(['An apple', '{{count}} apples'], 1)
95
+ assert_equal 'An apple', n_(['An apple', '{{count}} apples'], 1)
96
+ end
97
+
98
+ def test_ngettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
99
+ assert_equal '2 apples', ngettext(['An apple', '{{count}} apples'], 2)
100
+ assert_equal '2 apples', n_(['An apple', '{{count}} apples'], 2)
101
+ end
102
+
103
+ def test_ngettext_looks_up_a_singular_with_alternative_syntax
104
+ I18n.locale = :de
105
+ assert_equal 'Ein Apfel', ngettext(['An apple', '{{count}} apples'], 1)
106
+ assert_equal 'Ein Apfel', n_(['An apple', '{{count}} apples'], 1)
107
+ end
108
+
109
+ def test_ngettext_looks_up_a_plural_with_alternative_syntax
110
+ I18n.locale = :de
111
+ assert_equal '2 Äpfel', ngettext(['An apple', '{{count}} apples'], 2)
112
+ assert_equal '2 Äpfel', n_(['An apple', '{{count}} apples'], 2)
113
+ end
114
+
115
+ # nsgettext
116
+ def test_nsgettext_looks_up_msg_id_as_default_singular
117
+ assert_equal 'A special apple', nsgettext('special|A special apple', '{{count}} special apples', 1)
118
+ assert_equal 'A special apple', ns_('special|A special apple', '{{count}} special apples', 1)
119
+ end
120
+
121
+ def test_nsgettext_looks_up_msg_id_plural_as_default_plural
122
+ assert_equal '2 special apples', nsgettext('special|A special apple', '{{count}} special apples', 2)
123
+ assert_equal '2 special apples', ns_('special|A special apple', '{{count}} special apples', 2)
124
+ end
125
+
126
+ def test_nsgettext_looks_up_a_singular
127
+ I18n.locale = :de
128
+ assert_equal 'Ein spezieller Apfel', nsgettext('special|A special apple', '{{count}} special apples', 1)
129
+ assert_equal 'Ein spezieller Apfel', ns_('special|A special apple', '{{count}} special apples', 1)
130
+ end
131
+
132
+ def test_nsgettext_looks_up_a_plural
133
+ I18n.locale = :de
134
+ assert_equal '2 spezielle Äpfel', nsgettext('special|A special apple', '{{count}} special apples', 2)
135
+ assert_equal '2 spezielle Äpfel', ns_('special|A special apple', '{{count}} special apples', 2)
136
+ end
137
+
138
+ def test_nsgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
139
+ assert_equal 'A special apple', nsgettext(['special|A special apple', '{{count}} special apples'], 1)
140
+ assert_equal 'A special apple', ns_(['special|A special apple', '{{count}} special apples'], 1)
141
+ end
142
+
143
+ def test_nsgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
144
+ assert_equal '2 special apples', nsgettext(['special|A special apple', '{{count}} special apples'], 2)
145
+ assert_equal '2 special apples', ns_(['special|A special apple', '{{count}} special apples'], 2)
146
+ end
147
+
148
+ def test_nsgettext_looks_up_a_singular_with_alternative_syntax
149
+ I18n.locale = :de
150
+ assert_equal 'Ein spezieller Apfel', nsgettext(['special|A special apple', '{{count}} special apples'], 1)
151
+ assert_equal 'Ein spezieller Apfel', ns_(['special|A special apple', '{{count}} special apples'], 1)
152
+ end
153
+
154
+ def test_nsgettext_looks_up_a_plural_with_alternative_syntax
155
+ I18n.locale = :de
156
+ assert_equal '2 spezielle Äpfel', nsgettext(['special|A special apple', '{{count}} special apples'], 2)
157
+ assert_equal '2 spezielle Äpfel', ns_(['special|A special apple', '{{count}} special apples'], 2)
158
+ end
159
+
160
+ # npgettext
161
+ def test_npgettext_looks_up_msg_id_as_default_singular
162
+ assert_equal 'A special apple', npgettext('special', 'A special apple', '{{count}} special apples', 1)
163
+ assert_equal 'A special apple', np_('special', 'A special apple', '{{count}} special apples', 1)
164
+ end
165
+
166
+ def test_npgettext_looks_up_msg_id_plural_as_default_plural
167
+ assert_equal '2 special apples', npgettext('special', 'A special apple', '{{count}} special apples', 2)
168
+ assert_equal '2 special apples', np_('special', 'A special apple', '{{count}} special apples', 2)
169
+ end
170
+
171
+ def test_npgettext_looks_up_a_singular
172
+ I18n.locale = :de
173
+ assert_equal 'Ein spezieller Apfel', npgettext('special', 'A special apple', '{{count}} special apples', 1)
174
+ assert_equal 'Ein spezieller Apfel', np_('special', 'A special apple', '{{count}} special apples', 1)
175
+ end
176
+
177
+ def test_npgettext_looks_up_a_plural
178
+ I18n.locale = :de
179
+ assert_equal '2 spezielle Äpfel', npgettext('special', 'A special apple', '{{count}} special apples', 2)
180
+ assert_equal '2 spezielle Äpfel', np_('special', 'A special apple', '{{count}} special apples', 2)
181
+ end
182
+
183
+ def test_npgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
184
+ assert_equal 'A special apple', npgettext('special', ['A special apple', '{{count}} special apples'], 1)
185
+ assert_equal 'A special apple', np_('special', ['A special apple', '{{count}} special apples'], 1)
186
+ end
187
+
188
+ def test_npgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
189
+ assert_equal '2 special apples', npgettext('special', ['A special apple', '{{count}} special apples'], 2)
190
+ assert_equal '2 special apples', np_('special', ['A special apple', '{{count}} special apples'], 2)
191
+ end
192
+
193
+ def test_npgettext_looks_up_a_singular_with_alternative_syntax
194
+ I18n.locale = :de
195
+ assert_equal 'Ein spezieller Apfel', npgettext('special', ['A special apple', '{{count}} special apples'], 1)
196
+ assert_equal 'Ein spezieller Apfel', np_('special', ['A special apple', '{{count}} special apples'], 1)
197
+ end
198
+
199
+ def test_npgettext_looks_up_a_plural_with_alternative_syntax
200
+ I18n.locale = :de
201
+ assert_equal '2 spezielle Äpfel', npgettext('special', ['A special apple', '{{count}} special apples'], 2)
202
+ assert_equal '2 spezielle Äpfel', np_('special', ['A special apple', '{{count}} special apples'], 2)
203
+ end
204
+ end
@@ -0,0 +1,84 @@
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
+ class I18nGettextBackendTest < Test::Unit::TestCase
8
+ include I18n::Helpers::Gettext
9
+
10
+ class Backend
11
+ include I18n::Backend::Base
12
+ include I18n::Backend::Gettext
13
+ end
14
+
15
+ def setup
16
+ I18n.backend = Backend.new
17
+ I18n.locale = :en
18
+ I18n.load_path = [locales_dir + '/de.po']
19
+ end
20
+
21
+ def teardown
22
+ I18n.load_path = nil
23
+ I18n.backend = nil
24
+ end
25
+
26
+ def test_backend_loads_po_file
27
+ I18n.backend.send(:init_translations)
28
+ assert I18n.backend.send(:translations)[:de][:"Axis"]
29
+ end
30
+
31
+ def test_looks_up_a_translation
32
+ I18n.locale = :de
33
+ assert_equal 'Auto', gettext('car')
34
+ end
35
+
36
+ def test_uses_default_translation
37
+ assert_equal 'car', gettext('car')
38
+ end
39
+
40
+ def test_looks_up_a_namespaced_translation
41
+ I18n.locale = :de
42
+ assert_equal 'Räderzahl', sgettext('Car|Wheels count')
43
+ assert_equal 'Räderzahl', pgettext('Car', 'Wheels count')
44
+ end
45
+
46
+ def test_uses_namespaced_default_translation
47
+ assert_equal 'Wheels count', sgettext('Car|Wheels count')
48
+ assert_equal 'Wheels count', pgettext('Car', 'Wheels count')
49
+ end
50
+
51
+ def test_pluralizes_entry
52
+ I18n.locale = :de
53
+ assert_equal 'Achse', ngettext('Axis', 'Axis', 1)
54
+ assert_equal 'Achsen', ngettext('Axis', 'Axis', 2)
55
+ end
56
+
57
+ def test_pluralizes_default_entry
58
+ assert_equal 'Axis', ngettext('Axis', 'Axis', 1)
59
+ assert_equal 'Axis', ngettext('Axis', 'Axis', 2)
60
+ end
61
+
62
+ def test_pluralizes_namespaced_entry
63
+ I18n.locale = :de
64
+ assert_equal 'Rad', nsgettext('Car|wheel', 'wheels', 1)
65
+ assert_equal 'Räder', nsgettext('Car|wheel', 'wheels', 2)
66
+ assert_equal 'Rad', npgettext('Car', 'wheel', 'wheels', 1)
67
+ assert_equal 'Räder', npgettext('Car', 'wheel', 'wheels', 2)
68
+ end
69
+
70
+ def test_pluralizes_namespaced_default_entry
71
+ assert_equal 'wheel', nsgettext('Car|wheel', 'wheels', 1)
72
+ assert_equal 'wheels', nsgettext('Car|wheel', 'wheels', 2)
73
+ assert_equal 'wheel', npgettext('Car', 'wheel', 'wheels', 1)
74
+ assert_equal 'wheels', npgettext('Car', 'wheel', 'wheels', 2)
75
+ end
76
+
77
+ def test_pluralizes_namespaced_entry_with_alternative_syntax
78
+ I18n.locale = :de
79
+ assert_equal 'Rad', nsgettext(['Car|wheel', 'wheels'], 1)
80
+ assert_equal 'Räder', nsgettext(['Car|wheel', 'wheels'], 2)
81
+ assert_equal 'Rad', npgettext('Car', ['wheel', 'wheels'], 1)
82
+ assert_equal 'Räder', npgettext('Car', ['wheel', 'wheels'], 2)
83
+ end
84
+ end