sayso-i18n 0.5.0.001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/CHANGELOG.textile +152 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +103 -0
  4. data/ci/Gemfile.no-rails +5 -0
  5. data/ci/Gemfile.no-rails.lock +14 -0
  6. data/ci/Gemfile.rails-2.3.x +9 -0
  7. data/ci/Gemfile.rails-2.3.x.lock +23 -0
  8. data/ci/Gemfile.rails-3.x +9 -0
  9. data/ci/Gemfile.rails-3.x.lock +23 -0
  10. data/lib/i18n.rb +324 -0
  11. data/lib/i18n/backend.rb +19 -0
  12. data/lib/i18n/backend/base.rb +174 -0
  13. data/lib/i18n/backend/cache.rb +102 -0
  14. data/lib/i18n/backend/cascade.rb +53 -0
  15. data/lib/i18n/backend/chain.rb +80 -0
  16. data/lib/i18n/backend/fallbacks.rb +70 -0
  17. data/lib/i18n/backend/flatten.rb +113 -0
  18. data/lib/i18n/backend/flatten_yml.rb +70 -0
  19. data/lib/i18n/backend/gettext.rb +71 -0
  20. data/lib/i18n/backend/interpolation_compiler.rb +121 -0
  21. data/lib/i18n/backend/key_value.rb +100 -0
  22. data/lib/i18n/backend/memoize.rb +46 -0
  23. data/lib/i18n/backend/metadata.rb +65 -0
  24. data/lib/i18n/backend/pluralization.rb +55 -0
  25. data/lib/i18n/backend/simple.rb +87 -0
  26. data/lib/i18n/backend/transliterator.rb +98 -0
  27. data/lib/i18n/config.rb +86 -0
  28. data/lib/i18n/core_ext/hash.rb +29 -0
  29. data/lib/i18n/core_ext/kernel/surpress_warnings.rb +9 -0
  30. data/lib/i18n/core_ext/string/interpolate.rb +105 -0
  31. data/lib/i18n/exceptions.rb +88 -0
  32. data/lib/i18n/gettext.rb +25 -0
  33. data/lib/i18n/gettext/helpers.rb +64 -0
  34. data/lib/i18n/gettext/po_parser.rb +329 -0
  35. data/lib/i18n/interpolate/ruby.rb +31 -0
  36. data/lib/i18n/locale.rb +6 -0
  37. data/lib/i18n/locale/fallbacks.rb +96 -0
  38. data/lib/i18n/locale/tag.rb +28 -0
  39. data/lib/i18n/locale/tag/parents.rb +22 -0
  40. data/lib/i18n/locale/tag/rfc4646.rb +74 -0
  41. data/lib/i18n/locale/tag/simple.rb +39 -0
  42. data/lib/i18n/tests.rb +12 -0
  43. data/lib/i18n/tests/basics.rb +54 -0
  44. data/lib/i18n/tests/defaults.rb +40 -0
  45. data/lib/i18n/tests/interpolation.rb +133 -0
  46. data/lib/i18n/tests/link.rb +56 -0
  47. data/lib/i18n/tests/localization.rb +19 -0
  48. data/lib/i18n/tests/localization/date.rb +84 -0
  49. data/lib/i18n/tests/localization/date_time.rb +77 -0
  50. data/lib/i18n/tests/localization/procs.rb +116 -0
  51. data/lib/i18n/tests/localization/time.rb +76 -0
  52. data/lib/i18n/tests/lookup.rb +74 -0
  53. data/lib/i18n/tests/pluralization.rb +35 -0
  54. data/lib/i18n/tests/procs.rb +55 -0
  55. data/lib/i18n/version.rb +3 -0
  56. data/test/all.rb +8 -0
  57. data/test/api/all_features_test.rb +58 -0
  58. data/test/api/cascade_test.rb +28 -0
  59. data/test/api/chain_test.rb +24 -0
  60. data/test/api/fallbacks_test.rb +30 -0
  61. data/test/api/flatten_yml_test.rb +32 -0
  62. data/test/api/key_value_test.rb +28 -0
  63. data/test/api/memoize_test.rb +60 -0
  64. data/test/api/pluralization_test.rb +30 -0
  65. data/test/api/simple_test.rb +28 -0
  66. data/test/backend/cache_test.rb +83 -0
  67. data/test/backend/cascade_test.rb +85 -0
  68. data/test/backend/chain_test.rb +72 -0
  69. data/test/backend/exceptions_test.rb +23 -0
  70. data/test/backend/fallbacks_test.rb +120 -0
  71. data/test/backend/flatten_yml_test.rb +49 -0
  72. data/test/backend/interpolation_compiler_test.rb +102 -0
  73. data/test/backend/key_value_test.rb +46 -0
  74. data/test/backend/memoize_test.rb +47 -0
  75. data/test/backend/metadata_test.rb +67 -0
  76. data/test/backend/pluralization_test.rb +44 -0
  77. data/test/backend/simple_test.rb +83 -0
  78. data/test/backend/transliterator_test.rb +81 -0
  79. data/test/core_ext/hash_test.rb +30 -0
  80. data/test/core_ext/string/interpolate_test.rb +99 -0
  81. data/test/gettext/api_test.rb +206 -0
  82. data/test/gettext/backend_test.rb +93 -0
  83. data/test/i18n/exceptions_test.rb +116 -0
  84. data/test/i18n/interpolate_test.rb +61 -0
  85. data/test/i18n/load_path_test.rb +26 -0
  86. data/test/i18n_test.rb +236 -0
  87. data/test/locale/fallbacks_test.rb +124 -0
  88. data/test/locale/tag/rfc4646_test.rb +142 -0
  89. data/test/locale/tag/simple_test.rb +32 -0
  90. data/test/run_all.rb +21 -0
  91. data/test/test_data/locales/de.po +72 -0
  92. data/test/test_data/locales/en.rb +3 -0
  93. data/test/test_data/locales/en.yml +3 -0
  94. data/test/test_data/locales/invalid/empty.yml +1 -0
  95. data/test/test_data/locales/plurals.rb +113 -0
  96. data/test/test_helper.rb +56 -0
  97. metadata +194 -0
