Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update vendored i18n gem to 0.3.3 [#3492 status:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 652bdeb3c3ef3692108cb3364f92df672f1dc1a7 1 parent ef10988
@sikachu sikachu authored josevalim committed
Showing with 5,585 additions and 1,005 deletions.
  1. +2 −2 activesupport/lib/active_support/vendor.rb
  2. +0 −20 activesupport/lib/active_support/vendor/i18n-0.1.3/README.textile
  3. +0 −5 activesupport/lib/active_support/vendor/i18n-0.1.3/Rakefile
  4. +0 −27 activesupport/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec
  5. +0 −214 activesupport/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb
  6. +0 −5 activesupport/lib/active_support/vendor/i18n-0.1.3/test/all.rb
  7. +0 −124 activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb
  8. +0 −1  activesupport/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb
  9. +0 −3  activesupport/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml
  10. +0 −567 activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb
  11. +3 −0  activesupport/lib/active_support/vendor/i18n-0.3.3/.gitignore
  12. +76 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile
  13. 0  activesupport/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/MIT-LICENSE
  14. +81 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/README.textile
  15. +24 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/Rakefile
  16. +144 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml
  17. +71 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb
  18. +17 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/contributors.txt
  19. +165 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/i18n.gemspec
  20. +1 −0  activesupport/lib/active_support/vendor/i18n-0.3.3/init.rb
  21. +99 −21 activesupport/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/lib/i18n.rb
  22. +17 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend.rb
  23. +70 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record.rb
  24. +67 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/missing.rb
  25. +38 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/store_procs.rb
  26. +83 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/translation.rb
  27. +259 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/base.rb
  28. +75 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cache.rb
  29. +44 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cascade.rb
  30. +74 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/chain.rb
  31. +52 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fallbacks.rb
  32. +68 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fast.rb
  33. +75 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/gettext.rb
  34. +80 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/helpers.rb
  35. +119 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/interpolation_compiler.rb
  36. +73 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/metadata.rb
  37. +57 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/pluralization.rb
  38. +22 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/simple.rb
  39. +5 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/object/meta_class.rb
  40. +95 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/string/interpolate.rb
  41. +14 −6 activesupport/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/lib/i18n/exceptions.rb
  42. +25 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/gettext.rb
  43. +5 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers.rb
  44. +64 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers/gettext.rb
  45. +6 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale.rb
  46. +98 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/fallbacks.rb
  47. +28 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag.rb
  48. +24 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/parents.rb
  49. +76 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/rfc4646.rb
  50. +41 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/simple.rb
  51. +3 −0  activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/version.rb
  52. +8 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/all.rb
  53. +15 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/basics.rb
  54. +40 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/defaults.rb
  55. +92 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/interpolation.rb
  56. +55 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/link.rb
  57. +91 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date.rb
  58. +90 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date_time.rb
  59. +54 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/localization/procs.rb
  60. +84 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/localization/time.rb
  61. +45 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/lookup.rb
  62. +35 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/pluralization.rb
  63. +40 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/api/procs.rb
  64. +29 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/api/active_record_test.rb
  65. +40 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/api/all_features_test.rb
  66. +31 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/api/cascade_test.rb
  67. +26 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/api/chain_test.rb
  68. +33 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fallbacks_test.rb
  69. +31 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fast_test.rb
  70. +33 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/api/pluralization_test.rb
  71. +21 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/api/simple_test.rb
  72. +60 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record/missing_test.rb
  73. +52 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record_test.rb
  74. +72 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cache_test.rb
  75. +66 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cascade_test.rb
  76. +64 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/chain_test.rb
  77. +57 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fallbacks_test.rb
  78. +50 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fast_test.rb
  79. +26 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/helpers_test.rb
  80. +107 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/interpolation_compiler_test.rb
  81. +67 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/metadata_test.rb
  82. +43 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/pluralization_test.rb
  83. +77 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/simple_test.rb
  84. +94 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/core_ext/string/interpolate_test.rb
  85. +201 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/api_test.rb
  86. +91 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/backend_test.rb
  87. +8 −10 activesupport/lib/active_support/vendor/{i18n-0.1.3/test → i18n-0.3.3/test/cases}/i18n_exceptions_test.rb
  88. +23 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_load_path_test.rb
  89. +172 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_test.rb
  90. +126 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/fallbacks_test.rb
  91. +143 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/rfc4646_test.rb
  92. +33 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/simple_test.rb
  93. +72 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/de.po
  94. +3 −0  activesupport/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.rb
  95. +3 −0  activesupport/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.yml
  96. +113 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/plurals.rb
  97. +100 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/test/test_helper.rb
  98. +329 −0 activesupport/lib/active_support/vendor/i18n-0.3.3/vendor/po_parser.rb
View
4 activesupport/lib/active_support/vendor.rb
@@ -21,8 +21,8 @@
end
begin
- gem 'i18n', '>= 0.1.3'
+ gem 'i18n', '>= 0.3.3'
rescue Gem::LoadError
- $:.unshift "#{File.dirname(__FILE__)}/vendor/i18n-0.1.3/lib"
+ $:.unshift "#{File.dirname(__FILE__)}/vendor/i18n-0.3.3/lib"
end
require 'i18n'
View
20 activesupport/lib/active_support/vendor/i18n-0.1.3/README.textile
@@ -1,20 +0,0 @@
-h1. Ruby I18n gem
-
-I18n and localization solution for Ruby.
-
-For information please refer to http://rails-i18n.org
-
-h2. Authors
-
-* "Matt Aimonetti":http://railsontherun.com
-* "Sven Fuchs":http://www.artweb-design.de
-* "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
-* "Saimon Moore":http://saimonmoore.net
-* "Stephan Soller":http://www.arkanis-development.de
-
-h2. License
-
-MIT License. See the included MIT-LICENCE file.
-
-
-
View
5 activesupport/lib/active_support/vendor/i18n-0.1.3/Rakefile
@@ -1,5 +0,0 @@
-task :default => [:test]
-
-task :test do
- ruby "test/all.rb"
-end
View
27 activesupport/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec
@@ -1,27 +0,0 @@
-Gem::Specification.new do |s|
- s.name = "i18n"
- s.version = "0.1.3"
- s.date = "2009-01-09"
- s.summary = "Internationalization support for Ruby"
- s.email = "rails-i18n@googlegroups.com"
- s.homepage = "http://rails-i18n.org"
- s.description = "Add Internationalization support to your Ruby application."
- s.has_rdoc = false
- s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Matt Aimonetti', 'Stephan Soller', 'Saimon Moore']
- s.files = [
- 'i18n.gemspec',
- 'lib/i18n/backend/simple.rb',
- 'lib/i18n/exceptions.rb',
- 'lib/i18n.rb',
- 'MIT-LICENSE',
- 'README.textile'
- ]
- s.test_files = [
- 'test/all.rb',
- 'test/i18n_exceptions_test.rb',
- 'test/i18n_test.rb',
- 'test/locale/en.rb',
- 'test/locale/en.yml',
- 'test/simple_backend_test.rb'
- ]
-end
View
214 activesupport/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb
@@ -1,214 +0,0 @@
-require 'yaml'
-
-module I18n
- module Backend
- class Simple
- INTERPOLATION_RESERVED_KEYS = %w(scope default)
- MATCH = /(\\\\)?\{\{([^\}]+)\}\}/
-
- # 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.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.
- def store_translations(locale, data)
- merge_translations(locale, data)
- end
-
- def translate(locale, key, options = {})
- raise InvalidLocale.new(locale) if locale.nil?
- return key.map { |k| translate(locale, k, options) } if key.is_a? Array
-
- reserved = :scope, :default
- count, scope, default = options.values_at(:count, *reserved)
- options.delete(:default)
- values = options.reject { |name, value| reserved.include?(name) }
-
- entry = lookup(locale, key, scope)
- if entry.nil?
- entry = default(locale, default, options)
- if entry.nil?
- raise(I18n::MissingTranslationData.new(locale, key, options))
- end
- end
- entry = pluralize(locale, entry, count)
- entry = interpolate(locale, entry, values)
- entry
- end
-
- # Acts the same as +strftime+, but returns a localized version of the
- # formatted date string. Takes a key from the date/time formats
- # translations as a format argument (<em>e.g.</em>, <tt>:short</tt> in <tt>:'date.formats'</tt>).
- def localize(locale, object, format = :default)
- raise ArgumentError, "Object must be a Date, DateTime or Time object. #{object.inspect} given." unless object.respond_to?(:strftime)
-
- type = object.respond_to?(:sec) ? 'time' : 'date'
- # TODO only translate these if format is a String?
- formats = translate(locale, :"#{type}.formats")
- format = formats[format.to_sym] if formats && formats[format.to_sym]
- # TODO raise exception unless format found?
- format = format.to_s.dup
-
- # TODO only translate these if the format string is actually present
- # TODO check which format strings are present, then bulk translate then, then replace them
- format.gsub!(/%a/, translate(locale, :"date.abbr_day_names")[object.wday])
- format.gsub!(/%A/, translate(locale, :"date.day_names")[object.wday])
- format.gsub!(/%b/, translate(locale, :"date.abbr_month_names")[object.mon])
- format.gsub!(/%B/, translate(locale, :"date.month_names")[object.mon])
- format.gsub!(/%p/, translate(locale, :"time.#{object.hour < 12 ? :am : :pm}")) if object.respond_to? :hour
- object.strftime(format)
- end
-
- def initialized?
- @initialized ||= false
- end
-
- # Returns an array of locales for which translations are available
- def available_locales
- init_translations unless initialized?
- translations.keys
- end
-
- def reload!
- @initialized = false
- @translations = nil
- 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>.
- def lookup(locale, key, scope = [])
- return unless key
- init_translations unless initialized?
- keys = I18n.send(:normalize_translation_keys, locale, key, scope)
- keys.inject(translations) do |result, k|
- if (x = result[k.to_sym]).nil?
- return nil
- else
- x
- end
- end
- end
-
- # Evaluates a default translation.
- # If the given default is a String it is used literally. If it is a Symbol
- # it will be translated with the given options. If it is an Array the first
- # translation yielded will be returned.
- #
- # <em>I.e.</em>, <tt>default(locale, [:foo, 'default'])</tt> will return +default+ if
- # <tt>translate(locale, :foo)</tt> does not yield a result.
- def default(locale, default, options = {})
- case default
- when String then default
- when Symbol then translate locale, default, options
- when Array then default.each do |obj|
- result = default(locale, obj, options.dup) and return result
- end and nil
- end
- rescue MissingTranslationData
- nil
- end
-
- # Picks a translation from an array according to English pluralization
- # rules. It will pick the first translation if count is not equal to 1
- # 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
- # raise InvalidPluralizationData.new(entry, count) unless entry.is_a?(Hash)
- key = :zero if count == 0 && entry.has_key?(:zero)
- key ||= count == 1 ? :one : :other
- raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key)
- entry[key]
- end
-
- # Interpolates values into a given string.
- #
- # 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)
-
- string.gsub(MATCH) do
- escaped, pattern, key = $1, $2, $2.to_sym
-
- if escaped
- pattern
- elsif INTERPOLATION_RESERVED_KEYS.include?(pattern)
- raise ReservedInterpolationKey.new(pattern, string)
- elsif !values.include?(key)
- raise MissingInterpolationArgument.new(pattern, string)
- else
- values[key].to_s
- end
- end
- end
-
- # Loads a single translations file by delegating to #load_rb or
- # #load_yml depending on the file extension and directly merges the
- # data to the existing translations. Raises I18n::UnknownFileType
- # for all other file extensions.
- 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) }
- end
-
- # Loads a plain Ruby translations file. eval'ing the file must yield
- # a Hash containing translation data with locales as toplevel keys.
- def load_rb(filename)
- eval(IO.read(filename), binding, filename)
- end
-
- # Loads a YAML translations file. The data must have locales as
- # toplevel keys.
- 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)
- locale = locale.to_sym
- translations[locale] ||= {}
- data = deep_symbolize_keys(data)
-
- # deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
- merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
- translations[locale].merge!(data, &merger)
- end
-
- # 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
- end
- end
-end
View
5 activesupport/lib/active_support/vendor/i18n-0.1.3/test/all.rb
@@ -1,5 +0,0 @@
-dir = File.dirname(__FILE__)
-require dir + '/i18n_test.rb'
-require dir + '/simple_backend_test.rb'
-require dir + '/i18n_exceptions_test.rb'
-# *require* dir + '/custom_backend_test.rb'
View
124 activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb
@@ -1,124 +0,0 @@
-$:.unshift "lib"
-
-require 'rubygems'
-require 'test/unit'
-require 'i18n'
-require 'active_support'
-
-class I18nTest < Test::Unit::TestCase
- def setup
- I18n.backend.store_translations :'en', {
- :currency => {
- :format => {
- :separator => '.',
- :delimiter => ',',
- }
- }
- }
- end
-
- def test_uses_simple_backend_set_by_default
- assert I18n.backend.is_a?(I18n::Backend::Simple)
- end
-
- def test_can_set_backend
- assert_nothing_raised{ I18n.backend = self }
- assert_equal self, I18n.backend
- I18n.backend = I18n::Backend::Simple.new
- end
-
- def test_uses_en_us_as_default_locale_by_default
- assert_equal 'en', I18n.default_locale
- end
-
- def test_can_set_default_locale
- assert_nothing_raised{ I18n.default_locale = 'de' }
- assert_equal 'de', I18n.default_locale
- I18n.default_locale = 'en'
- end
-
- def test_uses_default_locale_as_locale_by_default
- assert_equal I18n.default_locale, I18n.locale
- end
-
- def test_can_set_locale_to_thread_current
- assert_nothing_raised{ I18n.locale = 'de' }
- assert_equal 'de', I18n.locale
- assert_equal 'de', Thread.current[:locale]
- I18n.locale = 'en'
- end
-
- def test_can_set_exception_handler
- assert_nothing_raised{ I18n.exception_handler = :custom_exception_handler }
- I18n.exception_handler = :default_exception_handler # revert it
- end
-
- def test_uses_custom_exception_handler
- I18n.exception_handler = :custom_exception_handler
- I18n.expects(:custom_exception_handler)
- I18n.translate :bogus
- I18n.exception_handler = :default_exception_handler # revert it
- end
-
- def test_delegates_translate_to_backend
- I18n.backend.expects(:translate).with 'de', :foo, {}
- I18n.translate :foo, :locale => 'de'
- end
-
- def test_delegates_localize_to_backend
- I18n.backend.expects(:localize).with 'de', :whatever, :default
- I18n.localize :whatever, :locale => 'de'
- end
-
- def test_translate_given_no_locale_uses_i18n_locale
- I18n.backend.expects(:translate).with 'en', :foo, {}
- I18n.translate :foo
- end
-
- def test_translate_on_nested_symbol_keys_works
- assert_equal ".", I18n.t(:'currency.format.separator')
- end
-
- def test_translate_with_nested_string_keys_works
- assert_equal ".", I18n.t('currency.format.separator')
- end
-
- def test_translate_with_array_as_scope_works
- assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
- end
-
- def test_translate_with_array_containing_dot_separated_strings_as_scope_works
- assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
- end
-
- def test_translate_with_key_array_and_dot_separated_scope_works
- assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
- end
-
- def test_translate_with_dot_separated_key_array_and_scope_works
- assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
- end
-
- def test_translate_with_options_using_scope_works
- I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format")
- I18n.with_options :locale => 'de', :scope => :'currency.format' do |locale|
- locale.t :precision
- end
- end
-
- # def test_translate_given_no_args_raises_missing_translation_data
- # assert_equal "translation missing: en, no key", I18n.t
- # end
-
- def test_translate_given_a_bogus_key_raises_missing_translation_data
- assert_equal "translation missing: en, bogus", I18n.t(:bogus)
- end
-
- def test_localize_nil_raises_argument_error
- assert_raise(I18n::ArgumentError) { I18n.l nil }
- end
-
- def test_localize_object_raises_argument_error
- assert_raise(I18n::ArgumentError) { I18n.l Object.new }
- end
-end
View
1  activesupport/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb
@@ -1 +0,0 @@
-{:'en-Ruby' => {:foo => {:bar => "baz"}}}
View
3  activesupport/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml
@@ -1,3 +0,0 @@
-en-Yaml:
- foo:
- bar: baz
View
567 activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb
@@ -1,567 +0,0 @@
-# encoding: utf-8
-$:.unshift "lib"
-
-require 'rubygems'
-require 'test/unit'
-require 'i18n'
-require 'time'
-require 'yaml'
-
-module I18nSimpleBackendTestSetup
- def setup_backend
- # backend_reset_translations!
- @backend = I18n::Backend::Simple.new
- @backend.store_translations 'en', :foo => {:bar => 'bar', :baz => 'baz'}
- @locale_dir = File.dirname(__FILE__) + '/locale'
- end
- alias :setup :setup_backend
-
- # def backend_reset_translations!
- # I18n::Backend::Simple::ClassMethods.send :class_variable_set, :@@translations, {}
- # end
-
- def backend_get_translations
- # I18n::Backend::Simple::ClassMethods.send :class_variable_get, :@@translations
- @backend.instance_variable_get :@translations
- end
-
- def add_datetime_translations
- @backend.store_translations :'de', {
- :date => {
- :formats => {
- :default => "%d.%m.%Y",
- :short => "%d. %b",
- :long => "%d. %B %Y",
- },
- :day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
- :abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
- :month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
- :abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil),
- :order => [:day, :month, :year]
- },
- :time => {
- :formats => {
- :default => "%a, %d. %b %Y %H:%M:%S %z",
- :short => "%d. %b %H:%M",
- :long => "%d. %B %Y %H:%M",
- },
- :am => 'am',
- :pm => 'pm'
- },
- :datetime => {
- :distance_in_words => {
- :half_a_minute => 'half a minute',
- :less_than_x_seconds => {
- :one => 'less than 1 second',
- :other => 'less than {{count}} seconds'
- },
- :x_seconds => {
- :one => '1 second',
- :other => '{{count}} seconds'
- },
- :less_than_x_minutes => {
- :one => 'less than a minute',
- :other => 'less than {{count}} minutes'
- },
- :x_minutes => {
- :one => '1 minute',
- :other => '{{count}} minutes'
- },
- :about_x_hours => {
- :one => 'about 1 hour',
- :other => 'about {{count}} hours'
- },
- :x_days => {
- :one => '1 day',
- :other => '{{count}} days'
- },
- :about_x_months => {
- :one => 'about 1 month',
- :other => 'about {{count}} months'
- },
- :x_months => {
- :one => '1 month',
- :other => '{{count}} months'
- },
- :about_x_years => {
- :one => 'about 1 year',
- :other => 'about {{count}} year'
- },
- :over_x_years => {
- :one => 'over 1 year',
- :other => 'over {{count}} years'
- }
- }
- }
- }
- end
-end
-
-class I18nSimpleBackendTranslationsTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def test_store_translations_adds_translations # no, really :-)
- @backend.store_translations :'en', :foo => 'bar'
- assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
- end
-
- def test_store_translations_deep_merges_translations
- @backend.store_translations :'en', :foo => {:bar => 'bar'}
- @backend.store_translations :'en', :foo => {:baz => 'baz'}
- assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
- end
-
- def test_store_translations_forces_locale_to_sym
- @backend.store_translations 'en', :foo => 'bar'
- assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
- end
-
- def test_store_translations_converts_keys_to_symbols
- # backend_reset_translations!
- @backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
- assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
- end
-end
-
-class I18nSimpleBackendAvailableLocalesTest < Test::Unit::TestCase
- def test_available_locales
- @backend = I18n::Backend::Simple.new
- @backend.store_translations 'de', :foo => 'bar'
- @backend.store_translations 'en', :foo => 'foo'
-
- assert_equal ['de', 'en'], @backend.available_locales.map{|locale| locale.to_s }.sort
- end
-end
-
-class I18nSimpleBackendTranslateTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def test_translate_calls_lookup_with_locale_given
- @backend.expects(:lookup).with('de', :bar, [:foo]).returns 'bar'
- @backend.translate 'de', :bar, :scope => [:foo]
- end
-
- def test_given_no_keys_it_returns_the_default
- assert_equal 'default', @backend.translate('en', nil, :default => 'default')
- end
-
- def test_translate_given_a_symbol_as_a_default_translates_the_symbol
- assert_equal 'bar', @backend.translate('en', nil, :scope => [:foo], :default => :bar)
- end
-
- def test_translate_given_an_array_as_default_uses_the_first_match
- assert_equal 'bar', @backend.translate('en', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :bar])
- end
-
- def test_translate_given_an_array_of_inexistent_keys_it_raises_missing_translation_data
- assert_raise I18n::MissingTranslationData do
- @backend.translate('en', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :does_not_exist_3])
- end
- end
-
- def test_translate_an_array_of_keys_translates_all_of_them
- assert_equal %w(bar baz), @backend.translate('en', [:bar, :baz], :scope => [:foo])
- end
-
- def test_translate_calls_pluralize
- @backend.expects(:pluralize).with 'en', 'bar', 1
- @backend.translate 'en', :bar, :scope => [:foo], :count => 1
- end
-
- def test_translate_calls_interpolate
- @backend.expects(:interpolate).with 'en', 'bar', {}
- @backend.translate 'en', :bar, :scope => [:foo]
- end
-
- def test_translate_calls_interpolate_including_count_as_a_value
- @backend.expects(:interpolate).with 'en', 'bar', {:count => 1}
- @backend.translate 'en', :bar, :scope => [:foo], :count => 1
- end
-
- def test_translate_given_nil_as_a_locale_raises_an_argument_error
- assert_raise(I18n::InvalidLocale){ @backend.translate nil, :bar }
- end
-
- def test_translate_with_a_bogus_key_and_no_default_raises_missing_translation_data
- assert_raise(I18n::MissingTranslationData){ @backend.translate 'de', :bogus }
- end
-end
-
-class I18nSimpleBackendLookupTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- # useful because this way we can use the backend with no key for interpolation/pluralization
- def test_lookup_given_nil_as_a_key_returns_nil
- assert_nil @backend.send(:lookup, 'en', nil)
- end
-
- def test_lookup_given_nested_keys_looks_up_a_nested_hash_value
- assert_equal 'bar', @backend.send(:lookup, 'en', :bar, [:foo])
- end
-end
-
-class I18nSimpleBackendPluralizeTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def test_pluralize_given_nil_returns_the_given_entry
- entry = {:one => 'bar', :other => 'bars'}
- assert_equal entry, @backend.send(:pluralize, nil, entry, nil)
- end
-
- def test_pluralize_given_0_returns_zero_string_if_zero_key_given
- assert_equal 'zero', @backend.send(:pluralize, nil, {:zero => 'zero', :one => 'bar', :other => 'bars'}, 0)
- end
-
- def test_pluralize_given_0_returns_plural_string_if_no_zero_key_given
- assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 0)
- end
-
- def test_pluralize_given_1_returns_singular_string
- assert_equal 'bar', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 1)
- end
-
- def test_pluralize_given_2_returns_plural_string
- assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 2)
- end
-
- def test_pluralize_given_3_returns_plural_string
- assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 3)
- end
-
- def test_interpolate_given_incomplete_pluralization_data_raises_invalid_pluralization_data
- assert_raise(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, {:one => 'bar'}, 2) }
- end
-
- # def test_interpolate_given_a_string_raises_invalid_pluralization_data
- # assert_raise(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, 'bar', 2) }
- # end
- #
- # def test_interpolate_given_an_array_raises_invalid_pluralization_data
- # assert_raise(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, ['bar'], 2) }
- # end
-end
-
-class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def test_interpolate_given_a_value_hash_interpolates_the_values_to_the_string
- assert_equal 'Hi David!', @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => 'David')
- end
-
- def test_interpolate_given_a_value_hash_interpolates_into_unicode_string
- assert_equal 'Häi David!', @backend.send(:interpolate, nil, 'Häi {{name}}!', :name => 'David')
- end
-
- def test_interpolate_given_an_unicode_value_hash_interpolates_to_the_string
- assert_equal 'Hi ゆきひろ!', @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => 'ゆきひろ')
- end
-
- def test_interpolate_given_an_unicode_value_hash_interpolates_into_unicode_string
- assert_equal 'こんにちは、ゆきひろさん!', @backend.send(:interpolate, nil, 'こんにちは、{{name}}さん!', :name => 'ゆきひろ')
- end
-
- if Kernel.const_defined?(:Encoding)
- def test_interpolate_given_a_non_unicode_multibyte_value_hash_interpolates_into_a_string_with_the_same_encoding
- assert_equal euc_jp('Hi ゆきひろ!'), @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => euc_jp('ゆきひろ'))
- end
-
- def test_interpolate_given_an_unicode_value_hash_into_a_non_unicode_multibyte_string_raises_encoding_compatibility_error
- assert_raise(Encoding::CompatibilityError) do
- @backend.send(:interpolate, nil, euc_jp('こんにちは、{{name}}さん!'), :name => 'ゆきひろ')
- end
- end
-
- def test_interpolate_given_a_non_unicode_multibyte_value_hash_into_an_unicode_string_raises_encoding_compatibility_error
- assert_raise(Encoding::CompatibilityError) do
- @backend.send(:interpolate, nil, 'こんにちは、{{name}}さん!', :name => euc_jp('ゆきひろ'))
- end
- end
- end
-
- def test_interpolate_given_nil_as_a_string_returns_nil
- assert_nil @backend.send(:interpolate, nil, nil, :name => 'David')
- end
-
- def test_interpolate_given_an_non_string_as_a_string_returns_nil
- assert_equal [], @backend.send(:interpolate, nil, [], :name => 'David')
- end
-
- def test_interpolate_given_a_values_hash_with_nil_values_interpolates_the_string
- assert_equal 'Hi !', @backend.send(:interpolate, nil, 'Hi {{name}}!', {:name => nil})
- end
-
- def test_interpolate_given_an_empty_values_hash_raises_missing_interpolation_argument
- assert_raise(I18n::MissingInterpolationArgument) { @backend.send(:interpolate, nil, 'Hi {{name}}!', {}) }
- end
-
- def test_interpolate_given_a_string_containing_a_reserved_key_raises_reserved_interpolation_key
- assert_raise(I18n::ReservedInterpolationKey) { @backend.send(:interpolate, nil, '{{default}}', {:default => nil}) }
- end
-
- private
-
- def euc_jp(string)
- string.encode!(Encoding::EUC_JP)
- end
-end
-
-class I18nSimpleBackendLocalizeDateTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def setup
- @backend = I18n::Backend::Simple.new
- add_datetime_translations
- @date = Date.new 2008, 1, 1
- end
-
- def test_translate_given_the_short_format_it_uses_it
- assert_equal '01. Jan', @backend.localize('de', @date, :short)
- end
-
- def test_translate_given_the_long_format_it_uses_it
- assert_equal '01. Januar 2008', @backend.localize('de', @date, :long)
- end
-
- def test_translate_given_the_default_format_it_uses_it
- assert_equal '01.01.2008', @backend.localize('de', @date, :default)
- end
-
- def test_translate_given_a_day_name_format_it_returns_a_day_name
- assert_equal 'Dienstag', @backend.localize('de', @date, '%A')
- end
-
- def test_translate_given_an_abbr_day_name_format_it_returns_an_abbrevated_day_name
- assert_equal 'Di', @backend.localize('de', @date, '%a')
- end
-
- def test_translate_given_a_month_name_format_it_returns_a_month_name
- assert_equal 'Januar', @backend.localize('de', @date, '%B')
- end
-
- def test_translate_given_an_abbr_month_name_format_it_returns_an_abbrevated_month_name
- assert_equal 'Jan', @backend.localize('de', @date, '%b')
- end
-
- def test_translate_given_no_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de', @date }
- end
-
- def test_translate_given_an_unknown_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de', @date, '%x' }
- end
-
- def test_localize_nil_raises_argument_error
- assert_raise(I18n::ArgumentError) { @backend.localize 'de', nil }
- end
-
- def test_localize_object_raises_argument_error
- assert_raise(I18n::ArgumentError) { @backend.localize 'de', Object.new }
- end
-end
-
-class I18nSimpleBackendLocalizeDateTimeTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def setup
- @backend = I18n::Backend::Simple.new
- add_datetime_translations
- @morning = DateTime.new 2008, 1, 1, 6
- @evening = DateTime.new 2008, 1, 1, 18
- end
-
- def test_translate_given_the_short_format_it_uses_it
- assert_equal '01. Jan 06:00', @backend.localize('de', @morning, :short)
- end
-
- def test_translate_given_the_long_format_it_uses_it
- assert_equal '01. Januar 2008 06:00', @backend.localize('de', @morning, :long)
- end
-
- def test_translate_given_the_default_format_it_uses_it
- assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de', @morning, :default)
- end
-
- def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
- assert_equal 'Dienstag', @backend.localize('de', @morning, '%A')
- end
-
- def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
- assert_equal 'Di', @backend.localize('de', @morning, '%a')
- end
-
- def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
- assert_equal 'Januar', @backend.localize('de', @morning, '%B')
- end
-
- def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
- assert_equal 'Jan', @backend.localize('de', @morning, '%b')
- end
-
- def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
- assert_equal 'am', @backend.localize('de', @morning, '%p')
- assert_equal 'pm', @backend.localize('de', @evening, '%p')
- end
-
- def test_translate_given_no_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de', @morning }
- end
-
- def test_translate_given_an_unknown_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de', @morning, '%x' }
- end
-end
-
-class I18nSimpleBackendLocalizeTimeTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def setup
- @old_timezone, ENV['TZ'] = ENV['TZ'], 'UTC'
- @backend = I18n::Backend::Simple.new
- add_datetime_translations
- @morning = Time.parse '2008-01-01 6:00 UTC'
- @evening = Time.parse '2008-01-01 18:00 UTC'
- end
-
- def teardown
- @old_timezone ? ENV['TZ'] = @old_timezone : ENV.delete('TZ')
- end
-
- def test_translate_given_the_short_format_it_uses_it
- assert_equal '01. Jan 06:00', @backend.localize('de', @morning, :short)
- end
-
- def test_translate_given_the_long_format_it_uses_it
- assert_equal '01. Januar 2008 06:00', @backend.localize('de', @morning, :long)
- end
-
- # TODO Seems to break on Windows because ENV['TZ'] is ignored. What's a better way to do this?
- # def test_translate_given_the_default_format_it_uses_it
- # assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de', @morning, :default)
- # end
-
- def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
- assert_equal 'Dienstag', @backend.localize('de', @morning, '%A')
- end
-
- def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
- assert_equal 'Di', @backend.localize('de', @morning, '%a')
- end
-
- def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
- assert_equal 'Januar', @backend.localize('de', @morning, '%B')
- end
-
- def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
- assert_equal 'Jan', @backend.localize('de', @morning, '%b')
- end
-
- def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
- assert_equal 'am', @backend.localize('de', @morning, '%p')
- assert_equal 'pm', @backend.localize('de', @evening, '%p')
- end
-
- def test_translate_given_no_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de', @morning }
- end
-
- def test_translate_given_an_unknown_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de', @morning, '%x' }
- end
-end
-
-class I18nSimpleBackendHelperMethodsTest < Test::Unit::TestCase
- def setup
- @backend = I18n::Backend::Simple.new
- end
-
- def test_deep_symbolize_keys_works
- result = @backend.send :deep_symbolize_keys, 'foo' => {'bar' => {'baz' => 'bar'}}
- expected = {:foo => {:bar => {:baz => 'bar'}}}
- assert_equal expected, result
- end
-end
-
-class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def test_load_translations_with_unknown_file_type_raises_exception
- assert_raise(I18n::UnknownFileType) { @backend.load_translations "#{@locale_dir}/en.xml" }
- end
-
- def test_load_translations_with_ruby_file_type_does_not_raise_exception
- assert_nothing_raised { @backend.load_translations "#{@locale_dir}/en.rb" }
- end
-
- def test_load_rb_loads_data_from_ruby_file
- data = @backend.send :load_rb, "#{@locale_dir}/en.rb"
- assert_equal({:'en-Ruby' => {:foo => {:bar => "baz"}}}, data)
- end
-
- def test_load_rb_loads_data_from_yaml_file
- data = @backend.send :load_yml, "#{@locale_dir}/en.yml"
- assert_equal({'en-Yaml' => {'foo' => {'bar' => 'baz'}}}, data)
- end
-
- def test_load_translations_loads_from_different_file_formats
- @backend = I18n::Backend::Simple.new
- @backend.load_translations "#{@locale_dir}/en.rb", "#{@locale_dir}/en.yml"
- expected = {
- :'en-Ruby' => {:foo => {:bar => "baz"}},
- :'en-Yaml' => {:foo => {:bar => "baz"}}
- }
- assert_equal expected, backend_get_translations
- end
-end
-
-class I18nSimpleBackendLoadPathTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def teardown
- I18n.load_path = []
- end
-
- def test_nested_load_paths_do_not_break_locale_loading
- @backend = I18n::Backend::Simple.new
- I18n.load_path = [[File.dirname(__FILE__) + '/locale/en.yml']]
- assert_nil backend_get_translations
- assert_nothing_raised { @backend.send :init_translations }
- assert_not_nil backend_get_translations
- end
-
- def test_adding_arrays_of_filenames_to_load_path_do_not_break_locale_loading
- @backend = I18n::Backend::Simple.new
- I18n.load_path << Dir[File.dirname(__FILE__) + '/locale/*.{rb,yml}']
- assert_nil backend_get_translations
- assert_nothing_raised { @backend.send :init_translations }
- assert_not_nil backend_get_translations
- end
-end
-
-class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def setup
- @backend = I18n::Backend::Simple.new
- I18n.load_path = [File.dirname(__FILE__) + '/locale/en.yml']
- assert_nil backend_get_translations
- @backend.send :init_translations
- end
-
- def teardown
- I18n.load_path = []
- end
-
- def test_setup
- assert_not_nil backend_get_translations
- end
-
- def test_reload_translations_unloads_translations
- @backend.reload!
- assert_nil backend_get_translations
- end
-
- def test_reload_translations_uninitializes_translations
- @backend.reload!
- assert_equal @backend.initialized?, false
- end
-end
View
3  activesupport/lib/active_support/vendor/i18n-0.3.3/.gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+test/rails/fixtures
+doc
View
76 activesupport/lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile
@@ -0,0 +1,76 @@
+h1. Changelog
+
+h2. master
+
+* (no changes)
+
+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
0  ...ive_support/vendor/i18n-0.1.3/MIT-LICENSE → ...ive_support/vendor/i18n-0.3.3/MIT-LICENSE
File renamed without changes
View
81 activesupport/lib/active_support/vendor/i18n-0.3.3/README.textile
@@ -0,0 +1,81 @@
+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)
+* 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: ActiveRecordMissing)
+
+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. 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
+
+* Akira Matsuda
+* Andrew Briening
+* Clemens Kofler
+* Frederick Cheung
+* Jeremy Kemper
+* José Valim
+* Lawrence Pit
+* Luca Guidi
+* M4SSIVE
+* Marko Seppae
+* Mathias Meyer
+* Michael Lang
+* Theo Cushion
+* Yaroslav Markin
+
+h2. License
+
+MIT License. See the included MIT-LICENCE file.
View
24 activesupport/lib/active_support/vendor/i18n-0.3.3/Rakefile
@@ -0,0 +1,24 @@
+task :default => [:test]
+
+task :test do
+ ruby "test/all.rb"
+end
+
+require File.expand_path("lib/i18n/version", File.dirname(__FILE__))
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |s|
+ s.name = "i18n"
+ s.version = I18n::VERSION
+ s.rubyforge_project = "i18n"
+ s.summary = "New wave Internationalization support for Ruby"
+ s.email = "rails-i18n@googlegroups.com"
+ s.homepage = "http://rails-i18n.org"
+ s.description = "Add Internationalization support to your Ruby application."
+ s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Matt Aimonetti', 'Stephan Soller', 'Saimon Moore']
+ s.files = FileList["[A-Z]*", "{lib,test,vendor}/**/*"]
+ end
+rescue LoadError
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+end
View
144 activesupport/lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml
@@ -0,0 +1,144 @@
+en:
+ first: "First"
+ 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
71 activesupport/lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb
@@ -0,0 +1,71 @@
+#! /usr/bin/ruby
+$:.unshift File.expand_path("../lib", File.dirname(__FILE__))
+
+require 'i18n'
+require 'i18n/core_ext/object/meta_class'
+require 'benchmark'
+require 'yaml'
+
+# Load YAML example file
+YAML_HASH = YAML.load_file(File.expand_path("example.yml", File.dirname(__FILE__)))
+
+# Create benchmark backends
+def create_backend(*modules)
+ Class.new do
+ modules.unshift(:Base)
+ modules.each { |m| include I18n::Backend.const_get(m) }
+ end
+end
+
+BACKENDS = []
+BACKENDS << (SimpleBackend = create_backend)
+BACKENDS << (FastBackend = create_backend(:Fast))
+BACKENDS << (InterpolationBackend = create_backend(:InterpolationCompiler))
+BACKENDS << (FastInterpolBackend = create_backend(:Fast, :InterpolationCompiler))
+
+# Hack Report to print ms
+module Benchmark
+ def self.ms(label = "", width=20, &blk) # :yield:
+ print label.ljust(width)
+ res = Benchmark::measure(&blk)
+ print format("%10.6f ms\n", res.real * 1000)
+ res
+ end
+end
+
+# Run!
+BACKENDS.each do |backend|
+ I18n.backend = backend.new
+ puts "===> #{backend.name}\n\n"
+
+ Benchmark.ms "store" do
+ I18n.backend.store_translations *(YAML_HASH.to_a.first)
+ I18n.backend.translate :en, :first
+ end
+
+ Benchmark.ms "t (depth=3)" do
+ I18n.backend.translate :en, :"activerecord.models.user"
+ end
+
+ Benchmark.ms "t (depth=5)" do
+ I18n.backend.translate :en, :"activerecord.attributes.admins.user.login"
+ end
+
+ Benchmark.ms "t (depth=7)" do
+ I18n.backend.translate :en, :"activerecord.errors.models.user.attributes.login.blank"
+ end
+
+ Benchmark.ms "t w/ default" do
+ I18n.backend.translate :en, :"activerecord.models.another", :default => "Another"
+ end
+
+ Benchmark.ms "t w/ interpolation" do
+ I18n.backend.translate :en, :"activerecord.errors.models.user.blank", :model => "User", :attribute => "name"
+ end
+
+ Benchmark.ms "t subtree" do
+ I18n.backend.translate :en, :"activerecord.errors.messages"
+ end
+
+ puts
+end
View
17 activesupport/lib/active_support/vendor/i18n-0.3.3/contributors.txt
@@ -0,0 +1,17 @@
+Akira Matsuda
+Andrew Briening
+Clemens Kofler
+Frederick Cheung
+Jeremy Kemper
+Josh Harvey
+José Valim
+Lawrence Pit
+Luca Guidi
+M4SSIVE
+Marko Seppae
+Mathias Meyer
+Matt Aimonetti
+Michael Lang
+Sven Fuchs
+Theo Cushion
+Yaroslav Markin
View
165 activesupport/lib/active_support/vendor/i18n-0.3.3/i18n.gemspec
@@ -0,0 +1,165 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{i18n}
+ s.version = "0.3.3"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Sven Fuchs", "Joshua Harvey", "Matt Aimonetti", "Stephan Soller", "Saimon Moore"]
+ s.date = %q{2009-12-29}
+ s.description = %q{Add Internationalization support to your Ruby application.}
+ s.email = %q{rails-i18n@googlegroups.com}
+ s.extra_rdoc_files = [
+ "README.textile"
+ ]
+ s.files = [
+ "CHANGELOG.textile",
+ "MIT-LICENSE",
+ "README.textile",
+ "Rakefile",
+ "lib/i18n.rb",
+ "lib/i18n/backend.rb",
+ "lib/i18n/backend/active_record.rb",
+ "lib/i18n/backend/active_record/missing.rb",
+ "lib/i18n/backend/active_record/store_procs.rb",
+ "lib/i18n/backend/active_record/translation.rb",
+ "lib/i18n/backend/base.rb",
+ "lib/i18n/backend/cache.rb",
+ "lib/i18n/backend/cascade.rb",
+ "lib/i18n/backend/chain.rb",
+ "lib/i18n/backend/fallbacks.rb",
+ "lib/i18n/backend/fast.rb",
+ "lib/i18n/backend/gettext.rb",
+ "lib/i18n/backend/helpers.rb",
+ "lib/i18n/backend/interpolation_compiler.rb",
+ "lib/i18n/backend/metadata.rb",
+ "lib/i18n/backend/pluralization.rb",
+ "lib/i18n/backend/simple.rb",
+ "lib/i18n/core_ext/object/meta_class.rb",
+ "lib/i18n/core_ext/string/interpolate.rb",
+ "lib/i18n/exceptions.rb",
+ "lib/i18n/gettext.rb",
+ "lib/i18n/helpers.rb",
+ "lib/i18n/helpers/gettext.rb",
+ "lib/i18n/locale.rb",
+ "lib/i18n/locale/fallbacks.rb",
+ "lib/i18n/locale/tag.rb",
+ "lib/i18n/locale/tag/parents.rb",
+ "lib/i18n/locale/tag/rfc4646.rb",
+ "lib/i18n/locale/tag/simple.rb",
+ "lib/i18n/version.rb",
+ "test/all.rb",
+ "test/api/basics.rb",
+ "test/api/defaults.rb",
+ "test/api/interpolation.rb",
+ "test/api/link.rb",
+ "test/api/localization/date.rb",
+ "test/api/localization/date_time.rb",
+ "test/api/localization/procs.rb",
+ "test/api/localization/time.rb",
+ "test/api/lookup.rb",
+ "test/api/pluralization.rb",
+ "test/api/procs.rb",
+ "test/cases/api/active_record_test.rb",
+ "test/cases/api/all_features_test.rb",
+ "test/cases/api/cascade_test.rb",
+ "test/cases/api/chain_test.rb",
+ "test/cases/api/fallbacks_test.rb",
+ "test/cases/api/fast_test.rb",
+ "test/cases/api/pluralization_test.rb",
+ "test/cases/api/simple_test.rb",
+ "test/cases/backend/active_record/missing_test.rb",
+ "test/cases/backend/active_record_test.rb",
+ "test/cases/backend/cache_test.rb",
+ "test/cases/backend/cascade_test.rb",
+ "test/cases/backend/chain_test.rb",
+ "test/cases/backend/fallbacks_test.rb",
+ "test/cases/backend/fast_test.rb",
+ "test/cases/backend/helpers_test.rb",
+ "test/cases/backend/interpolation_compiler_test.rb",
+ "test/cases/backend/metadata_test.rb",
+ "test/cases/backend/pluralization_test.rb",
+ "test/cases/backend/simple_test.rb",
+ "test/cases/core_ext/string/interpolate_test.rb",
+ "test/cases/gettext/api_test.rb",
+ "test/cases/gettext/backend_test.rb",
+ "test/cases/i18n_exceptions_test.rb",
+ "test/cases/i18n_load_path_test.rb",
+ "test/cases/i18n_test.rb",
+ "test/cases/locale/fallbacks_test.rb",
+ "test/cases/locale/tag/rfc4646_test.rb",
+ "test/cases/locale/tag/simple_test.rb",
+ "test/fixtures/locales/de.po",
+ "test/fixtures/locales/en.rb",
+ "test/fixtures/locales/en.yml",
+ "test/fixtures/locales/plurals.rb",
+ "test/test_helper.rb",
+ "vendor/po_parser.rb"
+ ]
+ s.homepage = %q{http://rails-i18n.org}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{i18n}
+ s.rubygems_version = %q{1.3.5}
+ s.summary = %q{New wave Internationalization support for Ruby}
+ s.test_files = [
+ "test/all.rb",
+ "test/api/basics.rb",
+ "test/api/defaults.rb",
+ "test/api/interpolation.rb",
+ "test/api/link.rb",
+ "test/api/localization/date.rb",
+ "test/api/localization/date_time.rb",
+ "test/api/localization/procs.rb",
+ "test/api/localization/time.rb",
+ "test/api/lookup.rb",
+ "test/api/pluralization.rb",
+ "test/api/procs.rb",
+ "test/cases/api/active_record_test.rb",
+ "test/cases/api/all_features_test.rb",
+ "test/cases/api/cascade_test.rb",
+ "test/cases/api/chain_test.rb",
+ "test/cases/api/fallbacks_test.rb",
+ "test/cases/api/fast_test.rb",
+ "test/cases/api/pluralization_test.rb",
+ "test/cases/api/simple_test.rb",
+ "test/cases/backend/active_record/missing_test.rb",
+ "test/cases/backend/active_record_test.rb",
+ "test/cases/backend/cache_test.rb",
+ "test/cases/backend/cascade_test.rb",
+ "test/cases/backend/chain_test.rb",
+ "test/cases/backend/fallbacks_test.rb",
+ "test/cases/backend/fast_test.rb",
+ "test/cases/backend/helpers_test.rb",
+ "test/cases/backend/interpolation_compiler_test.rb",
+ "test/cases/backend/metadata_test.rb",
+ "test/cases/backend/pluralization_test.rb",
+ "test/cases/backend/simple_test.rb",
+ "test/cases/core_ext/string/interpolate_test.rb",
+ "test/cases/gettext/api_test.rb",
+ "test/cases/gettext/backend_test.rb",
+ "test/cases/i18n_exceptions_test.rb",
+ "test/cases/i18n_load_path_test.rb",
+ "test/cases/i18n_test.rb",
+ "test/cases/locale/fallbacks_test.rb",
+ "test/cases/locale/tag/rfc4646_test.rb",
+ "test/cases/locale/tag/simple_test.rb",
+ "test/fixtures/locales/en.rb",
+ "test/fixtures/locales/plurals.rb",
+ "test/test_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
+
View
1  activesupport/lib/active_support/vendor/i18n-0.3.3/init.rb
@@ -0,0 +1 @@
+require File.dirname(__FILE__) + '/lib/i18n'
View
120 ...ive_support/vendor/i18n-0.1.3/lib/i18n.rb → ...ive_support/vendor/i18n-0.3.3/lib/i18n.rb
@@ -1,17 +1,24 @@
-# Authors:: Matt Aimonetti (http://railsontherun.com/),
-# Sven Fuchs (http://www.artweb-design.de),
+# encoding: utf-8
+
+# 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),
-# Stephan Soller (http://www.arkanis-development.de/)
+# Matt Aimonetti (http://railsontherun.com/)
# Copyright:: Copyright (c) 2008 The Ruby i18n Team
# License:: MIT
-require 'i18n/backend/simple'
require 'i18n/exceptions'
+require 'i18n/core_ext/string/interpolate'
module I18n
+ autoload :Backend, 'i18n/backend'
+ autoload :Helpers, 'i18n/helpers'
+ autoload :Locale, 'i18n/locale'
+
@@backend = nil
@@load_path = nil
- @@default_locale = :'en'
+ @@default_locale = :en
+ @@default_separator = '.'
@@exception_handler = :default_exception_handler
class << self
@@ -32,7 +39,7 @@ def default_locale
# Sets the current default locale. Used to set a custom default locale.
def default_locale=(locale)
- @@default_locale = locale
+ @@default_locale = locale.to_sym rescue nil
end
# Returns the current locale. Defaults to I18n.default_locale.
@@ -42,12 +49,29 @@ def locale
# Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
def locale=(locale)
- Thread.current[:locale] = locale
+ Thread.current[:locale] = locale.to_sym rescue nil
end
- # Returns an array of locales for which translations are available
+ # 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
- backend.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
# Sets the exception handler.
@@ -150,7 +174,7 @@ def reload!
# or <tt>default</tt> if no translations for <tt>:foo</tt> and <tt>:bar</tt> were found.
# I18n.t :foo, :default => [:bar, 'default']
#
- # <b>BULK LOOKUP</b>
+ # *BULK LOOKUP*
#
# This returns an array with the translations for <tt>:foo</tt> and <tt>:bar</tt>.
# I18n.t [:foo, :bar]
@@ -160,15 +184,39 @@ def reload!
#
# Which is the same as using a scope option:
# I18n.t [:foo, :bar], :scope => :baz
- def translate(key, options = {})
- locale = options.delete(:locale) || I18n.locale
- backend.translate(locale, key, options)
- rescue I18n::ArgumentError => e
- raise e if options[:raise]
- send(@@exception_handler, e, locale, key, options)
+ #
+ # *LAMBDAS*
+ #
+ # Both translations and defaults can be given as Ruby lambdas. Lambdas will be
+ # 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]}}" }
+ #
+ # Then <tt>I18n.t(:salutation, :gender => 'w', :name => 'Smith') will result in "Mrs. Smith".
+ #
+ # It is recommended to use/implement lambdas in an "idempotent" way. E.g. when
+ # a cache layer is put in front of I18n.translate it will generate a cache key
+ # from the argument values passed to #translate. Therefor your lambdas should
+ # always return the same translations/values per unique combination of argument
+ # values.
+ def translate(*args)
+ options = args.pop if args.last.is_a?(Hash)
+ key = args.shift
+ locale = options && options.delete(:locale) || I18n.locale
+ raises = options && options.delete(:raise)
+ backend.translate(locale, key, options || {})
+ rescue I18n::ArgumentError => exception
+ raise exception if raises
+ handle_exception(exception, locale, key, options)
end
alias :t :translate
+ def translate!(key, options = {})
+ translate(key, options.merge( :raise => true ))
+ end
+ alias :t! :translate!
+
# Localizes certain objects, such as dates and numbers to local formatting.
def localize(object, options = {})
locale = options[:locale] || I18n.locale
@@ -177,7 +225,10 @@ def localize(object, options = {})
end
alias :l :localize
- protected
+ # making these private until Ruby 1.9.2 can send to protected methods again
+ # see http://redmine.ruby-lang.org/repositories/revision/ruby-19?rev=24280
+ private
+
# Handles exceptions raised in the backend. All exceptions except for
# MissingTranslationData exceptions are re-raised. When a MissingTranslationData
# was caught and the option :raise is not set the handler returns an error
@@ -187,13 +238,40 @@ def default_exception_handler(exception, locale, key, options)
raise exception
end
+ # Any exceptions thrown in translate will be sent to the @@exception_handler
+ # which can be a Symbol, a Proc or any other Object.
+ #
+ # If exception_handler is a Symbol then it will simply be sent to I18n as
+ # a method call. A Proc will simply be called. In any other case the
+ # method #call will be called on the exception_handler object.
+ #
+ # Examples:
+ #
+ # I18n.exception_handler = :default_exception_handler # this is the default
+ # I18n.default_exception_handler(exception, locale, key, options) # will be called like this
+ #
+ # I18n.exception_handler = lambda { |*args| ... } # a lambda
+ # I18n.exception_handler.call(exception, locale, key, options) # will be called like this
+ #
+ # I18n.exception_handler = I18nExceptionHandler.new # an object
+ # I18n.exception_handler.call(exception, locale, key, options) # will be called like this
+ def handle_exception(exception, locale, key, options)
+ case @@exception_handler
+ when Symbol
+ send(@@exception_handler, exception, locale, key, options)
+ else
+ @@exception_handler.call(exception, locale, key, options)
+ end
+ 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_translation_keys(locale, key, scope)
- keys = [locale] + Array(scope) + [key]
- keys = keys.map { |k| k.to_s.split(/\./) }
- keys.flatten.map { |k| k.to_sym }
+ def normalize_translation_keys(locale, key, scope, separator = nil)
+ keys = [locale] + Array(scope) + Array(key)
+ keys = keys.map { |k| k.to_s.split(separator || I18n.default_separator) }
+ keys = keys.flatten - ['']
+ keys.map { |k| k.to_sym }
end
end
end
View
17 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend.rb
@@ -0,0 +1,17 @@
+module I18n
+ module Backend
+ autoload :ActiveRecord, 'i18n/backend/active_record'
+ autoload :Base, 'i18n/backend/base'
+ autoload :Cache, 'i18n/backend/cache'
+ autoload :Cascade, 'i18n/backend/cascade'
+ autoload :Chain, 'i18n/backend/chain'
+ autoload :Fallbacks, 'i18n/backend/fallbacks'
+ autoload :Fast, 'i18n/backend/fast'
+ autoload :Gettext, 'i18n/backend/gettext'
+ autoload :Helpers, 'i18n/backend/helpers'
+ autoload :InterpolationCompiler, 'i18n/backend/interpolation_compiler'
+ autoload :Metadata, 'i18n/backend/metadata'
+ autoload :Pluralization, 'i18n/backend/pluralization'
+ autoload :Simple, 'i18n/backend/simple'
+ end
+end
View
70 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record.rb
@@ -0,0 +1,70 @@
+require 'i18n/backend/base'
+require 'i18n/backend/active_record/translation'
+
+#
+# This backend reads translations from a Translations table in environment database. Note that the database
+# will not automatically be prepopulated with missing keys. You can achieve this effect with the ActiveRecordMissing backend,
+# as the following example shows:
+#
+# I18n.backend = I18n::Backend::Chain.new(I18n::Backend::ActiveRecord.new, I18.backend, I18n::Backend::ActiveRecordMissing.new)
+#
+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
+
+ def reload!
+ end
+
+ def store_translations(locale, data, options = {})
+ separator = options[:separator] || I18n.default_separator
+ wind_keys(data, separator).each do |key, v|
+ Translation.locale(locale).lookup(expand_keys(key, separator), separator).delete_all
+ Translation.create(:locale => locale.to_s, :key => key.to_s, :value => v)
+ end
+ end
+
+ def available_locales
+ begin
+ Translation.available_locales
+ rescue ::ActiveRecord::StatementInvalid
+ []
+ end
+ end
+
+ protected
+
+ def lookup(locale, key, scope = [], separator = nil)
+ return unless key
+
+ separator ||= I18n.default_separator
+ 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
67 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/missing.rb
@@ -0,0 +1,67 @@
+# This extension stores translation stub records for missing translations to
+# the database.
+#
+# This is useful if you have a web based translation tool. It will populate
+# the database with untranslated keys as the application is being used. A
+# translator can then go through these and add missing translations.
+#
+# Example usage:
+#
+# I18n::Backend::Chain.send(:include, I18n::Backend::ActiveRecord::Missing)
+# I18n.backend = I18nChainBackend.new(I18n::Backend::ActiveRecord.new, I18n::Backend::Simple.new)
+#
+# Stub records for pluralizations will also be created for each key defined
+# in i18n.plural.keys.
+#
+# For example:
+#
+# # en.yml
+# en:
+# i18n:
+# plural:
+# keys: [:zero, :one, :other]
+#
+# # pl.yml
+# pl:
+# i18n:
+# plural:
+# keys: [:zero, :one, :few, :other]
+#
+# It will also persist interpolation keys in Translation#interpolations so
+# translators will be able to review and use them.
+module I18n
+ module Backend
+ class ActiveRecord
+ module Missing
+ def store_default_translations(locale, key, options = {})
+ count, scope, default, separator = options.values_at(:count, *Base::RESERVED_KEYS)
+ separator ||= I18n.default_separator
+
+ keys = I18n.send(:normalize_translation_keys, locale, key, scope, separator)[1..-1]
+ key = keys.join(separator || I18n.default_separator)
+
+ unless ActiveRecord::Translation.locale(locale).lookup(key, separator).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) }
+ end
+ end
+
+ def store_default_translation(locale, key, interpolations)
+ translation = ActiveRecord::Translation.new :locale => locale.to_s, :key => key
+ translation.interpolations = interpolations
+ translation.save
+ end
+
+ def translate(locale, key, options = {})
+ super
+
+ rescue I18n::MissingTranslationData => e
+ self.store_default_translations(locale, key, options)
+
+ raise e
+ end
+ end
+ end
+ end
+end
View
38 ...upport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/store_procs.rb
@@ -0,0 +1,38 @@
+# This module is intended to be mixed into the ActiveRecord backend to allow
+# storing Ruby Procs as translation values in the database.
+#
+# I18n.backend = I18n::Backend::ActiveRecord.new
+# I18n::Backend::ActiveRecord::Translation.send(:include, I18n::Backend::ActiveRecord::StoreProcs)
+#
+# The StoreProcs module requires the ParseTree and ruby2ruby gems and therefor
+# was extracted from the original backend.
+#
+# ParseTree is not compatible with Ruby 1.9.
+
+begin
+ require 'ruby2ruby'
+ require 'parse_tree'
+ require 'parse_tree_extensions'
+rescue LoadError => e
+ puts "can't use StoreProcs because: #{e.message}"
+end
+
+module I18n
+ module Backend
+ class ActiveRecord
+ module StoreProcs
+ def value=(v)
+ case v
+ when Proc
+ write_attribute(:value, v.to_ruby)
+ write_attribute(:is_proc, true)
+ else
+ write_attribute(:value, v)
+ end
+ end
+
+ Translation.send(:include, self) unless RUBY_VERSION >= '1.9'
+ end
+ end
+ end
+end
View
83 ...upport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/translation.rb
@@ -0,0 +1,83 @@
+require 'active_record'
+
+module I18n
+ module Backend
+ # ActiveRecord model used to store actual translations to the database.
+ #
+ # This model expects a table like the following to be already set up in
+ # your the database:
+ #
+ # create_table :translations do |t|
+ # t.string :locale
+ # t.string :key
+ # t.string :value
+ # t.boolean :is_proc, :default => false
+ # end
+ #
+ # This model supports to named scopes :locale and :lookup. The :locale
+ # scope simply adds a condition for a given locale:
+ #
+ # I18n::Backend::ActiveRecord::Translation.locale(:en).all
+ # # => all translation records that belong to the :en locale
+ #
+ # The :lookup scope adds a condition for looking up all translations
+ # that either start with the given keys (joined by an optionally given
+ # separator or I18n.default_separator) or that exactly have this key.
+ #
+ # # with translations present for :"foo.bar" and :"foo.baz"
+ # I18n::Backend::ActiveRecord::Translation.lookup(:foo)
+ # # => an array with both translation records :"foo.bar" and :"foo.baz"
+ #
+ # I18n::Backend::ActiveRecord::Translation.lookup([:foo, :bar])
+ # I18n::Backend::ActiveRecord::Translation.lookup(:"foo.bar")
+ # # => an array with the translation record :"foo.bar"
+ #
+ # When the StoreProcs module was mixed into this model then Procs will
+ # be stored to the database as Ruby code and evaluated when :value is
+ # called.
+ #
+ # Translation = I18n::Backend::ActiveRecord::Translation
+ # Translation.create \
+ # :locale => 'en'
+ # :key => 'foo'
+ # :value => lambda { |key, options| 'FOO' }
+ # Translation.find_by_locale_and_key('en', 'foo').value
+ # # => 'FOO'
+ class ActiveRecord
+ class Translation < ::ActiveRecord::Base
+ set_table_name 'translations'
+ attr_protected :is_proc, :interpolations
+
+ serialize :value
+ serialize :interpolations, Array
+
+ named_scope :locale, lambda { |locale|
+ { :conditions => { :locale => locale.to_s } }
+ }
+
+ named_scope :lookup, lambda { |keys, *separator|
+ keys = Array(keys).map! { |key| key.to_s }
+ separator = separator.first || I18n.default_separator
+ { :conditions => ["`key` IN (?) OR `key` LIKE '#{keys.last}#{separator}%'", keys] }
+ }
+
+ def self.available_locales
+ Translation.find(:all, :select => 'DISTINCT locale').map { |t| t.locale.to_sym }
+ end
+
+ def interpolates?(key)
+ self.interpolations.include?(key) if self.interpolations
+ end
+
+ def value
+ if is_proc
+ Kernel.eval read_attribute(:value)
+ else
+ value = read_attribute(:value)
+ value == 'f' ? false : value
+ end
+ end
+ end
+ end
+ end
+end
View
259 activesupport/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/base.rb
@@ -0,0 +1,259 @@
+# encoding: utf-8
+
+require 'yaml'
+
+module I18n
+ module Backend
+ module Base
+ include I18n::Backend::Helpers
+
+ RESERVED_KEYS = [:scope, :default, :separator]
+ 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.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.
+ def store_translations(locale, data, options = {})
+ merge_translations(locale, data)
+ end
+