Skip to content
Browse files

Update bundled i18n gem to 0.4.1 to make sure every project will be w…

…arn about using deprecated %{..} interpolation.

This will also make sure that by changing {{..}} into %{..} won't break any Rails 2.3.x application, since it would load the vendored version if it's not satisfy the version requirement.

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 08302d2 commit 54a5088cd56d28303c1af204b9f632083ff6a3f5 @sikachu sikachu committed with josevalim Jun 20, 2010
Showing with 5,141 additions and 517 deletions.
  1. +2 −2 activesupport/lib/active_support/vendor.rb
  2. +0 −66 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/backend/active_record.rb
  3. +0 −69 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/backend/fast.rb
  4. +0 −68 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/backend/helpers.rb
  5. +0 −34 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/backend/links.rb
  6. +0 −22 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/backend/simple.rb
  7. +0 −8 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/except.rb
  8. +0 −8 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/slice.rb
  9. +0 −5 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/object/meta_class.rb
  10. +0 −5 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/helpers.rb
  11. +0 −3 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/version.rb
  12. +135 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/CHANGELOG.textile
  13. +20 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/MIT-LICENSE
  14. +93 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/README.textile
  15. +24 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/Rakefile
  16. +148 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/benchmark/example.yml
  17. +116 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/benchmark/run.rb
  18. +20 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/i18n.gemspec
  19. +1 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/init.rb
  20. +92 −105 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n.rb
  21. +5 −4 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend.rb
  22. +61 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/backend/active_record.rb
  23. +4 −6 ...ort/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/active_record/missing.rb
  24. 0 ...lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/active_record/store_procs.rb
  25. +8 −3 ...lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/active_record/translation.rb
  26. +55 −84 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/base.rb
  27. +1 −0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/cache.rb
  28. +0 −1 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/cascade.rb
  29. +3 −1 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/chain.rb
  30. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/cldr.rb
  31. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/fallbacks.rb
  32. +113 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/backend/flatten.rb
  33. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/gettext.rb
  34. +8 −4 ...rt/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/interpolation_compiler.rb
  35. +102 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/backend/key_value.rb
  36. +48 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/backend/memoize.rb
  37. +5 −13 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/metadata.rb
  38. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/backend/pluralization.rb
  39. +87 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/backend/simple.rb
  40. +98 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/backend/transliterator.rb
  41. +84 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/config.rb
  42. +29 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/core_ext/hash.rb
  43. +3 −4 ...pport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/core_ext/string/interpolate.rb
  44. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/exceptions.rb
  45. +2 −0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/gettext.rb
  46. +2 −2 ...tive_support/vendor/{i18n-0.3.7/i18n/helpers/gettext.rb → i18n-0.4.1/lib/i18n/gettext/helpers.rb}
  47. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/gettext/po_parser.rb
  48. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/locale.rb
  49. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/locale/fallbacks.rb
  50. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/locale/tag.rb
  51. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/locale/tag/parents.rb
  52. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/locale/tag/rfc4646.rb
  53. 0 activesupport/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1/lib}/i18n/locale/tag/simple.rb
  54. +3 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/version.rb
  55. +8 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/all.rb
  56. +18 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api.rb
  57. +30 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/active_record_test.rb
  58. +57 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/all_features_test.rb
  59. +31 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/cascade_test.rb
  60. +27 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/chain_test.rb
  61. +33 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/fallbacks_test.rb
  62. +31 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/key_value_test.rb
  63. +62 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/memoize_test.rb
  64. +33 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/pluralization_test.rb
  65. +22 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/simple_test.rb
  66. +24 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/basics.rb
  67. +40 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/defaults.rb
  68. +108 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/interpolation.rb
  69. +56 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/link.rb
  70. +84 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/localization/date.rb
  71. +77 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/localization/date_time.rb
  72. +117 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/localization/procs.rb
  73. +76 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/localization/time.rb
  74. +70 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/lookup.rb
  75. +35 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/pluralization.rb
  76. +55 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/api/tests/procs.rb
  77. +51 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/active_record/missing_test.rb
  78. +57 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/active_record_test.rb
  79. +70 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/cache_test.rb
  80. +72 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/cascade_test.rb
  81. +63 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/chain_test.rb
  82. +150 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/cldr_test.rb
  83. +25 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/exceptions_test.rb
  84. +104 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/fallbacks_test.rb
  85. +105 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/interpolation_compiler_test.rb
  86. +50 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/key_value_test.rb
  87. +15 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/memoize_test.rb
  88. +69 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/metadata_test.rb
  89. +46 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/pluralization_test.rb
  90. +81 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/simple_test.rb
  91. +83 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/backend/transliterator_test.rb
  92. +33 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/core_ext/hash_test.rb
  93. +100 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/core_ext/string/interpolate_test.rb
  94. +207 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/gettext/api_test.rb
  95. +90 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/gettext/backend_test.rb
  96. +97 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/i18n_exceptions_test.rb
  97. +23 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/i18n_load_path_test.rb
  98. +244 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/i18n_test.rb
  99. +126 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/locale/fallbacks_test.rb
  100. +143 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/locale/tag/rfc4646_test.rb
  101. +33 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/locale/tag/simple_test.rb
  102. +152 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/test_data/locales/cldr/de/calendars.yml
  103. +8 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/test_data/locales/cldr/de/currencies.yml
  104. +31 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/test_data/locales/cldr/de/numbers.yml
  105. +72 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/test_data/locales/de.po
  106. +3 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/test_data/locales/en.rb
  107. +3 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/test_data/locales/en.yml
  108. +113 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/test_data/locales/plurals.rb
  109. +85 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/test_helper.rb
  110. +71 −0 activesupport/lib/active_support/vendor/i18n-0.4.1/test/test_setup_requirements.rb