@@ -0,0 +1,152 @@
1
+ h1. Changelog
2
+
3
+ h2. 0.5.0
4
+
5
+ * "Extract Backend::ActiveRecord to a separate gem":https://github.com/svenfuchs/i18n/commit/197dacebad356b910d69fa69a719c2ad10cf49e6 (see "i18n-active_record":https://github.com/svenfuchs/i18n-active_record)
6
+ * "Improve exception handling":https://github.com/svenfuchs/i18n/commit/2913ff9a7544f223f60e7d7b32c2a0e1af89812b (deprectates I18n.default_exception_handler)
7
+ * "Change MissingTranslationData message to 'translation missing: foo.bar'":https://github.com/svenfuchs/i18n/commit/68fdfe47952325411afe5942e971ce10b2bdf900
8
+ * "Expose MissingTranslationsData#keys method":https://github.com/svenfuchs/i18n/commit/3a37a389ecaac9670355b334e23e775549ee9822
9
+ * "Improve Cascade#lookup (add default options)":https://github.com/svenfuchs/i18n/commit/0b9a1f2058a2be9543106cc19d08071c359511e1
10
+ * "Finally remove deprecated interpolation syntax":https://github.com/svenfuchs/i18n/commit/2d43846d2b2a2e596f30fa58ea1c9ddb2243bb64
11
+
12
+ h2. 0.4.2 (2010-10-26)
13
+
14
+ * "Improve UTF8 handling":http://github.com/svenfuchs/i18n/commit/e8d5820a3b08eeca28de1a2b9c8a6ad2b9e6476c
15
+ * "Expose I18n::VERSION":http://github.com/svenfuchs/i18n/commit/b832037bac94c7144f45f3ff5e3b4e4089781726
16
+ * "Better deprecation output":http://github.com/svenfuchs/i18n/commit/2bee924464b8a9c33d3d7852eb1c8423aa38cc25
17
+
18
+ h2. 0.4.1 (2010-06-05)
19
+
20
+ * "Fix interpolation failure on Ruby 1.9":http://github.com/svenfuchs/i18n/commit/8d45bedb11c4136c00e853d104b00a8e67ec4894
21
+
22
+ h2. 0.4.0 (2010-05-27)
23
+
24
+ * "The localization proc also receives the object as option":http://github.com/svenfuchs/i18n/commit/4a8cd9fa660daaa3078e24c5851353ca377d9213
25
+
26
+ h2. 0.4.0.beta1 (2010-05-03)
27
+
28
+ * "Renamed Fast backend to Memoize backend":http://github.com/svenfuchs/i18n/commit/f7f7dc12c00a19d3876223771e14f8671ff313cd
29
+
30
+ * "Deprecate {{}} as interpolation syntax":http://github.com/svenfuchs/i18n/commit/8894ee521ef5788c415b625a6daf522af4c416e0
31
+
32
+ * "Allow nil translation to be stored again":http://github.com/svenfuchs/i18n/commit/f2074f1e82d10c2e9a801c8cc2f2a0c7c30703ba
33
+
34
+ h2. 0.4.0.beta (2010-04-30)
35
+
36
+ * "Added a KeyValue backend":http://github.com/svenfuchs/i18n/commit/28ca5f53ade7f545f8c0804e93564d4686b416a4
37
+
38
+ * "Added transliteration support":http://github.com/svenfuchs/i18n/commit/928fdb4794959e779e90f360eb01ba043672d8d5
39
+
40
+ * "Create Flatten backend module to aid handling flatten translations":http://github.com/svenfuchs/i18n/commit/2ec9d6998aa8facd7b15a3ef47a96cf2471cd8a1
41
+
42
+ * "Decouple the external separator (used when storing translations) from the internal separator in Fast and ActiveRecord backends":http://github.com/svenfuchs/i18n/commit/274cb4daa0ca5e3b2bd23b45eb7f9fc58f75a79d
43
+
44
+ h2. 0.3.7 (2010-04-17)
45
+
46
+ * "Speed up I18n.normalize_keys by caching reused normalizations and producing less garbage":http://github.com/svenfuchs/i18n/commit/819dac0fea9c29e6545801aa107e63e355728cd4
47
+
48
+ h2. 0.3.6 (2010-03-23)
49
+
50
+ * "Move gettext po parser to lib":http://github.com/svenfuchs/i18n/commit/b2f038663b55727ac2327e6f07a46ba5d69d600c
51
+
52
+ * "Move I18n configuration to I18n.config":http://github.com/svenfuchs/i18n/commit/4a7baea86663ead8c681008c3e80a622f0546b07
53
+
54
+ h2. 0.3.5 (2010-02-26)
55
+
56
+ * "Delegate I18n.normalize_translation_keys to I18n.normalize_keys and deprecate
57
+ the former":http://github.com/svenfuchs/i18n/commit/7284b04d5f5dd9679cb68875515cdd0cdfc96fef
58
+
59
+ h2. 0.3.4 (2010-02-25)
60
+
61
+ * "Rename I18n.normalize_translation_keys to I18n.normalize_keys and finally make it public":http://github.com/svenfuchs/i18n/commit/20b05fe5802df6c90fb70a4e3760b2b851b791b3
62
+
63
+ * "Added CLDR supoprt":http://github.com/svenfuchs/i18n/commit/860eadf671a231e7f5dffb1bb27fa318ff7a8786
64
+
65
+ h2. 0.3.3 (2009-12-29)
66
+
67
+ * "Use lib/i18n/version":http://github.com/svenfuchs/i18n/commit/ff426c8e7a2438b814cb303adadec292dacb752e
68
+
69
+ * "Added a benchmark suite":http://github.com/svenfuchs/i18n/commit/f9b5b9b113097724638bdab96862ffa404e67e70
70
+
71
+ * "Ensure links can be handled recursively":http://github.com/svenfuchs/i18n/commit/2c50bd209f3fc24fe9dfa694c81be64340f09b7d
72
+
73
+ * "Make sure we can lookup false values as translation data":http://github.com/svenfuchs/i18n/commit/561c82ba4b8921d03bfdf56cb2d0c2f287629001
74
+
75
+ * "Added Fast backend module":http://github.com/svenfuchs/i18n/commit/bd2f09f0a251ca793b0e8ecc7e32177a2f091c23
76
+
77
+ * "Added InterpolationCompiler backend module":http://github.com/svenfuchs/i18n/commit/91810887d1abfb28996a9183bc9004678290d28b
78
+
79
+ h2. 0.3.2 (2009-12-12)
80
+
81
+ * "Added Cascade backend":http://github.com/svenfuchs/i18n/commit/8009aef293e9ef8564c9005090d8380feabcaf6f
82
+
83
+ h2. 0.3.1 (2009-12-11)
84
+
85
+ * "Add PoParser to gemspec":http://github.com/svenfuchs/i18n/commit/d6b2763f39c932f66adb039b96882a472f883c51
86
+ * "Enable custom separators for ActiveRecord backend":http://github.com/svenfuchs/i18n/commit/9341d3fcfc951cc31807ba672d2b5d90909ef3e5
87
+ * "Pass interpolation values to interpolation procs":http://github.com/svenfuchs/i18n/commit/39c2ed8fbad645671cd5520ce7ad0aeefe2b0cca
88
+ * "Fix that ngettext supports keys with dots":http://github.com/svenfuchs/i18n/commit/7362a43c34364d500de8899cfcca6bf1a5e6d1c8
89
+
90
+ h2. 0.3.0 (2009-11-30)
91
+
92
+ * "Gettext backend and helpers":http://github.com/svenfuchs/i18n/commit/35a1740d2f10b808548af352006950da4017e374
93
+ * "Metadata module":http://github.com/svenfuchs/i18n/commit/2677208555179b36fcbe958c0e8bc642cf5bc020
94
+ * "Basic ActiveRecord backend":http://github.com/svenfuchs/i18n/commit/786632d0b42de423ecf0969622efc87f1691e2a2
95
+ * "Set encoding to UTF8 for all files":http://github.com/svenfuchs/i18n/commit/9be3d4a311b5bf583eec5d39986176cc40c112f2
96
+ * "Chain backend":http://github.com/svenfuchs/i18n/commit/08259ffb88b3005403648d77bc1cbca0b92f3cf5
97
+ * "Backend/cache implementation":http://github.com/svenfuchs/i18n/commit/e7bf15351cd2e27f5972eb40e65a5dd6f4a0feed
98
+ * "Pluralization module":http://github.com/svenfuchs/i18n/commit/9ca4c9ed52d4706566a6abeb2d78722dcc5d4764
99
+ * "add and adapt Globalize2 fallback implementation":http://github.com/svenfuchs/i18n/commit/1b37a303b27d6222b17162804b06323e5628768f
100
+ * "move Simple backend implementation to a Base backend class and extend Simple from Base.":http://github.com/svenfuchs/i18n/commit/32ddc80a04e6aa247f6d6613bde7f78c73396cb4
101
+
102
+ h2. 0.2.0 (2009-07-12)
103
+
104
+ * "Allow using Ruby 1.9 syntax for string interpolation (API addition)":http://github.com/svenfuchs/i18n/commit/c6e0b06d512f2af57199a843a1d8a40241b32861
105
+ * "Allow configuring the default scope separator, allow to pass a custom scope separator(API addition)":http://github.com/svenfuchs/i18n/commit/5b75bfbc348061adc11e3790187a187275bfd471 (e.g. I18n.t(:'foo|bar', :separator => '|')
106
+ * "Pass :format option to #translate for #localize more useful lambda support":http://github.com/svenfuchs/i18n/commit/e277711b3c844fe7589b8d3f9af0f7d1b969a273
107
+ * "Refactor Simple backend #resolve to #default and #resolve for more consistency. Now allows to pass lambdas as defaults and re-resolve Symbols":http://github.com/svenfuchs/i18n/commit/8c4ce3d923ce5fa73e973fe28217e18165549aba
108
+ * "Add lambda support to #translate (API addition)":http://github.com/svenfuchs/i18n/commit/c90e62d8f7d3d5b78f34cfe328d871b58884f115
109
+ * "Add lambda support to #localize (API addition)":http://github.com/svenfuchs/i18n/commit/9d390afcf33f3f469bb95e6888147152f6cc7442
110
+
111
+ h2. 0.1.3 (2009-02-27)
112
+
113
+ * "Remove unnecessary string encoding handling in the i18n simple backend which made the backend break on Ruby 1.9":http://github.com/svenfuchs/i18n/commit/4c3a970783861a94f2e89f46714fb3434e4f4f8d
114
+
115
+ h2. 0.1.2 (2009-01-09)
116
+
117
+ * "added #available_locales (returns an array of locales for which translations are available)":http://github.com/svenfuchs/i18n/commit/411f8fe7c8f3f89e9b6b921fa62ed66cb92f3af4
118
+ * "flatten load_path before using it so that a nested array of paths won't throw up":http://github.com/svenfuchs/i18n/commit/d473a068a2b90aba98135deb225d6eb6d8104d70
119
+
120
+ h2. 0.1.1 (2008-11-20)
121
+
122
+ * "Use :'en' as a default locale (in favor of :'en-US')":http://github.com/svenfuchs/i18n/commit/c4b10b246aecf7da78cb2568dd0d2ab7e6b8a230
123
+ * "Add #reload! to Simple backend":http://github.com/svenfuchs/i18n/commit/36dd2bd9973b9e1559728749a9daafa44693e964
124
+
125
+ h2. 0.1.0 (2008-10-25)
126
+
127
+ * "Fix Simple backend to distinguish false from nil values":http://github.com/svenfuchs/i18n/commit/39d9a47da14b5f3ba126af48923af8c30e135166
128
+ * "Add #load_path to public api, add initialize to simple backend and remove #load_translations from public api":http://github.com/svenfuchs/i18n/commit/c4c5649e6bc8f020f1aaf5a5470bde048e22c82d
129
+ * "Speed up Backend::Simple#interpolate":http://github.com/svenfuchs/i18n/commit/9e1ac6bf8833304e036323ec9932b9f33c468a35
130
+ * "Remove #populate and #store_translations from public API":http://github.com/svenfuchs/i18n/commit/f4e514a80be7feb509f66824ee311905e2940900
131
+ * "Use :other instead of :many as a plural key":http://github.com/svenfuchs/i18n/commit/0f8f20a2552bf6a2aa758d8fdd62a7154e4a1bf6
132
+ * "Use a class instead of a module for Simple backend":http://github.com/svenfuchs/i18n/commit/08f051aa61320c17debde24a83268bc74e33b995
133
+ * "Make Simple backend #interpolate deal with non-ASCII string encodings":http://github.com/svenfuchs/i18n/commit/d84a3f3f55543c084d5dc5d1fed613b8df148789
134
+ * "Fix default arrays of non-existant keys returning the default array":http://github.com/svenfuchs/i18n/commit/6c04ca86c87f97dc78f07c2a4023644e5ba8b839
135
+
136
+ h2. Initial implementation (June/July 2008)
137
+
138
+ Initial implementation by "Sven Fuchs":http://www.workingwithrails.com/person/9963-sven-fuchs based on previous discussion/consensus of the rails-i18n team (alphabetical order) and many others:
139
+
140
+ * "Matt Aimonetti":http://railsontherun.com
141
+ * "Sven Fuchs":http://www.workingwithrails.com/person/9963-sven-fuchs
142
+ * "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
143
+ * "Saimon Moore":http://saimonmoore.net
144
+ * "Stephan Soller":http://www.arkanis-development.de
145
+
146
+ h2. More information
147
+
148
+ * "Homepage":http://rails-i18n.org
149
+ * "Wiki":http://rails-i18n.org/wiki
150
+ * "Mailinglist":http://groups.google.com/group/rails-i18n
151
+ * "About the project/history":http://www.artweb-design.de/2008/7/18/finally-ruby-on-rails-gets-internationalized
152
+ * "Initial API Intro":http://www.artweb-design.de/2008/7/18/the-ruby-on-rails-i18n-core-api
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 The Ruby I18n team
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,103 @@
1
+ h1. Ruby I18n
2
+
3
+ Ruby Internationalization and localization solution.
4
+
5
+ Features:
6
+
7
+ * translation and localization
8
+ * interpolation of values to translations (Ruby 1.9 compatible syntax)
9
+ * pluralization (CLDR compatible)
10
+ * customizable transliteration to ASCII
11
+ * flexible defaults
12
+ * bulk lookup
13
+ * lambdas as translation data
14
+ * custom key/scope separator
15
+ * custom exception handlers
16
+ * extensible architecture with a swappable backend
17
+
18
+ Pluggable features:
19
+
20
+ * Cache
21
+ * Pluralization: lambda pluralizers stored as translation data
22
+ * Locale fallbacks, RFC4647 compliant (optionally: RFC4646 locale validation)
23
+ * Gettext support
24
+ * Translation metadata
25
+
26
+ Alternative backends:
27
+
28
+ * Chain
29
+ * ActiveRecord (optionally: ActiveRecord::Missing and ActiveRecord::StoreProcs)
30
+ * KeyValue (uses active_support/json and cannot store procs)
31
+
32
+ For more information and lots of resources see: "http://ruby-i18n.org/wiki":http://ruby-i18n.org/wiki
33
+
34
+ h2. Installation
35
+
36
+ gem install i18n
37
+
38
+ h4. Rails version warning
39
+
40
+ On Rails < 2.3.6 the method I18n.localize will fail with MissingInterpolationArgument (issue "20":http://github.com/svenfuchs/i18n/issues/issue/20). Upgrade to Rails 2.3.6 or higher (2.3.8 preferably) is recommended.
41
+
42
+ h3. Installation on Rails < 2.3.5 (deprecated)
43
+
44
+ Up to version 2.3.4 Rails will not accept i18n gems > 0.1.3. There is an unpacked
45
+ gem inside of active_support/lib/vendor which gets loaded unless gem 'i18n', '~> 0.1.3'.
46
+ This requirement is relaxed in "6da03653":http://github.com/rails/rails/commit/6da03653
47
+
48
+ The new i18n gem can be loaded from vendor/plugins like this:
49
+
50
+ <pre>
51
+ def reload_i18n!
52
+ raise "Move to i18n version 0.2.0 or greater" if Rails.version > "2.3.4"
53
+
54
+ $:.grep(/i18n/).each { |path| $:.delete(path) }
55
+ I18n::Backend.send :remove_const, "Simple"
56
+ $: << Rails.root.join('vendor', 'plugins', 'i18n', 'lib').to_s
57
+ end
58
+ </pre>
59
+
60
+ Then you can `reload_i18n!` inside an i18n initializer.
61
+
62
+ h2. Tests
63
+
64
+ You can run tests both with
65
+
66
+ * `rake test` or just `rake`
67
+ * run any test file directly, e.g. `ruby -Ilib -Itest test/api/simple_test.rb`
68
+ * run all tests with `ruby -Ilib -Itest test/all.rb`
69
+
70
+ You can run all tests against all Gemfiles with
71
+
72
+ * `ruby test/run_all.rb`
73
+
74
+ The structure of the test suite is a bit unusual as it uses modules to reuse
75
+ particular tests in different test cases.
76
+
77
+ The reason for this is that we need to enforce the I18n API across various
78
+ combinations of extensions. E.g. the Simple backend alone needs to support
79
+ the same API as any combination of feature and/or optimization modules included
80
+ to the Simple backend. We test this by reusing the same API defition (implemented
81
+ as test methods) in test cases with different setups.
82
+
83
+ You can find the test cases that enforce the API in test/api. And you can find
84
+ the API definition test methods in test/api/tests.
85
+
86
+ All other test cases (e.g. as defined in test/backend, test/core\_ext) etc.
87
+ follow the usual test setup and should be easy to grok.
88
+
89
+ h2. Authors
90
+
91
+ * "Sven Fuchs":http://www.artweb-design.de
92
+ * "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
93
+ * "Stephan Soller":http://www.arkanis-development.de
94
+ * "Saimon Moore":http://saimonmoore.net
95
+ * "Matt Aimonetti":http://railsontherun.com
96
+
97
+ h2. Contributors
98
+
99
+ http://github.com/svenfuchs/i18n/contributors
100
+
101
+ h2. License
102
+
103
+ MIT License. See the included MIT-LICENSE file.
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'mocha'
4
+ gem 'test_declarative'
5
+
@@ -0,0 +1,14 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ mocha (0.9.9)
5
+ rake
6
+ rake (0.8.7)
7
+ test_declarative (0.0.4)
8
+
9
+ PLATFORMS
10
+ ruby
11
+
12
+ DEPENDENCIES
13
+ mocha
14
+ test_declarative
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gem 'activesupport', '~> 2.3'
4
+ gem 'sqlite3-ruby'
5
+ gem 'mocha'
6
+ gem 'test_declarative'
7
+ gem 'rufus-tokyo'
8
+ gem 'ffi'
9
+
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (2.3.10)
5
+ ffi (0.6.3)
6
+ rake (>= 0.8.7)
7
+ mocha (0.9.9)
8
+ rake
9
+ rake (0.8.7)
10
+ rufus-tokyo (1.0.7)
11
+ sqlite3-ruby (1.3.2)
12
+ test_declarative (0.0.4)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ activesupport (~> 2.3)
19
+ ffi
20
+ mocha
21
+ rufus-tokyo
22
+ sqlite3-ruby
23
+ test_declarative
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gem 'activesupport', '~> 3.0.0'
4
+ gem 'sqlite3-ruby'
5
+ gem 'mocha'
6
+ gem 'test_declarative'
7
+ gem 'rufus-tokyo'
8
+ gem 'ffi'
9
+
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.0.3)
5
+ ffi (0.6.3)
6
+ rake (>= 0.8.7)
7
+ mocha (0.9.9)
8
+ rake
9
+ rake (0.8.7)
10
+ rufus-tokyo (1.0.7)
11
+ sqlite3-ruby (1.3.2)
12
+ test_declarative (0.0.4)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ activesupport (~> 3.0.0)
19
+ ffi
20
+ mocha
21
+ rufus-tokyo
22
+ sqlite3-ruby
23
+ test_declarative
@@ -0,0 +1,324 @@
1
+ require 'i18n/version'
2
+ require 'i18n/exceptions'
3
+ require 'i18n/interpolate/ruby'
4
+
5
+ module I18n
6
+ autoload :Backend, 'i18n/backend'
7
+ autoload :Config, 'i18n/config'
8
+ autoload :Gettext, 'i18n/gettext'
9
+ autoload :Locale, 'i18n/locale'
10
+ autoload :Tests, 'i18n/tests'
11
+
12
+ RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :format, :cascade, :raise, :rescue_format]
13
+ RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
14
+
15
+ class << self
16
+ # Gets I18n configuration object.
17
+ def config
18
+ Thread.current[:i18n_config] ||= I18n::Config.new
19
+ end
20
+
21
+ # Sets I18n configuration object.
22
+ def config=(value)
23
+ Thread.current[:i18n_config] = value
24
+ end
25
+
26
+ # Write methods which delegates to the configuration object
27
+ %w(locale backend default_locale available_locales default_separator
28
+ exception_handler load_path).each do |method|
29
+ module_eval <<-DELEGATORS, __FILE__, __LINE__ + 1
30
+ def #{method}
31
+ config.#{method}
32
+ end
33
+
34
+ def #{method}=(value)
35
+ config.#{method} = (value)
36
+ end
37
+ DELEGATORS
38
+ end
39
+
40
+ # Tells the backend to reload translations. Used in situations like the
41
+ # Rails development environment. Backends can implement whatever strategy
42
+ # is useful.
43
+ def reload!
44
+ config.backend.reload!
45
+ end
46
+
47
+ # Translates, pluralizes and interpolates a given key using a given locale,
48
+ # scope, and default, as well as interpolation values.
49
+ #
50
+ # *LOOKUP*
51
+ #
52
+ # Translation data is organized as a nested hash using the upper-level keys
53
+ # as namespaces. <em>E.g.</em>, ActionView ships with the translation:
54
+ # <tt>:date => {:formats => {:short => "%b %d"}}</tt>.
55
+ #
56
+ # Translations can be looked up at any level of this hash using the key argument
57
+ # and the scope option. <em>E.g.</em>, in this example <tt>I18n.t :date</tt>
58
+ # returns the whole translations hash <tt>{:formats => {:short => "%b %d"}}</tt>.
59
+ #
60
+ # Key can be either a single key or a dot-separated key (both Strings and Symbols
61
+ # work). <em>E.g.</em>, the short format can be looked up using both:
62
+ # I18n.t 'date.formats.short'
63
+ # I18n.t :'date.formats.short'
64
+ #
65
+ # Scope can be either a single key, a dot-separated key or an array of keys
66
+ # or dot-separated keys. Keys and scopes can be combined freely. So these
67
+ # examples will all look up the same short date format:
68
+ # I18n.t 'date.formats.short'
69
+ # I18n.t 'formats.short', :scope => 'date'
70
+ # I18n.t 'short', :scope => 'date.formats'
71
+ # I18n.t 'short', :scope => %w(date formats)
72
+ #
73
+ # *INTERPOLATION*
74
+ #
75
+ # Translations can contain interpolation variables which will be replaced by
76
+ # values passed to #translate as part of the options hash, with the keys matching
77
+ # the interpolation variable names.
78
+ #
79
+ # <em>E.g.</em>, with a translation <tt>:foo => "foo %{bar}"</tt> the option
80
+ # value for the key +bar+ will be interpolated into the translation:
81
+ # I18n.t :foo, :bar => 'baz' # => 'foo baz'
82
+ #
83
+ # *PLURALIZATION*
84
+ #
85
+ # Translation data can contain pluralized translations. Pluralized translations
86
+ # are arrays of singluar/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
87
+ #
88
+ # Note that <tt>I18n::Backend::Simple</tt> only supports an algorithm for English
89
+ # pluralization rules. Other algorithms can be supported by custom backends.
90
+ #
91
+ # This returns the singular version of a pluralized translation:
92
+ # I18n.t :foo, :count => 1 # => 'Foo'
93
+ #
94
+ # These both return the plural version of a pluralized translation:
95
+ # I18n.t :foo, :count => 0 # => 'Foos'
96
+ # I18n.t :foo, :count => 2 # => 'Foos'
97
+ #
98
+ # The <tt>:count</tt> option can be used both for pluralization and interpolation.
99
+ # <em>E.g.</em>, with the translation
100
+ # <tt>:foo => ['%{count} foo', '%{count} foos']</tt>, count will
101
+ # be interpolated to the pluralized translation:
102
+ # I18n.t :foo, :count => 1 # => '1 foo'
103
+ #
104
+ # *DEFAULTS*
105
+ #
106
+ # This returns the translation for <tt>:foo</tt> or <tt>default</tt> if no translation was found:
107
+ # I18n.t :foo, :default => 'default'
108
+ #
109
+ # This returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt> if no
110
+ # translation for <tt>:foo</tt> was found:
111
+ # I18n.t :foo, :default => :bar
112
+ #
113
+ # Returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt>
114
+ # or <tt>default</tt> if no translations for <tt>:foo</tt> and <tt>:bar</tt> were found.
115
+ # I18n.t :foo, :default => [:bar, 'default']
116
+ #
117
+ # *BULK LOOKUP*
118
+ #
119
+ # This returns an array with the translations for <tt>:foo</tt> and <tt>:bar</tt>.
120
+ # I18n.t [:foo, :bar]
121
+ #
122
+ # Can be used with dot-separated nested keys:
123
+ # I18n.t [:'baz.foo', :'baz.bar']
124
+ #
125
+ # Which is the same as using a scope option:
126
+ # I18n.t [:foo, :bar], :scope => :baz
127
+ #
128
+ # *LAMBDAS*
129
+ #
130
+ # Both translations and defaults can be given as Ruby lambdas. Lambdas will be
131
+ # called and passed the key and options.
132
+ #
133
+ # E.g. assuming the key <tt>:salutation</tt> resolves to:
134
+ # lambda { |key, options| options[:gender] == 'm' ? "Mr. %{options[:name]}" : "Mrs. %{options[:name]}" }
135
+ #
136
+ # Then <tt>I18n.t(:salutation, :gender => 'w', :name => 'Smith') will result in "Mrs. Smith".
137
+ #
138
+ # It is recommended to use/implement lambdas in an "idempotent" way. E.g. when
139
+ # a cache layer is put in front of I18n.translate it will generate a cache key
140
+ # from the argument values passed to #translate. Therefor your lambdas should
141
+ # always return the same translations/values per unique combination of argument
142
+ # values.
143
+ def translate(*args)
144
+ options = args.last.is_a?(Hash) ? args.pop : {}
145
+ key = args.shift
146
+ backend = config.backend
147
+ locale = options.delete(:locale) || config.locale
148
+ raises = options.delete(:raise)
149
+
150
+ raise I18n::ArgumentError if key.is_a?(String) && key.empty?
151
+
152
+ if key.is_a?(Array)
153
+ key.map { |k| backend.translate(locale, k, options) }
154
+ else
155
+ backend.translate(locale, key, options)
156
+ end
157
+ rescue I18n::ArgumentError => exception
158
+ raise exception if raises
159
+ handle_exception(exception, locale, key, options)
160
+ end
161
+ alias :t :translate
162
+
163
+ def translate!(key, options={})
164
+ translate(key, options.merge(:raise => true))
165
+ end
166
+ alias :t! :translate!
167
+
168
+ # Transliterates UTF-8 characters to ASCII. By default this method will
169
+ # transliterate only Latin strings to an ASCII approximation:
170
+ #
171
+ # I18n.transliterate("Ærøskøbing")
172
+ # # => "AEroskobing"
173
+ #
174
+ # I18n.transliterate("日本語")
175
+ # # => "???"
176
+ #
177
+ # It's also possible to add support for per-locale transliterations. I18n
178
+ # expects transliteration rules to be stored at
179
+ # <tt>i18n.transliterate.rule</tt>.
180
+ #
181
+ # Transliteration rules can either be a Hash or a Proc. Procs must accept a
182
+ # single string argument. Hash rules inherit the default transliteration
183
+ # rules, while Procs do not.
184
+ #
185
+ # *Examples*
186
+ #
187
+ # Setting a Hash in <locale>.yml:
188
+ #
189
+ # i18n:
190
+ # transliterate:
191
+ # rule:
192
+ # ü: "ue"
193
+ # ö: "oe"
194
+ #
195
+ # Setting a Hash using Ruby:
196
+ #
197
+ # store_translations(:de, :i18n => {
198
+ # :transliterate => {
199
+ # :rule => {
200
+ # "ü" => "ue",
201
+ # "ö" => "oe"
202
+ # }
203
+ # }
204
+ # )
205
+ #
206
+ # Setting a Proc:
207
+ #
208
+ # translit = lambda {|string| MyTransliterator.transliterate(string) }
209
+ # store_translations(:xx, :i18n => {:transliterate => {:rule => translit})
210
+ #
211
+ # Transliterating strings:
212
+ #
213
+ # I18n.locale = :en
214
+ # I18n.transliterate("Jürgen") # => "Jurgen"
215
+ # I18n.locale = :de
216
+ # I18n.transliterate("Jürgen") # => "Juergen"
217
+ # I18n.transliterate("Jürgen", :locale => :en) # => "Jurgen"
218
+ # I18n.transliterate("Jürgen", :locale => :de) # => "Juergen"
219
+ def transliterate(*args)
220
+ options = args.pop if args.last.is_a?(Hash)
221
+ key = args.shift
222
+ locale = options && options.delete(:locale) || config.locale
223
+ raises = options && options.delete(:raise)
224
+ replacement = options && options.delete(:replacement)
225
+ config.backend.transliterate(locale, key, replacement)
226
+ rescue I18n::ArgumentError => exception
227
+ raise exception if raises
228
+ handle_exception(exception, locale, key, options)
229
+ end
230
+
231
+ # Localizes certain objects, such as dates and numbers to local formatting.
232
+ def localize(object, options = {})
233
+ locale = options.delete(:locale) || config.locale
234
+ format = options.delete(:format) || :default
235
+ config.backend.localize(locale, object, format, options)
236
+ end
237
+ alias :l :localize
238
+
239
+ # Executes block with given I18n.locale set.
240
+ def with_locale(tmp_locale = nil)
241
+ if tmp_locale
242
+ current_locale = self.locale
243
+ self.locale = tmp_locale
244
+ end
245
+ yield
246
+ ensure
247
+ self.locale = current_locale if tmp_locale
248
+ end
249
+
250
+ # Merges the given locale, key and scope into a single array of keys.
251
+ # Splits keys that contain dots into multiple keys. Makes sure all
252
+ # keys are Symbols.
253
+ def normalize_keys(locale, key, scope, separator = nil)
254
+ separator ||= I18n.default_separator
255
+
256
+ keys = []
257
+ keys.concat normalize_key(locale, separator)
258
+ keys.concat normalize_key(scope, separator)
259
+ keys.concat normalize_key(key, separator)
260
+ keys
261
+ end
262
+
263
+ # making these private until Ruby 1.9.2 can send to protected methods again
264
+ # see http://redmine.ruby-lang.org/repositories/revision/ruby-19?rev=24280
265
+ private
266
+
267
+ # Any exceptions thrown in translate will be sent to the @@exception_handler
268
+ # which can be a Symbol, a Proc or any other Object.
269
+ #
270
+ # If exception_handler is a Symbol then it will simply be sent to I18n as
271
+ # a method call. A Proc will simply be called. In any other case the
272
+ # method #call will be called on the exception_handler object.
273
+ #
274
+ # Examples:
275
+ #
276
+ # I18n.exception_handler = :default_exception_handler # this is the default
277
+ # I18n.default_exception_handler(exception, locale, key, options) # will be called like this
278
+ #
279
+ # I18n.exception_handler = lambda { |*args| ... } # a lambda
280
+ # I18n.exception_handler.call(exception, locale, key, options) # will be called like this
281
+ #
282
+ # I18n.exception_handler = I18nExceptionHandler.new # an object
283
+ # I18n.exception_handler.call(exception, locale, key, options) # will be called like this
284
+ def handle_exception(exception, locale, key, options)
285
+ case handler = options[:exception_handler] || config.exception_handler
286
+ when Symbol
287
+ send(handler, exception, locale, key, options)
288
+ else
289
+ handler.call(exception, locale, key, options)
290
+ end
291
+ end
292
+
293
+ def normalize_key(key, separator)
294
+ normalized_key_cache[separator][key] ||=
295
+ case key
296
+ when Array
297
+ key.map { |k| normalize_key(k, separator) }.flatten
298
+ else
299
+ keys = key.to_s.split(separator)
300
+ keys.delete('')
301
+ keys.map!{ |k| k.to_sym }
302
+ keys
303
+ end
304
+ end
305
+
306
+ def normalized_key_cache
307
+ @normalized_key_cache ||= Hash.new { |h,k| h[k] = {} }
308
+ end
309
+
310
+ # DEPRECATED. Use I18n.normalize_keys instead.
311
+ def normalize_translation_keys(locale, key, scope, separator = nil)
312
+ puts "I18n.normalize_translation_keys is deprecated. Please use the class I18n.normalize_keys instead."
313
+ normalize_keys(locale, key, scope, separator)
314
+ end
315
+
316
+ # DEPRECATED. Please use the I18n::ExceptionHandler class instead.
317
+ def default_exception_handler(exception, locale, key, options)
318
+ puts "I18n.default_exception_handler is deprecated. Please use the class I18n::ExceptionHandler instead " +
319
+ "(an instance of which is set to I18n.exception_handler by default)."
320
+ return exception.message if MissingTranslationData === exception
321
+ raise exception
322
+ end
323
+ end
324
+ end