View
4 activesupport/lib/active_support/vendor.rb
@@ -21,9 +21,9 @@
end
begin
- gem 'i18n', '>= 0.3.3'
+ gem 'i18n', '>= 0.4.1'
rescue Gem::LoadError
- $:.unshift "#{File.dirname(__FILE__)}/vendor/i18n-0.3.7"
+ $:.unshift "#{File.dirname(__FILE__)}/vendor/i18n-0.4.1"
end
require 'i18n'
View
66 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/backend/active_record.rb
@@ -1,66 +0,0 @@
-require 'i18n/backend/base'
-require 'i18n/backend/active_record/translation'
-
-module I18n
- module Backend
- class ActiveRecord
- autoload :Missing, 'i18n/backend/active_record/missing'
- autoload :StoreProcs, 'i18n/backend/active_record/store_procs'
- autoload :Translation, 'i18n/backend/active_record/translation'
-
- include Base, Links
-
- def reload!
- end
-
- def store_translations(locale, data, options = {})
- separator = options[:separator] || I18n.default_separator
- wind_keys(data, separator).each do |key, value|
- store_link(locale, key, value) if value.is_a?(Symbol)
- Translation.locale(locale).lookup(expand_keys(key, separator), separator).delete_all
- Translation.create(:locale => locale.to_s, :key => key.to_s, :value => value)
- end
- end
-
- def available_locales
- begin
- Translation.available_locales
- rescue ::ActiveRecord::StatementInvalid
- []
- end
- end
-
- protected
-
- def lookup(locale, key, scope = [], options = {})
- return unless key
-
- separator = options[:separator] || I18n.default_separator
-
- key = resolve_link(locale, key)
- key = (Array(scope) + Array(key)).join(separator)
- result = Translation.locale(locale).lookup(key, separator).all
-
- if result.empty?
- return nil
- elsif result.first.key == key
- return result.first.value
- else
- chop_range = (key.size + separator.size)..-1
- result = result.inject({}) do |hash, r|
- hash[r.key.slice(chop_range)] = r.value
- hash
- end
- deep_symbolize_keys(unwind_keys(result, separator))
- end
- end
-
- # For a key :'foo.bar.baz' return ['foo', 'foo.bar', 'foo.bar.baz']
- def expand_keys(key, separator = I18n.default_separator)
- key.to_s.split(separator).inject([]) do |keys, key|
- keys << [keys.last, key].compact.join(separator)
- end
- end
- end
- end
-end
View
69 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/backend/fast.rb
@@ -1,69 +0,0 @@
-# encoding: utf-8
-
-# The Fast module contains optimizations that can tremendously speed up the
-# lookup process on the Simple backend. It works by flattening the nested
-# translation hash to a flat hash (e.g. { :a => { :b => 'c' } } becomes
-# { :'a.b' => 'c' }).
-#
-# To enable these optimizations you can simply include the Fast module to
-# the Simple backend:
-#
-# I18n::Backend::Simple.send(:include, I18n::Backend::Fast)
-module I18n
- module Backend
- module Fast
- include Links
-
- def reset_flattened_translations!
- @flattened_translations = nil
- end
-
- def flattened_translations
- @flattened_translations ||= flatten_translations(translations)
- end
-
- def merge_translations(locale, data, options = {})
- super
- reset_flattened_translations!
- end
-
- def init_translations
- super
- reset_flattened_translations!
- end
-
- protected
- def flatten_translations(translations)
- # don't flatten locale roots
- translations.inject({}) do |result, (locale, translations)|
- result[locale] = wind_keys(translations, nil, true)
- result[locale].each do |key, value|
- store_link(locale, key, value) if value.is_a?(Symbol)
- end
- result
- end
- end
-
- def lookup(locale, key, scope = nil, options = {})
- return unless key
- init_translations unless initialized?
-
- return nil unless flattened_translations.has_key?(locale.to_sym)
-
- separator = options[:separator]
- if separator && I18n.default_separator != separator
- key = cleanup_non_standard_separator(key, separator)
- scope = Array(scope).map{|k| cleanup_non_standard_separator(k, separator)} if scope
- end
-
- key = resolve_link(locale, key)
- key = (Array(scope) + [key]).join(I18n.default_separator) if scope
- flattened_translations[locale.to_sym][key.to_sym]
- end
-
- def cleanup_non_standard_separator(key, user_separator)
- escape_default_separator(key).tr(user_separator, I18n.default_separator)
- end
- end
- end
-end
View
68 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/backend/helpers.rb
@@ -1,68 +0,0 @@
-module I18n
- module Backend
- module Helpers
- SEPARATOR_ESCAPE_CHAR = "\001"
-
- # Return a new hash with all keys and nested keys converted to symbols.
- def deep_symbolize_keys(hash)
- hash.inject({}) { |result, (key, value)|
- value = deep_symbolize_keys(value) if value.is_a?(Hash)
- result[(key.to_sym rescue key) || key] = value
- result
- }
- end
-
- # Flatten keys for nested Hashes by chaining up keys using the separator
- # >> { "a" => { "b" => { "c" => "d", "e" => "f" }, "g" => "h" }, "i" => "j"}.wind
- # => { "a.b.c" => "d", "a.b.e" => "f", "a.g" => "h", "i" => "j" }
- def wind_keys(hash, separator = nil, subtree = false, prev_key = nil, result = {}, orig_hash=hash)
- separator ||= I18n.default_separator
-
- hash.each_pair do |key, value|
- key = escape_default_separator(key, separator)
- curr_key = [prev_key, key].compact.join(separator).to_sym
-
- if value.is_a?(Hash)
- result[curr_key] = value if subtree
- wind_keys(value, separator, subtree, curr_key, result, orig_hash)
- else
- result[unescape_default_separator(curr_key)] = value
- end
- end
-
- result
- end
-
- def escape_default_separator(key, separator=nil)
- key.to_s.tr(separator || I18n.default_separator, SEPARATOR_ESCAPE_CHAR)
- end
-
- def unescape_default_separator(key, separator=nil)
- key.to_s.tr(SEPARATOR_ESCAPE_CHAR, separator || I18n.default_separator).to_sym
- end
-
- # Expand keys chained by the the given separator through nested Hashes
- # >> { "a.b.c" => "d", "a.b.e" => "f", "a.g" => "h", "i" => "j" }.unwind
- # => { "a" => { "b" => { "c" => "d", "e" => "f" }, "g" => "h" }, "i" => "j"}
- def unwind_keys(hash, separator = ".")
- result = {}
- hash.each do |key, value|
- keys = key.to_s.split(separator)
- curr = result
- curr = curr[keys.shift] ||= {} while keys.size > 1
- curr[keys.shift] = value
- end
- result
- end
-
- # # Flatten the given array once
- # def flatten_once(array)
- # result = []
- # for element in array # a little faster than each
- # result.push(*element)
- # end
- # result
- # end
- end
- end
-end
View
34 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/backend/links.rb
@@ -1,34 +0,0 @@
-module I18n
- module Backend
- module Links
- protected
- def links(locale)
- @links ||= {}
- @links[locale.to_sym] ||= {}
- end
-
- def store_link(locale, key, link)
- links(locale)[key.to_s] = link.to_s
- end
-
- def resolve_link(locale, key)
- key = key.to_s
- links = self.links(locale)
-
- if links.key?(key)
- links[key]
- elsif link = find_link(locale, key)
- store_link(locale, key, key.gsub(*link))
- else
- key
- end
- end
-
- def find_link(locale, key)
- links(locale).each do |from, to|
- return [from, to] if key[0, from.length] == from
- end && nil
- end
- end
- end
-end
View
22 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/backend/simple.rb
@@ -1,22 +0,0 @@
-# encoding: utf-8
-
-# Stub class for the Simple backend. The actual implementation is provided by
-# the backend Base class. This makes it easier to extend the Simple backend's
-# behaviour by including modules. E.g.:
-#
-# module I18n::Backend::Pluralization
-# def pluralize(*args)
-# # extended pluralization logic
-# super
-# end
-# end
-#
-# I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
-
-module I18n
- module Backend
- class Simple
- include Base
- end
- end
-end
View
8 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/except.rb
@@ -1,8 +0,0 @@
-# from facets (http://facets.rubyforge.org)
-require 'i18n/core_ext/hash/slice'
-
-class Hash
- def except(*less_keys)
- slice(*keys - less_keys)
- end
-end unless Hash.method_defined?(:except)
View
8 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/slice.rb
@@ -1,8 +0,0 @@
-# from facets (http://facets.rubyforge.org)
-class Hash
- def slice(*keep_keys)
- h = {}
- keep_keys.each { |key| h[key] = fetch(key) }
- h
- end
-end unless Hash.new.respond_to?(:slice)
View
5 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/object/meta_class.rb
@@ -1,5 +0,0 @@
-Object.class_eval do
- def meta_class
- class << self; self; end
- end
-end unless Object.method_defined?(:meta_class)
View
5 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/helpers.rb
@@ -1,5 +0,0 @@
-module I18n
- module Helpers
- autoload :Gettext, 'i18n/helpers/gettext'
- end
-end
View
3 activesupport/lib/active_support/vendor/i18n-0.3.7/i18n/version.rb
@@ -1,3 +0,0 @@
-module I18n
- VERSION = "0.3.7"
-end
View
135 activesupport/lib/active_support/vendor/i18n-0.4.1/CHANGELOG.textile
@@ -0,0 +1,135 @@
+h1. Changelog
+
+h2. master
+
+h2. 0.4.0 (2010-05-27)
+
+* "The localization proc also receives the object as option":http://github.com/svenfuchs/i18n/commit/4a8cd9fa660daaa3078e24c5851353ca377d9213
+
+h2. 0.4.0.beta1 (2010-05-03)
+
+* "Renamed Fast backend to Memoize backend":http://github.com/svenfuchs/i18n/commit/f7f7dc12c00a19d3876223771e14f8671ff313cd
+
+* "Deprecate {{}} as interpolation syntax":http://github.com/svenfuchs/i18n/commit/8894ee521ef5788c415b625a6daf522af4c416e0
+
+* "Allow nil translation to be stored again":http://github.com/svenfuchs/i18n/commit/f2074f1e82d10c2e9a801c8cc2f2a0c7c30703ba
+
+h2. 0.4.0.beta (2010-04-30)
+
+* "Added a KeyValue backend":http://github.com/svenfuchs/i18n/commit/28ca5f53ade7f545f8c0804e93564d4686b416a4
+
+* "Added transliteration support":http://github.com/svenfuchs/i18n/commit/928fdb4794959e779e90f360eb01ba043672d8d5
+
+* "Create Flatten backend module to aid handling flatten translations":http://github.com/svenfuchs/i18n/commit/2ec9d6998aa8facd7b15a3ef47a96cf2471cd8a1
+
+* "Decouple the external separator (used when storing translations) from the internal separator in Fast and ActiveRecord backends":http://github.com/svenfuchs/i18n/commit/274cb4daa0ca5e3b2bd23b45eb7f9fc58f75a79d
+
+h2. 0.3.7 (2010-04-17)
+
+* "Speed up I18n.normalize_keys by caching reused normalizations and producing less garbage":http://github.com/svenfuchs/i18n/commit/819dac0fea9c29e6545801aa107e63e355728cd4
+
+h2. 0.3.6 (2010-03-23)
+
+* "Move gettext po parser to lib":http://github.com/svenfuchs/i18n/commit/b2f038663b55727ac2327e6f07a46ba5d69d600c
+
+* "Move I18n configuration to I18n.config":http://github.com/svenfuchs/i18n/commit/4a7baea86663ead8c681008c3e80a622f0546b07
+
+h2. 0.3.5 (2010-02-26)
+
+* "Delegate I18n.normalize_translation_keys to I18n.normalize_keys and deprecate
+the former":http://github.com/svenfuchs/i18n/commit/7284b04d5f5dd9679cb68875515cdd0cdfc96fef
+
+h2. 0.3.4 (2010-02-25)
+
+* "Rename I18n.normalize_translation_keys to I18n.normalize_keys and finally make it public":http://github.com/svenfuchs/i18n/commit/20b05fe5802df6c90fb70a4e3760b2b851b791b3
+
+* "Added CLDR supoprt":http://github.com/svenfuchs/i18n/commit/860eadf671a231e7f5dffb1bb27fa318ff7a8786
+
+h2. 0.3.3 (2009-12-29)
+
+* "Use lib/i18n/version":http://github.com/svenfuchs/i18n/commit/ff426c8e7a2438b814cb303adadec292dacb752e
+
+* "Added a benchmark suite":http://github.com/svenfuchs/i18n/commit/f9b5b9b113097724638bdab96862ffa404e67e70
+
+* "Ensure links can be handled recursively":http://github.com/svenfuchs/i18n/commit/2c50bd209f3fc24fe9dfa694c81be64340f09b7d
+
+* "Make sure we can lookup false values as translation data":http://github.com/svenfuchs/i18n/commit/561c82ba4b8921d03bfdf56cb2d0c2f287629001
+
+* "Added Fast backend module":http://github.com/svenfuchs/i18n/commit/bd2f09f0a251ca793b0e8ecc7e32177a2f091c23
+
+* "Added InterpolationCompiler backend module":http://github.com/svenfuchs/i18n/commit/91810887d1abfb28996a9183bc9004678290d28b
+
+h2. 0.3.2 (2009-12-12)
+
+* "Added Cascade backend":http://github.com/svenfuchs/i18n/commit/8009aef293e9ef8564c9005090d8380feabcaf6f
+
+h2. 0.3.1 (2009-12-11)
+
+* "Add PoParser to gemspec":http://github.com/svenfuchs/i18n/commit/d6b2763f39c932f66adb039b96882a472f883c51
+* "Enable custom separators for ActiveRecord backend":http://github.com/svenfuchs/i18n/commit/9341d3fcfc951cc31807ba672d2b5d90909ef3e5
+* "Pass interpolation values to interpolation procs":http://github.com/svenfuchs/i18n/commit/39c2ed8fbad645671cd5520ce7ad0aeefe2b0cca
+* "Fix that ngettext supports keys with dots":http://github.com/svenfuchs/i18n/commit/7362a43c34364d500de8899cfcca6bf1a5e6d1c8
+
+h2. 0.3.0 (2009-11-30)
+
+* "Gettext backend and helpers":http://github.com/svenfuchs/i18n/commit/35a1740d2f10b808548af352006950da4017e374
+* "Metadata module":http://github.com/svenfuchs/i18n/commit/2677208555179b36fcbe958c0e8bc642cf5bc020
+* "Basic ActiveRecord backend":http://github.com/svenfuchs/i18n/commit/786632d0b42de423ecf0969622efc87f1691e2a2
+* "Set encoding to UTF8 for all files":http://github.com/svenfuchs/i18n/commit/9be3d4a311b5bf583eec5d39986176cc40c112f2
+* "Chain backend":http://github.com/svenfuchs/i18n/commit/08259ffb88b3005403648d77bc1cbca0b92f3cf5
+* "Backend/cache implementation":http://github.com/svenfuchs/i18n/commit/e7bf15351cd2e27f5972eb40e65a5dd6f4a0feed
+* "Pluralization module":http://github.com/svenfuchs/i18n/commit/9ca4c9ed52d4706566a6abeb2d78722dcc5d4764
+* "add and adapt Globalize2 fallback implementation":http://github.com/svenfuchs/i18n/commit/1b37a303b27d6222b17162804b06323e5628768f
+* "move Simple backend implementation to a Base backend class and extend Simple from Base.":http://github.com/svenfuchs/i18n/commit/32ddc80a04e6aa247f6d6613bde7f78c73396cb4
+
+h2. 0.2.0 (2009-07-12)
+
+* "Allow using Ruby 1.9 syntax for string interpolation (API addition)":http://github.com/svenfuchs/i18n/commit/c6e0b06d512f2af57199a843a1d8a40241b32861
+* "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 => '|')
+* "Pass :format option to #translate for #localize more useful lambda support":http://github.com/svenfuchs/i18n/commit/e277711b3c844fe7589b8d3f9af0f7d1b969a273
+* "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
+* "Add lambda support to #translate (API addition)":http://github.com/svenfuchs/i18n/commit/c90e62d8f7d3d5b78f34cfe328d871b58884f115
+* "Add lambda support to #localize (API addition)":http://github.com/svenfuchs/i18n/commit/9d390afcf33f3f469bb95e6888147152f6cc7442
+
+h2. 0.1.3 (2009-02-27)
+
+* "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
+
+h2. 0.1.2 (2009-01-09)
+
+* "added #available_locales (returns an array of locales for which translations are available)":http://github.com/svenfuchs/i18n/commit/411f8fe7c8f3f89e9b6b921fa62ed66cb92f3af4
+* "flatten load_path before using it so that a nested array of paths won't throw up":http://github.com/svenfuchs/i18n/commit/d473a068a2b90aba98135deb225d6eb6d8104d70
+
+h2. 0.1.1 (2008-11-20)
+
+* "Use :'en' as a default locale (in favor of :'en-US')":http://github.com/svenfuchs/i18n/commit/c4b10b246aecf7da78cb2568dd0d2ab7e6b8a230
+* "Add #reload! to Simple backend":http://github.com/svenfuchs/i18n/commit/36dd2bd9973b9e1559728749a9daafa44693e964
+
+h2. 0.1.0 (2008-10-25)
+
+* "Fix Simple backend to distinguish false from nil values":http://github.com/svenfuchs/i18n/commit/39d9a47da14b5f3ba126af48923af8c30e135166
+* "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
+* "Speed up Backend::Simple#interpolate":http://github.com/svenfuchs/i18n/commit/9e1ac6bf8833304e036323ec9932b9f33c468a35
+* "Remove #populate and #store_translations from public API":http://github.com/svenfuchs/i18n/commit/f4e514a80be7feb509f66824ee311905e2940900
+* "Use :other instead of :many as a plural key":http://github.com/svenfuchs/i18n/commit/0f8f20a2552bf6a2aa758d8fdd62a7154e4a1bf6
+* "Use a class instead of a module for Simple backend":http://github.com/svenfuchs/i18n/commit/08f051aa61320c17debde24a83268bc74e33b995
+* "Make Simple backend #interpolate deal with non-ASCII string encodings":http://github.com/svenfuchs/i18n/commit/d84a3f3f55543c084d5dc5d1fed613b8df148789
+* "Fix default arrays of non-existant keys returning the default array":http://github.com/svenfuchs/i18n/commit/6c04ca86c87f97dc78f07c2a4023644e5ba8b839
+
+h2. Initial implementation (June/July 2008)
+
+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:
+
+* "Matt Aimonetti":http://railsontherun.com
+* "Sven Fuchs":http://www.workingwithrails.com/person/9963-sven-fuchs
+* "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
+* "Saimon Moore":http://saimonmoore.net
+* "Stephan Soller":http://www.arkanis-development.de
+
+h2. More information
+
+* "Homepage":http://rails-i18n.org
+* "Wiki":http://rails-i18n.org/wiki
+* "Mailinglist":http://groups.google.com/group/rails-i18n
+* "About the project/history":http://www.artweb-design.de/2008/7/18/finally-ruby-on-rails-gets-internationalized
+* "Initial API Intro":http://www.artweb-design.de/2008/7/18/the-ruby-on-rails-i18n-core-api
View
20 activesupport/lib/active_support/vendor/i18n-0.4.1/MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 The Ruby I18n team
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
93 activesupport/lib/active_support/vendor/i18n-0.4.1/README.textile
@@ -0,0 +1,93 @@
+h1. Ruby I18n
+
+Ruby Internationalization and localization solution.
+
+Features:
+
+* translation and localization
+* interpolation of values to translations (Ruby 1.9 compatible syntax)
+* pluralization (CLDR compatible)
+* customizable transliteration to ASCII
+* flexible defaults
+* bulk lookup
+* lambdas as translation data
+* custom key/scope separator
+* custom exception handlers
+* extensible architecture with a swappable backend
+
+Pluggable features:
+
+* Cache
+* Pluralization: lambda pluralizers stored as translation data
+* Locale fallbacks, RFC4647 compliant (optionally: RFC4646 locale validation)
+* Gettext support
+* Translation metadata
+
+Alternative backends:
+
+* Chain
+* ActiveRecord (optionally: ActiveRecord::Missing and ActiveRecord::StoreProcs)
+* KeyValue (uses active_support/json and cannot store procs)
+
+For more information and lots of resources see: "http://rails-i18n.org/wiki":http://rails-i18n.org/wiki
+
+h2. Installation
+
+gem install i18n
+
+h3. Installation on Rails < 2.3.5 (deprecated)
+
+Up to version 2.3.4 Rails will not accept i18n gems > 0.1.3. There is an unpacked
+gem inside of active_support/lib/vendor which gets loaded unless gem 'i18n', '~> 0.1.3'.
+This requirement is relaxed in "6da03653":http://github.com/rails/rails/commit/6da03653
+
+The new i18n gem can be loaded from vendor/plugins like this:
+
+ def reload_i18n!
+ raise "Move to i18n version 0.2.0 or greater" if Rails.version > "2.3.4"
+
+ $:.grep(/i18n/).each { |path| $:.delete(path) }
+ I18n::Backend.send :remove_const, "Simple"
+ $: << Rails.root.join('vendor', 'plugins', 'i18n', 'lib').to_s
+ end
+
+Then you can `reload_i18n!` inside an i18n initializer.
+
+h2. Tests
+
+You can run tests both with
+
+* `rake test` or just `rake`
+* run any test file directly, e.g. `ruby test/api/simple_test.rb`
+* run all tests with `ruby test/all.rb`
+
+The structure of the test suite is a bit unusual as it uses modules to reuse
+particular tests in different test cases.
+
+The reason for this is that we need to enforce the I18n API across various
+combinations of extensions. E.g. the Simple backend alone needs to support
+the same API as any combination of feature and/or optimization modules included
+to the Simple backend. We test this by reusing the same API defition (implemented
+as test methods) in test cases with different setups.
+
+You can find the test cases that enforce the API in test/api. And you can find
+the API definition test methods in test/api/tests.
+
+All other test cases (e.g. as defined in test/backend, test/core\_ext) etc.
+follow the usual test setup and should be easy to grok.
+
+h2. Authors
+
+* "Sven Fuchs":http://www.artweb-design.de
+* "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
+* "Stephan Soller":http://www.arkanis-development.de
+* "Saimon Moore":http://saimonmoore.net
+* "Matt Aimonetti":http://railsontherun.com
+
+h2. Contributors
+
+http://github.com/svenfuchs/i18n/contributors
+
+h2. License
+
+MIT License. See the included MIT-LICENSE file.
View
24 activesupport/lib/active_support/vendor/i18n-0.4.1/Rakefile
@@ -0,0 +1,24 @@
+require 'rake/testtask'
+require "rake/gempackagetask"
+require "rake/clean"
+
+task :default => [:test]
+
+CLEAN << "pkg" << "doc" << "coverage" << ".yardoc"
+
+Rake::TestTask.new(:test) do |t|
+ t.pattern = "#{File.dirname(__FILE__)}/test/all.rb"
+ t.verbose = true
+end
+Rake::Task['test'].comment = "Run all i18n tests"
+
+Rake::GemPackageTask.new(eval(File.read("i18n.gemspec"))) { |pkg| }
+
+begin
+ require "yard"
+ YARD::Rake::YardocTask.new do |t|
+ t.options = ["--output-dir=doc"]
+ t.options << "--files" << ["CHANGELOG.textile", "contributors.txt", "MIT-LICENSE"].join(",")
+ end
+rescue LoadError
+end
View
148 activesupport/lib/active_support/vendor/i18n-0.4.1/benchmark/example.yml
@@ -0,0 +1,148 @@
+en:
+ first: "First"
+
+ activemodel:
+ errors:
+ messages: :"activerecord.errors.messages"
+
+ activerecord:
+ errors:
+ messages:
+ inclusion: "is not included in the list"
+ exclusion: "is reserved"
+ invalid: "is invalid"
+ confirmation: "doesn't match confirmation"
+ accepted: "must be accepted"
+ empty: "can't be empty"
+ blank: "can't be blank"
+ too_long: "is too long (maximum is %{count} characters)"
+ too_short: "is too short (minimum is %{count} characters)"
+ wrong_length: "is the wrong length (should be %{count} characters)"
+ taken: "has already been taken"
+ not_a_number: "is not a number"
+ greater_than: "must be greater than %{count}"
+ greater_than_or_equal_to: "must be greater than or equal to %{count}"
+ equal_to: "must be equal to %{count}"
+ less_than: "must be less than %{count}"
+ less_than_or_equal_to: "must be less than or equal to %{count}"
+ odd: "must be odd"
+ even: "must be even"
+ record_invalid: "Validation failed: %{errors}"
+
+ models:
+ user:
+ blank: "This is a custom blank message for %{model}: %{attribute}"
+ attributes:
+ login:
+ blank: "This is a custom blank message for User login"
+
+ models:
+ user: "Dude"
+
+ attributes:
+ admins:
+ user:
+ login: "Handle"
+
+ date:
+ formats:
+ # Use the strftime parameters for formats.
+ # When no format has been given, it uses default.
+ # You can provide other formats here if you like!
+ default: "%Y-%m-%d"
+ short: "%b %d"
+ long: "%B %d, %Y"
+
+ day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
+ abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
+
+ # Don't forget the nil at the beginning; there's no such thing as a 0th month
+ month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
+ abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
+ # Used in date_select and datime_select.
+ order: [ :year, :month, :day ]
+
+ time:
+ formats:
+ default: "%a, %d %b %Y %H:%M:%S %z"
+ short: "%d %b %H:%M"
+ long: "%B %d, %Y %H:%M"
+ am: "am"
+ pm: "pm"
+
+ support:
+ array:
+ words_connector: ", "
+ two_words_connector: " and "
+ last_word_connector: ", and "
+
+ activemodel:
+ errors:
+ messages:
+ inclusion: "is not included in the list"
+ exclusion: "is reserved"
+ invalid: "is invalid"
+ confirmation: "doesn't match confirmation"
+ accepted: "must be accepted"
+ empty: "can't be empty"
+ blank: "can't be blank"
+ too_long: "is too long (maximum is %{count} characters)"
+ too_short: "is too short (minimum is %{count} characters)"
+ wrong_length: "is the wrong length (should be %{count} characters)"
+ taken: "has already been taken"
+ not_a_number: "is not a number"
+ greater_than: "must be greater than %{count}"
+ greater_than_or_equal_to: "must be greater than or equal to %{count}"
+ equal_to: "must be equal to %{count}"
+ less_than: "must be less than %{count}"
+ less_than_or_equal_to: "must be less than or equal to %{count}"
+ odd: "must be odd"
+ even: "must be even"
+ record_invalid: "Validation failed: %{errors}"
+
+ models:
+ user:
+ blank: "This is a custom blank message for %{model}: %{attribute}"
+ attributes:
+ login:
+ blank: "This is a custom blank message for User login"
+
+ models:
+ user: "Dude"
+
+ attributes:
+ user:
+ login: "Handle"
+
+ model_data:
+ date:
+ formats:
+ # Use the strftime parameters for formats.
+ # When no format has been given, it uses default.
+ # You can provide other formats here if you like!
+ default: "%Y-%m-%d"
+ short: "%b %d"
+ long: "%B %d, %Y"
+
+ day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
+ abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
+
+ # Don't forget the nil at the beginning; there's no such thing as a 0th month
+ month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
+ abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
+ # Used in date_select and datime_select.
+ order: [ :year, :month, :day ]
+
+ time:
+ formats:
+ default: "%a, %d %b %Y %H:%M:%S %z"
+ short: "%d %b %H:%M"
+ long: "%B %d, %Y %H:%M"
+ am: "am"
+ pm: "pm"
+
+ support:
+ array:
+ words_connector: ", "
+ two_words_connector: " and "
+ last_word_connector: ", and "
View
116 activesupport/lib/active_support/vendor/i18n-0.4.1/benchmark/run.rb
@@ -0,0 +1,116 @@
+#! /usr/bin/ruby
+$:.unshift File.expand_path('../../lib', __FILE__)
+
+require 'i18n'
+require 'benchmark'
+require 'yaml'
+
+DATA_STORES = ARGV.delete("-ds")
+N = (ARGV.shift || 1000).to_i
+YAML_HASH = YAML.load_file(File.expand_path("example.yml", File.dirname(__FILE__)))
+
+module Backends
+ Simple = I18n::Backend::Simple.new
+
+ Interpolation = Class.new(I18n::Backend::Simple) do
+ include I18n::Backend::InterpolationCompiler
+ end.new
+
+ if DATA_STORES
+ require 'rubygems'
+ require File.expand_path('../../test/test_setup_requirements', __FILE__)
+
+ setup_active_record
+ ActiveRecord = I18n::Backend::ActiveRecord.new if defined?(::ActiveRecord)
+
+ setup_rufus_tokyo
+ TokyoCabinet = I18n::Backend::KeyValue.new(Rufus::Tokyo::Cabinet.new("*"), true) if defined?(::Rufus::Tokyo)
+ end
+end
+
+ORDER = %w(Simple Interpolation ActiveRecord TokyoCabinet)
+ORDER.map!(&:to_sym) if RUBY_VERSION > '1.9'
+
+module Benchmark
+ WIDTH = 20
+
+ def self.rt(label = "", n=N, &blk)
+ print label.ljust(WIDTH)
+ time, objects = measure_objects(n, &blk)
+ time = time.respond_to?(:real) ? time.real : time
+ print format("%8.2f ms %8d objects\n", time * 1000, objects)
+ rescue Exception => e
+ print "FAILED: #{e.message}"
+ end
+
+ if ObjectSpace.respond_to?(:allocated_objects)
+ def self.measure_objects(n, &blk)
+ obj = ObjectSpace.allocated_objects
+ t = Benchmark.realtime { n.times(&blk) }
+ [t, ObjectSpace.allocated_objects - obj]
+ end
+ else
+ def self.measure_objects(n, &blk)
+ [Benchmark.measure { n.times(&blk) }, 0]
+ end
+ end
+end
+
+benchmarker = lambda do |backend_name|
+ I18n.backend = Backends.const_get(backend_name)
+ puts "=> #{backend_name}\n\n"
+
+ Benchmark.rt "store", 1 do
+ I18n.backend.store_translations *(YAML_HASH.to_a.first)
+ end
+
+ I18n.backend.translate :en, :first
+
+ Benchmark.rt "available_locales" do
+ I18n.backend.available_locales
+ end
+
+ Benchmark.rt "t (depth=3)" do
+ I18n.backend.translate :en, :"activerecord.models.user"
+ end
+
+ Benchmark.rt "t (depth=5)" do
+ I18n.backend.translate :en, :"activerecord.attributes.admins.user.login"
+ end
+
+ Benchmark.rt "t (depth=7)" do
+ I18n.backend.translate :en, :"activerecord.errors.models.user.attributes.login.blank"
+ end
+
+ Benchmark.rt "t w/ default" do
+ I18n.backend.translate :en, :"activerecord.models.another", :default => "Another"
+ end
+
+ Benchmark.rt "t w/ interpolation" do
+ I18n.backend.translate :en, :"activerecord.errors.models.user.blank", :model => "User", :attribute => "name"
+ end
+
+ Benchmark.rt "t w/ link" do
+ I18n.backend.translate :en, :"activemodel.errors.messages.blank"
+ end
+
+ Benchmark.rt "t subtree" do
+ I18n.backend.translate :en, :"activerecord.errors.messages"
+ end
+
+ puts
+end
+
+# Run!
+puts
+puts "Running benchmarks with N = #{N}\n\n"
+(ORDER & Backends.constants).each(&benchmarker)
+
+Backends.constants.each do |backend_name|
+ backend = Backends.const_get(backend_name)
+ backend.reload!
+ backend.extend I18n::Backend::Memoize
+end
+
+puts "Running memoized benchmarks with N = #{N}\n\n"
+(ORDER & Backends.constants).each(&benchmarker)
View
20 activesupport/lib/active_support/vendor/i18n-0.4.1/i18n.gemspec
@@ -0,0 +1,20 @@
+# encoding: utf-8
+
+$: << File.expand_path('../lib', __FILE__)
+require 'i18n/version'
+
+Gem::Specification.new do |s|
+ s.name = "i18n"
+ s.version = I18n::VERSION
+ s.authors = ["Sven Fuchs", "Joshua Harvey", "Matt Aimonetti", "Stephan Soller", "Saimon Moore"]
+ s.email = "rails-i18n@googlegroups.com"
+ s.homepage = "http://github.com/svenfuchs/i18n"
+ s.summary = "New wave Internationalization support for Ruby"
+ s.description = "New wave Internationalization support for Ruby."
+
+ s.files = `git ls-files {app,lib}`.split("\n") + %w(README.textile MIT-LICENSE CHANGELOG.textile)
+ s.platform = Gem::Platform::RUBY
+ s.require_path = 'lib'
+ s.rubyforge_project = '[none]'
+ s.required_rubygems_version = '>= 1.3.6'
+end
View
1 activesupport/lib/active_support/vendor/i18n-0.4.1/init.rb
@@ -0,0 +1 @@
+require 'i18n'
View
197 .../active_support/vendor/i18n-0.3.7/i18n.rb → ...ive_support/vendor/i18n-0.4.1/lib/i18n.rb 100644 → 100755
@@ -12,94 +12,11 @@
module I18n
autoload :Backend, 'i18n/backend'
- autoload :Helpers, 'i18n/helpers'
+ autoload :Config, 'i18n/config'
+ autoload :Gettext, 'i18n/gettext'
autoload :Locale, 'i18n/locale'
- class Config
- # The only configuration value that is not global and scoped to thread is :locale.
- # It defaults to the default_locale.
- def locale
- @locale ||= default_locale
- end
-
- # Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
- def locale=(locale)
- @locale = locale.to_sym rescue nil
- end
-
- # Returns the current backend. Defaults to +Backend::Simple+.
- def backend
- @@backend ||= Backend::Simple.new
- end
-
- # Sets the current backend. Used to set a custom backend.
- def backend=(backend)
- @@backend = backend
- end
-
- # Returns the current default locale. Defaults to :'en'
- def default_locale
- @@default_locale ||= :en
- end
-
- # Sets the current default locale. Used to set a custom default locale.
- def default_locale=(locale)
- @@default_locale = locale.to_sym rescue nil
- end
-
- # Returns an array of locales for which translations are available.
- # Unless you explicitely set the these through I18n.available_locales=
- # the call will be delegated to the backend and memoized on the I18n module.
- def available_locales
- @@available_locales ||= backend.available_locales
- end
-
- # Sets the available locales.
- def available_locales=(locales)
- @@available_locales = locales
- end
-
- # Returns the current default scope separator. Defaults to '.'
- def default_separator
- @@default_separator ||= '.'
- end
-
- # Sets the current default scope separator.
- def default_separator=(separator)
- @@default_separator = separator
- end
-
- # Return the current exception handler. Defaults to :default_exception_handler.
- def exception_handler
- @@exception_handler ||= :default_exception_handler
- end
-
- # Sets the exception handler.
- def exception_handler=(exception_handler)
- @@exception_handler = exception_handler
- end
-
- # Allow clients to register paths providing translation data sources. The
- # backend defines acceptable sources.
- #
- # E.g. the provided SimpleBackend accepts a list of paths to translation
- # files which are either named *.rb and contain plain Ruby Hashes or are
- # named *.yml and contain YAML data. So for the SimpleBackend clients may
- # register translation files like this:
- # I18n.load_path << 'path/to/locale/en.yml'
- def load_path
- @@load_path ||= []
- end
-
- # Sets the load path instance. Custom implementations are expected to
- # behave like a Ruby Array.
- def load_path=(load_path)
- @@load_path = load_path
- end
- end
-
class << self
-
# Gets I18n configuration object.
def config
Thread.current[:i18n_config] ||= I18n::Config.new
@@ -163,7 +80,7 @@ def reload!
# values passed to #translate as part of the options hash, with the keys matching
# the interpolation variable names.
#
- # <em>E.g.</em>, with a translation <tt>:foo => "foo {{bar}}"</tt> the option
+ # <em>E.g.</em>, with a translation <tt>:foo => "foo %{bar}"</tt> the option
# value for the key +bar+ will be interpolated into the translation:
# I18n.t :foo, :bar => 'baz' # => 'foo baz'
#
@@ -184,7 +101,7 @@ def reload!
#
# The <tt>:count</tt> option can be used both for pluralization and interpolation.
# <em>E.g.</em>, with the translation
- # <tt>:foo => ['{{count}} foo', '{{count}} foos']</tt>, count will
+ # <tt>:foo => ['%{count} foo', '%{count} foos']</tt>, count will
# be interpolated to the pluralized translation:
# I18n.t :foo, :count => 1 # => '1 foo'
#
@@ -218,7 +135,7 @@ def reload!
# called and passed the key and options.
#
# E.g. assuming the key <tt>:salutation</tt> resolves to:
- # lambda { |key, options| options[:gender] == 'm' ? "Mr. {{options[:name]}}" : "Mrs. {{options[:name]}}" }
+ # lambda { |key, options| options[:gender] == 'm' ? "Mr. %{options[:name]}" : "Mrs. %{options[:name]}" }
#
# Then <tt>I18n.t(:salutation, :gender => 'w', :name => 'Smith') will result in "Mrs. Smith".
#
@@ -244,6 +161,69 @@ def translate!(key, options = {})
end
alias :t! :translate!
+ # Transliterates UTF-8 characters to ASCII. By default this method will
+ # transliterate only Latin strings to an ASCII approximation:
+ #
+ # I18n.transliterate("Ærøskøbing")
+ # # => "AEroskobing"
+ #
+ # I18n.transliterate("日本語")
+ # # => "???"
+ #
+ # It's also possible to add support for per-locale transliterations. I18n
+ # expects transliteration rules to be stored at
+ # <tt>i18n.transliterate.rule</tt>.
+ #
+ # Transliteration rules can either be a Hash or a Proc. Procs must accept a
+ # single string argument. Hash rules inherit the default transliteration
+ # rules, while Procs do not.
+ #
+ # *Examples*
+ #
+ # Setting a Hash in <locale>.yml:
+ #
+ # i18n:
+ # transliterate:
+ # rule:
+ # ü: "ue"
+ # ö: "oe"
+ #
+ # Setting a Hash using Ruby:
+ #
+ # store_translations(:de, :i18n => {
+ # :transliterate => {
+ # :rule => {
+ # "ü" => "ue",
+ # "ö" => "oe"
+ # }
+ # }
+ # )
+ #
+ # Setting a Proc:
+ #
+ # translit = lambda {|string| MyTransliterator.transliterate(string) }
+ # store_translations(:xx, :i18n => {:transliterate => {:rule => translit})
+ #
+ # Transliterating strings:
+ #
+ # I18n.locale = :en
+ # I18n.transliterate("Jürgen") # => "Jurgen"
+ # I18n.locale = :de
+ # I18n.transliterate("Jürgen") # => "Juergen"
+ # I18n.transliterate("Jürgen", :locale => :en) # => "Jurgen"
+ # I18n.transliterate("Jürgen", :locale => :de) # => "Juergen"
+ def transliterate(*args)
+ options = args.pop if args.last.is_a?(Hash)
+ key = args.shift
+ locale = options && options.delete(:locale) || config.locale
+ raises = options && options.delete(:raise)
+ replacement = options && options.delete(:replacement)
+ config.backend.transliterate(locale, key, replacement)
+ rescue I18n::ArgumentError => exception
+ raise exception if raises
+ handle_exception(exception, locale, key, options)
+ end
+
# Localizes certain objects, such as dates and numbers to local formatting.
def localize(object, options = {})
locale = options.delete(:locale) || config.locale
@@ -252,14 +232,29 @@ def localize(object, options = {})
end
alias :l :localize
+ # Executes block with given I18n.locale set.
+ def with_locale(tmp_locale = nil)
+ if tmp_locale
+ current_locale = self.locale
+ self.locale = tmp_locale
+ end
+ yield
+ ensure
+ self.locale = current_locale if tmp_locale
+ end
+
+
# Merges the given locale, key and scope into a single array of keys.
# Splits keys that contain dots into multiple keys. Makes sure all
# keys are Symbols.
def normalize_keys(locale, key, scope, separator = nil)
separator ||= I18n.default_separator
- normalize_key(locale, separator) +
- normalize_key(scope, separator) +
- normalize_key(key, separator)
+
+ keys = []
+ keys.concat normalize_key(locale, separator)
+ keys.concat normalize_key(scope, separator)
+ keys.concat normalize_key(key, separator)
+ keys
end
# making these private until Ruby 1.9.2 can send to protected methods again
@@ -308,28 +303,20 @@ def normalize_translation_keys(locale, key, scope, separator = nil)
end
def normalize_key(key, separator)
- normalized_key_cache(separator)[key] ||=
+ normalized_key_cache[separator][key] ||=
case key
when Array
key.map { |k| normalize_key(k, separator) }.flatten
- when nil
- []
else
- key = key.to_s
- if key == ''
- []
- elsif key.include?(separator)
- keys = key.split(separator) - ['']
- keys.map { |k| k.to_sym }
- else
- [key.to_sym]
- end
+ keys = key.to_s.split(separator)
+ keys.delete('')
+ keys.map!{ |k| k.to_sym }
+ keys
end
end
- def normalized_key_cache(separator)
+ def normalized_key_cache
@normalized_key_cache ||= Hash.new { |h,k| h[k] = {} }
- @normalized_key_cache[separator]
end
end
end
View
9 ...support/vendor/i18n-0.3.7/i18n/backend.rb → ...ort/vendor/i18n-0.4.1/lib/i18n/backend.rb
@@ -2,18 +2,19 @@ module I18n
module Backend
autoload :ActiveRecord, 'i18n/backend/active_record'
autoload :Base, 'i18n/backend/base'
+ autoload :InterpolationCompiler, 'i18n/backend/interpolation_compiler'
autoload :Cache, 'i18n/backend/cache'
autoload :Cascade, 'i18n/backend/cascade'
autoload :Chain, 'i18n/backend/chain'
autoload :Cldr, 'i18n/backend/cldr'
autoload :Fallbacks, 'i18n/backend/fallbacks'
- autoload :Fast, 'i18n/backend/fast'
+ autoload :Flatten, 'i18n/backend/flatten'
autoload :Gettext, 'i18n/backend/gettext'
- autoload :Helpers, 'i18n/backend/helpers'
- autoload :Links, 'i18n/backend/links'
- autoload :InterpolationCompiler, 'i18n/backend/interpolation_compiler'
+ autoload :KeyValue, 'i18n/backend/key_value'
+ autoload :Memoize, 'i18n/backend/memoize'
autoload :Metadata, 'i18n/backend/metadata'
autoload :Pluralization, 'i18n/backend/pluralization'
autoload :Simple, 'i18n/backend/simple'
+ autoload :Transliterator, 'i18n/backend/transliterator'
end
end
View
61 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/backend/active_record.rb
@@ -0,0 +1,61 @@
+require 'i18n/backend/base'
+require 'i18n/backend/active_record/translation'
+
+module I18n
+ module Backend
+ class ActiveRecord
+ autoload :Missing, 'i18n/backend/active_record/missing'
+ autoload :StoreProcs, 'i18n/backend/active_record/store_procs'
+ autoload :Translation, 'i18n/backend/active_record/translation'
+
+ module Implementation
+ include Base, Flatten
+
+ def available_locales
+ begin
+ Translation.available_locales
+ rescue ::ActiveRecord::StatementInvalid
+ []
+ end
+ end
+
+ def store_translations(locale, data, options = {})
+ escape = options.fetch(:escape, true)
+ flatten_translations(locale, data, escape, false).each do |key, value|
+ Translation.locale(locale).lookup(expand_keys(key)).delete_all
+ Translation.create(:locale => locale.to_s, :key => key.to_s, :value => value)
+ end
+ end
+
+ protected
+
+ def lookup(locale, key, scope = [], options = {})
+ key = normalize_flat_keys(locale, key, scope, options[:separator])
+ result = Translation.locale(locale).lookup(key).all
+
+ if result.empty?
+ nil
+ elsif result.first.key == key
+ result.first.value
+ else
+ chop_range = (key.size + FLATTEN_SEPARATOR.size)..-1
+ result = result.inject({}) do |hash, r|
+ hash[r.key.slice(chop_range)] = r.value
+ hash
+ end
+ result.deep_symbolize_keys
+ end
+ end
+
+ # For a key :'foo.bar.baz' return ['foo', 'foo.bar', 'foo.bar.baz']
+ def expand_keys(key)
+ key.to_s.split(FLATTEN_SEPARATOR).inject([]) do |keys, key|
+ keys << [keys.last, key].compact.join(FLATTEN_SEPARATOR)
+ end
+ end
+ end
+
+ include Implementation
+ end
+ end
+end
View
10 ...3.7/i18n/backend/active_record/missing.rb → ...lib/i18n/backend/active_record/missing.rb
@@ -40,7 +40,7 @@ def store_default_translations(locale, key, options = {})
keys = I18n.normalize_keys(locale, key, scope, separator)[1..-1]
key = keys.join(separator || I18n.default_separator)
- unless ActiveRecord::Translation.locale(locale).lookup(key, separator).exists?
+ unless ActiveRecord::Translation.locale(locale).lookup(key).exists?
interpolations = options.reject { |name, value| Base::RESERVED_KEYS.include?(name) }.keys
keys = count ? I18n.t('i18n.plural.keys', :locale => locale).map { |k| [key, k].join(separator) } : [key]
keys.each { |key| store_default_translation(locale, key, interpolations) }
@@ -55,11 +55,9 @@ def store_default_translation(locale, key, interpolations)
def translate(locale, key, options = {})
super
-
- rescue I18n::MissingTranslationData => e
- self.store_default_translations(locale, key, options)
-
- raise e
+ rescue I18n::MissingTranslationData => e
+ self.store_default_translations(locale, key, options)
+ raise e
end
end
end
View
0 ...i18n/backend/active_record/store_procs.rb → ...i18n/backend/active_record/store_procs.rb
File renamed without changes.
View
11 ...i18n/backend/active_record/translation.rb → ...i18n/backend/active_record/translation.rb
@@ -60,9 +60,14 @@ class Translation < ::ActiveRecord::Base
send scope_method, :lookup, lambda { |keys, *separator|
column_name = connection.quote_column_name('key')
- keys = Array(keys).map! { |key| key.to_s }
- separator = separator.first || I18n.default_separator
- namespace = "#{keys.last}#{separator}%"
+ keys = Array(keys).map! { |key| key.to_s }
+
+ unless separator.empty?
+ warn "[DEPRECATION] Giving a separator to Translation.lookup is deprecated. " <<
+ "You can change the internal separator by overwriting FLATTEN_SEPARATOR."
+ end
+
+ namespace = "#{keys.last}#{I18n::Backend::Flatten::FLATTEN_SEPARATOR}%"
{ :conditions => ["#{column_name} IN (?) OR #{column_name} LIKE ?", keys, namespace] }
}
View
139 ...rt/vendor/i18n-0.3.7/i18n/backend/base.rb → ...endor/i18n-0.4.1/lib/i18n/backend/base.rb
@@ -1,50 +1,52 @@
# encoding: utf-8
require 'yaml'
-require 'i18n/core_ext/hash/except'
+require 'i18n/core_ext/hash'
module I18n
module Backend
module Base
- include I18n::Backend::Helpers
+ include I18n::Backend::Transliterator
RESERVED_KEYS = [:scope, :default, :separator, :resolve]
- INTERPOLATION_SYNTAX_PATTERN = /(\\)?\{\{([^\}]+)\}\}/
+ RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
+ DEPRECATED_INTERPOLATION_SYNTAX_PATTERN = /(\\)?\{\{([^\}]+)\}\}/
+ INTERPOLATION_SYNTAX_PATTERN = /%\{([^\}]+)\}/
# Accepts a list of paths to translation files. Loads translations from
# plain Ruby (*.rb) or YAML files (*.yml). See #load_rb and #load_yml
# for details.
def load_translations(*filenames)
+ filenames = I18n.load_path.flatten if filenames.empty?
filenames.each { |filename| load_file(filename) }
end
- # Stores translations for the given locale in memory.
- # This uses a deep merge for the translations hash, so existing
- # translations will be overwritten by new ones only at the deepest
- # level of the hash.
+ # This method receives a locale, a data hash and options for storing translations.
+ # Should be implemented
def store_translations(locale, data, options = {})
- merge_translations(locale, data, options)
+ raise NotImplementedError
end
def translate(locale, key, options = {})
raise InvalidLocale.new(locale) unless locale
return key.map { |k| translate(locale, k, options) } if key.is_a?(Array)
+ entry = key && lookup(locale, key, options[:scope], options)
+
if options.empty?
- entry = resolve(locale, key, lookup(locale, key), options)
- raise(I18n::MissingTranslationData.new(locale, key, options)) if entry.nil?
+ entry = resolve(locale, key, entry, options)
else
- count, scope, default = options.values_at(:count, :scope, :default)
- values = options.reject { |name, value| RESERVED_KEYS.include?(name) }
-
- entry = lookup(locale, key, scope, options)
- entry = entry.nil? && default ? default(locale, key, default, options) : resolve(locale, key, entry, options)
- raise(I18n::MissingTranslationData.new(locale, key, options)) if entry.nil?
-
- entry = pluralize(locale, entry, count) if count
- entry = interpolate(locale, entry, values) if values
+ count, default = options.values_at(:count, :default)
+ values = options.except(*RESERVED_KEYS)
+ entry = entry.nil? && default ?
+ default(locale, key, default, options) : resolve(locale, key, entry, options)
end
+ raise(I18n::MissingTranslationData.new(locale, key, options)) if entry.nil?
+ entry = entry.dup if entry.is_a?(String)
+
+ entry = pluralize(locale, entry, count) if count
+ entry = interpolate(locale, entry, values) if values
entry
end
@@ -57,7 +59,7 @@ def localize(locale, object, format = :default, options = {})
if Symbol === format
key = format
type = object.respond_to?(:sec) ? 'time' : 'date'
- format = I18n.t(:"#{type}.formats.#{key}", :locale => locale, :raise => true)
+ format = I18n.t(:"#{type}.formats.#{key}", options.merge(:raise => true, :object => object, :locale => locale))
end
# format = resolve(locale, object, format, options)
@@ -74,51 +76,21 @@ def localize(locale, object, format = :default, options = {})
object.strftime(format)
end
- def initialized?
- @initialized ||= false
- end
-
# Returns an array of locales for which translations are available
# ignoring the reserved translation meta data key :i18n.
def available_locales
- init_translations unless initialized?
- translations.inject([]) do |locales, (locale, data)|
- locales << locale unless (data.keys - [:i18n]).empty?
- locales
- end
+ raise NotImplementedError
end
def reload!
- @initialized = false
- @translations = nil
+ @skip_syntax_deprecation = false
end
protected
- def init_translations
- load_translations(*I18n.load_path.flatten)
- @initialized = true
- end
-
- def translations
- @translations ||= {}
- end
- # Looks up a translation from the translations hash. Returns nil if
- # eiher key is nil, or locale, scope or key do not exist as a key in the
- # nested translations hash. Splits keys or scopes containing dots
- # into multiple keys, i.e. <tt>currency.format</tt> is regarded the same as
- # <tt>%w(currency format)</tt>.
+ # The method which actually looks up for the translation in the store.
def lookup(locale, key, scope = [], options = {})
- return unless key
- init_translations unless initialized?
- keys = I18n.normalize_keys(locale, key, scope, options[:separator])
- keys.inject(translations) do |result, key|
- key = key.to_sym
- return nil unless result.is_a?(Hash) && result.has_key?(key)
- result = result[key]
- result = resolve(locale, key, result, options) if result.is_a?(Symbol)
- String === result ? result.dup : result
- end
+ raise NotImplementedError
end
# Evaluates defaults.
@@ -147,7 +119,8 @@ def resolve(locale, object, subject, options = nil)
when Symbol
I18n.translate(subject, (options || {}).merge(:locale => locale, :raise => true))
when Proc
- resolve(locale, object, subject.call(object, options), options = {})
+ date_or_time = options.delete(:object) || object
+ resolve(locale, object, subject.call(date_or_time, options), options = {})
else
subject
end
@@ -160,7 +133,7 @@ def resolve(locale, object, subject, options = nil)
# and the second translation if it is equal to 1. Other backends can
# implement more flexible or complex pluralization rules.
def pluralize(locale, entry, count)
- return entry unless entry.is_a?(Hash) and count
+ return entry unless entry.is_a?(Hash) && count
key = :zero if count == 0 && entry.has_key?(:zero)
key ||= count == 1 ? :one : :other
@@ -170,38 +143,48 @@ def pluralize(locale, entry, count)
# Interpolates values into a given string.
#
- # interpolate "file {{file}} opened by \\{{user}}", :file => 'test.txt', :user => 'Mr. X'
- # # => "file test.txt opened by {{user}}"
+ # interpolate "file %{file} opened by %%{user}", :file => 'test.txt', :user => 'Mr. X'
+ # # => "file test.txt opened by %{user}"
#
# Note that you have to double escape the <tt>\\</tt> when you want to escape
# the <tt>{{...}}</tt> key in a string (once for the string and once for the
# interpolation).
def interpolate(locale, string, values = {})
return string unless string.is_a?(::String) && !values.empty?
+ original_values = values.dup
preserve_encoding(string) do
- s = string.gsub(INTERPOLATION_SYNTAX_PATTERN) do
+ string = string.gsub(DEPRECATED_INTERPOLATION_SYNTAX_PATTERN) do
escaped, key = $1, $2.to_sym
if escaped
"{{#{key}}}"
- elsif RESERVED_KEYS.include?(key)
- raise ReservedInterpolationKey.new(key, string)
else
+ warn_syntax_deprecation!
"%{#{key}}"
end
end
+ keys = string.scan(INTERPOLATION_SYNTAX_PATTERN).flatten
+ return string if keys.empty?
+
values.each do |key, value|
- value = value.call(values) if interpolate_lambda?(value, s, key)
- value = value.to_s unless value.is_a?(::String)
- values[key] = value
+ if keys.include?(key.to_s)
+ value = value.call(values) if interpolate_lambda?(value, string, key)
+ value = value.to_s unless value.is_a?(::String)
+ values[key] = value
+ else
+ values.delete(key)
+ end
end
- s % values
+ string % values
end
-
rescue KeyError => e
- raise MissingInterpolationArgument.new(values, string)
+ if string =~ RESERVED_KEYS_PATTERN
+ raise ReservedInterpolationKey.new($1.to_sym, string)
+ else
+ raise MissingInterpolationArgument.new(original_values, string)
+ end
end
def preserve_encoding(string)
@@ -229,7 +212,7 @@ def load_file(filename)
type = File.extname(filename).tr('.', '').downcase
raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}")
data = send(:"load_#{type}", filename) # TODO raise a meaningful exception if this does not yield a Hash
- data.each { |locale, d| merge_translations(locale, d) }
+ data.each { |locale, d| store_translations(locale, d) }
end
# Loads a plain Ruby translations file. eval'ing the file must yield
@@ -244,22 +227,10 @@ def load_yml(filename)
YAML::load(IO.read(filename))
end
- # Deep merges the given translations hash with the existing translations
- # for the given locale
- def merge_translations(locale, data, options = {})
- locale = locale.to_sym
- translations[locale] ||= {}
- separator = options[:separator] || I18n.default_separator
- data = unwind_keys(data, separator)
- data = deep_symbolize_keys(data)
-
- # deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
- merger = proc do |key, v1, v2|
- # TODO should probably be:
- # raise TypeError.new("can't merge #{v1.inspect} and #{v2.inspect}") unless Hash === v1 && Hash === v2
- Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : (v2 || v1)
- end
- translations[locale].merge!(data, &merger)
+ def warn_syntax_deprecation! #:nodoc:
+ return if @skip_syntax_deprecation
+ warn "The {{key}} interpolation syntax in I18n messages is deprecated. Please use %{key} instead.\n#{caller.join("\n")}"
+ @skip_syntax_deprecation = true
end
end
end
View
1 ...t/vendor/i18n-0.3.7/i18n/backend/cache.rb → ...ndor/i18n-0.4.1/lib/i18n/backend/cache.rb
@@ -45,6 +45,7 @@ def perform_caching?
end
module Backend
+ # TODO Should the cache be cleared if new translations are stored?
module Cache
def translate(*args)
I18n.perform_caching? ? fetch(*args) { super } : super
View
1 ...vendor/i18n-0.3.7/i18n/backend/cascade.rb → ...or/i18n-0.4.1/lib/i18n/backend/cascade.rb
@@ -36,7 +36,6 @@ module I18n
module Backend
module Cascade
def lookup(locale, key, scope = [], options = {})
- return unless key
return super unless cascade = options[:cascade]
separator = options[:separator] || I18n.default_separator
View
4 ...t/vendor/i18n-0.3.7/i18n/backend/chain.rb → ...ndor/i18n-0.4.1/lib/i18n/backend/chain.rb
@@ -16,7 +16,9 @@ module Backend
#
# The implementation assumes that all backends added to the Chain implement
# a lookup method with the same API as Simple backend does.
- class Chain < Simple
+ class Chain
+ include Base
+
attr_accessor :backends
def initialize(*backends)
View
0 ...rt/vendor/i18n-0.3.7/i18n/backend/cldr.rb → ...endor/i18n-0.4.1/lib/i18n/backend/cldr.rb
File renamed without changes.
View
0 ...ndor/i18n-0.3.7/i18n/backend/fallbacks.rb → .../i18n-0.4.1/lib/i18n/backend/fallbacks.rb
File renamed without changes.
View
113 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/backend/flatten.rb
@@ -0,0 +1,113 @@
+module I18n
+ module Backend
+ # This module contains several helpers to assist flattening translations.
+ # You may want to flatten translations for:
+ #
+ # 1) speed up lookups, as in the Memoize backend;
+ # 2) In case you want to store translations in a data store, as in ActiveRecord backend;
+ #
+ # You can check both backends above for some examples.
+ # This module also keeps all links in a hash so they can be properly resolved when flattened.
+ module Flatten
+ SEPARATOR_ESCAPE_CHAR = "\001"
+ FLATTEN_SEPARATOR = "."
+
+ # normalize_keys the flatten way. This method is significantly faster
+ # and creates way less objects than the one at I18n.normalize_keys.
+ # It also handles escaping the translation keys.
+ def self.normalize_flat_keys(locale, key, scope, separator)
+ keys = [scope, key].flatten.compact
+ separator ||= I18n.default_separator
+
+ if separator != FLATTEN_SEPARATOR
+ keys.map! do |k|
+ k.to_s.tr("#{FLATTEN_SEPARATOR}#{separator}",
+ "#{SEPARATOR_ESCAPE_CHAR}#{FLATTEN_SEPARATOR}")
+ end
+ end
+
+ keys.join(".")
+ end
+
+ # Receives a string and escape the default separator.
+ def self.escape_default_separator(key) #:nodoc:
+ key.to_s.tr(FLATTEN_SEPARATOR, SEPARATOR_ESCAPE_CHAR)
+ end
+
+ # Shortcut to I18n::Backend::Flatten.normalize_flat_keys
+ # and then resolve_links.
+ def normalize_flat_keys(locale, key, scope, separator)
+ key = I18n::Backend::Flatten.normalize_flat_keys(locale, key, scope, separator)
+ resolve_link(locale, key)
+ end
+
+ # Store flattened links.
+ def links
+ @links ||= Hash.new { |h,k| h[k] = {} }
+ end
+
+ # Flatten keys for nested Hashes by chaining up keys:
+ #
+ # >> { "a" => { "b" => { "c" => "d", "e" => "f" }, "g" => "h" }, "i" => "j"}.wind
+ # => { "a.b.c" => "d", "a.b.e" => "f", "a.g" => "h", "i" => "j" }
+ #
+ def flatten_keys(hash, escape, prev_key=nil, &block)
+ hash.each_pair do |key, value|
+ key = escape_default_separator(key) if escape
+ curr_key = [prev_key, key].compact.join(FLATTEN_SEPARATOR).to_sym
+ yield curr_key, value
+ flatten_keys(value, escape, curr_key, &block) if value.is_a?(Hash)
+ end
+ end
+
+ # Receives a hash of translations (where the key is a locale and
+ # the value is another hash) and return a hash with all
+ # translations flattened.
+ #
+ # Nested hashes are included in the flattened hash just if subtree
+ # is true and Symbols are automatically stored as links.
+ def flatten_translations(locale, data, escape, subtree)
+ hash = {}
+ flatten_keys(data, escape) do |key, value|
+ if value.is_a?(Hash)
+ hash[key] = value if subtree
+ else
+ store_link(locale, key, value) if value.is_a?(Symbol)
+ hash[key] = value
+ end
+ end
+ hash
+ end
+
+ protected
+
+ def store_link(locale, key, link)
+ links[locale.to_sym][key.to_s] = link.to_s
+ end
+
+ def resolve_link(locale, key)
+ key, locale = key.to_s, locale.to_sym
+ links = self.links[locale]
+
+ if links.key?(key)
+ links[key]
+ elsif link = find_link(locale, key)
+ store_link(locale, key, key.gsub(*link))
+ else
+ key
+ end
+ end
+
+ def find_link(locale, key) #:nodoc:
+ links[locale].each do |from, to|
+ return [from, to] if key[0, from.length] == from
+ end && nil
+ end
+
+ def escape_default_separator(key) #:nodoc:
+ I18n::Backend::Flatten.escape_default_separator(key)
+ end
+
+ end
+ end
+end
View
0 ...vendor/i18n-0.3.7/i18n/backend/gettext.rb → ...or/i18n-0.4.1/lib/i18n/backend/gettext.rb
File renamed without changes.
View
12 ....7/i18n/backend/interpolation_compiler.rb → ...ib/i18n/backend/interpolation_compiler.rb
@@ -11,14 +11,18 @@
# InterpolationCompiler module to the Simple backend:
#
# I18n::Backend::Simple.send(:include, I18n::Backend::InterpolationCompiler)
+#
+# Note that InterpolationCompiler does not yield meaningful results and consequently
+# should not be used with Ruby 1.9 (YARV) but improves performance everywhere else
+# (jRuby, Rubinius and 1.8.7).
module I18n
module Backend
module InterpolationCompiler
module Compiler
extend self
- TOKENIZER = /(\\\{\{[^\}]+\}\}|\{\{[^\}]+\}\})/
- INTERPOLATION_SYNTAX_PATTERN = /(\\)?(\{\{([^\}]+)\}\})/
+ TOKENIZER = /(%%\{[^\}]+\}|%\{[^\}]+\})/
+ INTERPOLATION_SYNTAX_PATTERN = /(%)?(%\{([^\}]+)\})/
def compile_if_an_interpolation(string)
if interpolated_str?(string)
@@ -37,7 +41,7 @@ def interpolated_str?(str)
end
protected
- # tokenize("foo {{bar}} baz \\{{buz}}") # => ["foo ", "{{bar}}", " baz ", "\\{{buz}}"]
+ # tokenize("foo %{bar} baz %%{buz}") # => ["foo ", "%{bar}", " baz ", "%%{buz}"]
def tokenize(str)
str.split(TOKENIZER)
end
@@ -102,7 +106,7 @@ def interpolate(locale, string, values)
end
end
- def merge_translations(locale, data, options = {})
+ def store_translations(locale, data, options = {})
compile_all_strings_in(data)
super
end
View
102 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/backend/key_value.rb
@@ -0,0 +1,102 @@
+# encoding: utf-8
+
+require 'i18n/backend/base'
+require 'active_support/json'
+
+module I18n
+ module Backend
+ # This is a basic backend for key value stores. It receives on
+ # initialization the store, which should respond to three methods:
+ #
+ # * store#[](key) - Used to get a value
+ # * store#[]=(key, value) - Used to set a value
+ # * store#keys - Used to get all keys
+ #
+ # Since these stores only supports string, all values are converted
+ # to JSON before being stored, allowing it to also store booleans,
+ # hashes and arrays. However, this store does not support Procs.
+ #
+ # As the ActiveRecord backend, Symbols are just supported when loading
+ # translations from the filesystem or through explicit store translations.
+ #
+ # Also, avoid calling I18n.available_locales since it's a somehow
+ # expensive operation in most stores.
+ #
+ # == Example
+ #
+ # To setup I18n to use TokyoCabinet in memory is quite straightforward:
+ #
+ # require 'rufus/tokyo/cabinet' # gem install rufus-tokyo
+ # I18n.backend = I18n::Backend::KeyValue.new(Rufus::Tokyo::Cabinet.new('*'))
+ #
+ # == Performance
+ #
+ # You may make this backend even faster by including the Memoize module.
+ # However, notice that you should properly clear the cache if you change
+ # values directly in the key-store.
+ #
+ # == Subtrees
+ #
+ # In most backends, you are allowed to retrieve part of a translation tree:
+ #
+ # I18n.backend.store_translations :en, :foo => { :bar => :baz }
+ # I18n.t "foo" #=> { :bar => :baz }
+ #
+ # This backend supports this feature by default, but it slows down the storage
+ # of new data considerably and makes hard to delete entries. That said, you are
+ # allowed to disable the storage of subtrees on initialization:
+ #
+ # I18n::Backend::KeyValue.new(@store, false)
+ #
+ # This is useful if you are using a KeyValue backend chained to a Simple backend.
+ class KeyValue
+ module Implementation
+ attr_accessor :store
+
+ include Base, Flatten
+
+ def initialize(store, subtrees=true)
+ @store, @subtrees = store, subtrees
+ end
+
+ def store_translations(locale, data, options = {})
+ escape = options.fetch(:escape, true)
+ flatten_translations(locale, data, escape, @subtrees).each do |key, value|
+ key = "#{locale}.#{key}"
+
+ case value
+ when Hash
+ if @subtrees && (old_value = @store[key])
+ old_value = ActiveSupport::JSON.decode(old_value)
+ value = old_value.deep_symbolize_keys.deep_merge!(value) if old_value.is_a?(Hash)
+ end
+ when Proc
+ raise "Key-value stores cannot handle procs"
+ end
+
+ @store[key] = ActiveSupport::JSON.encode(value) unless value.is_a?(Symbol)
+ end
+ end
+
+ def available_locales
+ locales = @store.keys.map { |k| k =~ /\./; $` }
+ locales.uniq!
+ locales.compact!
+ locales.map! { |k| k.to_sym }
+ locales
+ end
+
+ protected
+
+ def lookup(locale, key, scope = [], options = {})
+ key = normalize_flat_keys(locale, key, scope, options[:separator])
+ value = @store["#{locale}.#{key}"]
+ value = ActiveSupport::JSON.decode(value) if value
+ value.is_a?(Hash) ? value.deep_symbolize_keys : value
+ end
+ end
+
+ include Implementation
+ end
+ end
+end
View
48 activesupport/lib/active_support/vendor/i18n-0.4.1/lib/i18n/backend/memoize.rb
@@ -0,0 +1,48 @@
+# encoding: utf-8
+#
+# Memoize module simply memoizes the values returned by lookup using
+# a flat hash and can tremendously speed up the lookup process in a backend.
+#
+# To enable it you can simply include the Memoize module to your backend:
+#
+# I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
+#
+# Notice that it's the responsibility of the backend to define whenever the
+# cache should be cleaned.
+module I18n
+ module Backend
+ module Memoize
+ def available_locales
+ @memoized_locales ||= super
+ end
+
+ def store_translations(locale, data, options = {})
+ reset_memoizations!(locale)
+ super
+ end
+
+ def reload!
+ reset_memoizations!
+ super
+ end
+
+ protected
+
+ def lookup(locale, key, scope = nil, options = {})
+ flat_key = I18n::Backend::Flatten.normalize_flat_keys(locale,
+ key, scope, options[:separator]).to_sym
+ flat_hash = memoized_lookup[locale.to_sym]
+ flat_hash.key?(flat_key) ? flat_hash[flat_key] : (flat_hash[flat_key] = super)
+ end
+
+ def memoized_lookup
+ @memoized_lookup ||= Hash.new { |h, k| h[k] = {} }
+ end
+
+ def reset_memoizations!(locale=nil)
+ @memoized_locales = nil
+ (locale ? memoized_lookup[locale.to_sym] : memoized_lookup).clear
+ end
+ end
+ end
+end
View
18 ...endor/i18n-0.3.7/i18n/backend/metadata.rb → ...r/i18n-0.4.1/lib/i18n/backend/metadata.rb
@@ -13,9 +13,7 @@
# into the Simple backend class - or whatever other backend you are using:
#
# I18n::Backend::Simple.send(:include, I18n::Backend::Metadata)
-
-require 'i18n/core_ext/object/meta_class'
-
+#
module I18n
module Backend
module Metadata
@@ -29,7 +27,7 @@ def translation_metadata
def translation_metadata=(translation_metadata)
@translation_metadata = translation_metadata
end
- end
+ end unless Object.method_defined?(:translation_metadata)
end
end
@@ -45,10 +43,9 @@ def translate(locale, key, options = {})
with_metadata(metadata) { super }
end
- def interpolate(locale, string, values = {})
- with_metadata(:original => string) do
- preserve_translation_metadata(string) { super }
- end if string
+ def interpolate(locale, entry, values = {})
+ metadata = entry.translation_metadata.merge(:original => entry)
+ with_metadata(metadata) { super }
end
def pluralize(locale, entry, count)
@@ -63,11 +60,6 @@ def with_metadata(metadata, &block)
result
end
- def preserve_translation_metadata(object, &block)
- result = yield
- result.translation_metadata = object.translation_metadata if result
- result
- end
end
end
end
View
0