[DRE-commits] [ruby-i18n] 01/03: Imported Upstream version 0.6.9

Jonas Genannt jonas at brachium-system.net
Mon Dec 30 18:37:03 UTC 2013


This is an automated email from the git hooks/post-receive script.

hggh-guest pushed a commit to branch master
in repository ruby-i18n.

commit 3d27a554058496134e9bfa188a9b9880d38a0543
Author: Jonas Genannt <jonas at brachium-system.net>
Date:   Mon Dec 30 19:26:24 2013 +0100

    Imported Upstream version 0.6.9
---
 CHANGELOG.textile            | 152 -----------------------------------------
 lib/i18n.rb                  |  36 +++++++++-
 lib/i18n/backend/base.rb     |   4 ++
 lib/i18n/backend/chain.rb    |   6 ++
 lib/i18n/config.rb           |  12 ++++
 lib/i18n/exceptions.rb       |  28 +++++++-
 lib/i18n/tests/basics.rb     |   5 ++
 lib/i18n/version.rb          |   2 +-
 metadata.yml                 | 157 +++++++++++++++++++++++--------------------
 test/i18n/exceptions_test.rb |  10 ++-
 test/i18n_test.rb            | 113 ++++++++++++++++++++++++++++++-
 11 files changed, 292 insertions(+), 233 deletions(-)

diff --git a/CHANGELOG.textile b/CHANGELOG.textile
deleted file mode 100644
index e1eeda8..0000000
--- a/CHANGELOG.textile
+++ /dev/null
@@ -1,152 +0,0 @@
-h1. Changelog
-
-h2. 0.5.0
-
-* "Extract Backend::ActiveRecord to a separate gem":https://github.com/svenfuchs/i18n/commit/197dacebad356b910d69fa69a719c2ad10cf49e6 (see "i18n-active_record":https://github.com/svenfuchs/i18n-active_record)
-* "Improve exception handling":https://github.com/svenfuchs/i18n/commit/2913ff9a7544f223f60e7d7b32c2a0e1af89812b (deprectates I18n.default_exception_handler)
-* "Change MissingTranslationData message to 'translation missing: foo.bar'":https://github.com/svenfuchs/i18n/commit/68fdfe47952325411afe5942e971ce10b2bdf900
-* "Expose MissingTranslationsData#keys method":https://github.com/svenfuchs/i18n/commit/3a37a389ecaac9670355b334e23e775549ee9822
-* "Improve Cascade#lookup (add default options)":https://github.com/svenfuchs/i18n/commit/0b9a1f2058a2be9543106cc19d08071c359511e1
-* "Finally remove deprecated interpolation syntax":https://github.com/svenfuchs/i18n/commit/2d43846d2b2a2e596f30fa58ea1c9ddb2243bb64
-
-h2. 0.4.2 (2010-10-26)
-
-* "Improve UTF8 handling":http://github.com/svenfuchs/i18n/commit/e8d5820a3b08eeca28de1a2b9c8a6ad2b9e6476c
-* "Expose I18n::VERSION":http://github.com/svenfuchs/i18n/commit/b832037bac94c7144f45f3ff5e3b4e4089781726
-* "Better deprecation output":http://github.com/svenfuchs/i18n/commit/2bee924464b8a9c33d3d7852eb1c8423aa38cc25
-
-h2. 0.4.1 (2010-06-05)
-
-* "Fix interpolation failure on Ruby 1.9":http://github.com/svenfuchs/i18n/commit/8d45bedb11c4136c00e853d104b00a8e67ec4894
-
-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
diff --git a/lib/i18n.rb b/lib/i18n.rb
index a32e0cb..ca477ea 100755
--- a/lib/i18n.rb
+++ b/lib/i18n.rb
@@ -25,7 +25,7 @@ module I18n
 
     # Write methods which delegates to the configuration object
     %w(locale backend default_locale available_locales default_separator
-      exception_handler load_path).each do |method|
+      exception_handler load_path enforce_available_locales).each do |method|
       module_eval <<-DELEGATORS, __FILE__, __LINE__ + 1
         def #{method}
           config.#{method}
@@ -147,6 +147,7 @@ module I18n
       locale   = options.delete(:locale) || config.locale
       handling = options.delete(:throw) && :throw || options.delete(:raise) && :raise # TODO deprecate :raise
 
+      enforce_available_locales!(locale)
       raise I18n::ArgumentError if key.is_a?(String) && key.empty?
 
       result = catch(:exception) do
@@ -167,6 +168,12 @@ module I18n
     end
     alias :t! :translate!
 
+    # Returns true if a translation exists for a given key, otherwise returns false.
+    def exists?(key, locale = config.locale)
+      raise I18n::ArgumentError if key.is_a?(String) && key.empty?
+      config.backend.exists?(locale, key)
+    end
+
     # Transliterates UTF-8 characters to ASCII. By default this method will
     # transliterate only Latin strings to an ASCII approximation:
     #
@@ -224,6 +231,7 @@ module I18n
       locale       = options && options.delete(:locale) || config.locale
       handling     = options && (options.delete(:throw) && :throw || options.delete(:raise) && :raise)
       replacement  = options && options.delete(:replacement)
+      enforce_available_locales!(locale)
       config.backend.transliterate(locale, key, replacement)
     rescue I18n::ArgumentError => exception
       handle_exception(handling, exception, locale, key, options || {})
@@ -234,6 +242,7 @@ module I18n
       options = options ? options.dup : {}
       locale = options.delete(:locale) || config.locale
       format = options.delete(:format) || :default
+      enforce_available_locales!(locale)
       config.backend.localize(locale, object, format, options)
     end
     alias :l :localize
@@ -262,6 +271,24 @@ module I18n
       keys
     end
 
+    # Returns true when the passed locale is in I18.available_locales.
+    # Returns false otherwise.
+    # Compare with Strings as `locale` may be coming from user input
+    def locale_available?(locale)
+      I18n.available_locales.map(&:to_s).include?(locale.to_s)
+    end
+
+    # Raises an InvalidLocale exception when the passed locale is not
+    # included in I18n.available_locales.
+    # Returns false otherwise
+    def enforce_available_locales!(locale)
+      handle_enforce_available_locales_deprecation
+
+      if config.enforce_available_locales
+        raise I18n::InvalidLocale.new(locale) if !locale_available?(locale)
+      end
+    end
+
   # 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
@@ -329,5 +356,12 @@ module I18n
            "(an instance of which is set to I18n.exception_handler by default)."
       exception.is_a?(MissingTranslation) ? exception.message : raise(exception)
     end
+
+    def handle_enforce_available_locales_deprecation
+      if config.enforce_available_locales.nil? && !@unenforced_available_locales_deprecation
+        $stderr.puts "[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message." 
+        @unenforced_available_locales_deprecation = true
+      end
+    end
   })
 end
diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb
index ad73a08..dddb145 100644
--- a/lib/i18n/backend/base.rb
+++ b/lib/i18n/backend/base.rb
@@ -42,6 +42,10 @@ module I18n
         entry
       end
 
+      def exists?(locale, key)
+        lookup(locale, key) != nil
+      end
+
       # Acts the same as +strftime+, but uses a localized version of the
       # format 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>).
diff --git a/lib/i18n/backend/chain.rb b/lib/i18n/backend/chain.rb
index c728e2b..cb6ad43 100644
--- a/lib/i18n/backend/chain.rb
+++ b/lib/i18n/backend/chain.rb
@@ -56,6 +56,12 @@ module I18n
           throw(:exception, I18n::MissingTranslation.new(locale, key, options))
         end
 
+        def exists?(locale, key)
+          backends.any? do |backend|
+            backend.exists?(locale, key)
+          end
+        end
+
         def localize(locale, object, format = :default, options = {})
           backends.each do |backend|
             catch(:exception) do
diff --git a/lib/i18n/config.rb b/lib/i18n/config.rb
index b64896f..76293a1 100644
--- a/lib/i18n/config.rb
+++ b/lib/i18n/config.rb
@@ -8,6 +8,7 @@ module I18n
 
     # Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
     def locale=(locale)
+      I18n.enforce_available_locales!(locale)
       @locale = locale.to_sym rescue nil
     end
 
@@ -28,6 +29,7 @@ module I18n
 
     # Sets the current default locale. Used to set a custom default locale.
     def default_locale=(locale)
+      I18n.enforce_available_locales!(locale)
       @@default_locale = locale.to_sym rescue nil
     end
 
@@ -105,5 +107,15 @@ module I18n
     def load_path=(load_path)
       @@load_path = load_path
     end
+
+    # [Deprecated] this will default to true in the future
+    # Defaults to nil so that it triggers the deprecation warning
+    def enforce_available_locales
+      defined?(@@enforce_available_locales) ? @@enforce_available_locales : nil
+    end
+
+    def enforce_available_locales=(enforce_available_locales)
+      @@enforce_available_locales = enforce_available_locales
+    end
   end
 end
diff --git a/lib/i18n/exceptions.rb b/lib/i18n/exceptions.rb
index c0cf438..48d50b8 100644
--- a/lib/i18n/exceptions.rb
+++ b/lib/i18n/exceptions.rb
@@ -1,3 +1,5 @@
+require 'cgi'
+
 module I18n
   # Handles exceptions raised in the backend. All exceptions except for
   # MissingTranslationData exceptions are re-thrown. When a MissingTranslationData
@@ -7,7 +9,19 @@ module I18n
     include Module.new {
       def call(exception, locale, key, options)
         if exception.is_a?(MissingTranslation)
-          options[:rescue_format] == :html ? exception.html_message : exception.message
+          #
+          # TODO: this block is to be replaced by `exception.message` when
+          # rescue_format is removed
+          if options[:rescue_format] == :html
+            if @rescue_format_deprecation
+              $stderr.puts "[DEPRECATED] I18n's :recue_format option will be removed from a future release. All exception messages will be plain text. If you need the exception handler to return an html format please set or pass a custom exception handler."
+              @rescue_format_deprecation = true
+            end
+            exception.html_message
+          else
+            exception.message
+          end
+
         elsif exception.is_a?(Exception)
           raise exception
         else
@@ -45,8 +59,9 @@ module I18n
       end
 
       def html_message
-        key = keys.last.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
-        %(<span class="translation_missing" title="translation missing: #{keys.join('.')}">#{key}</span>)
+        key  = CGI.escapeHTML titleize(keys.last)
+        path = CGI.escapeHTML keys.join('.')
+        %(<span class="translation_missing" title="translation missing: #{path}">#{key}</span>)
       end
 
       def keys
@@ -63,6 +78,13 @@ module I18n
       def to_exception
         MissingTranslationData.new(locale, key, options)
       end
+
+      protected
+
+      # TODO : remove when #html_message is removed
+      def titleize(key)
+        key.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
+      end
     end
 
     include Base
diff --git a/lib/i18n/tests/basics.rb b/lib/i18n/tests/basics.rb
index 101e7c5..dc0596a 100644
--- a/lib/i18n/tests/basics.rb
+++ b/lib/i18n/tests/basics.rb
@@ -41,6 +41,11 @@ module I18n
         assert_equal I18n.available_locales, I18n.available_locales
       end
 
+      test "exists? is implemented by the backend" do
+        I18n.backend.store_translations(:foo, :bar => 'baz')
+        assert I18n.exists?(:bar, :foo)
+      end
+
       test "storing a nil value as a translation removes it from the available locale data" do
         I18n.backend.store_translations(:en, :to_be_deleted => 'bar')
         assert_equal 'bar', I18n.t(:to_be_deleted, :default => 'baz')
diff --git a/lib/i18n/version.rb b/lib/i18n/version.rb
index c5e4154..01f274a 100644
--- a/lib/i18n/version.rb
+++ b/lib/i18n/version.rb
@@ -1,3 +1,3 @@
 module I18n
-  VERSION = "0.6.5"
+  VERSION = "0.6.9"
 end
diff --git a/metadata.yml b/metadata.yml
index 6dd4810..c3ba704 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,10 +1,15 @@
---- !ruby/object:Gem::Specification
+--- !ruby/object:Gem::Specification 
 name: i18n
-version: !ruby/object:Gem::Version
-  version: 0.6.5
+version: !ruby/object:Gem::Version 
+  hash: 21
   prerelease: 
+  segments: 
+  - 0
+  - 6
+  - 9
+  version: 0.6.9
 platform: ruby
-authors:
+authors: 
 - Sven Fuchs
 - Joshua Harvey
 - Matt Aimonetti
@@ -13,78 +18,76 @@ authors:
 autorequire: 
 bindir: bin
 cert_chain: []
-date: 2013-08-13 00:00:00.000000000 Z
-dependencies:
-- !ruby/object:Gem::Dependency
+
+date: 2013-12-03 00:00:00 Z
+dependencies: 
+- !ruby/object:Gem::Dependency 
   name: activesupport
-  requirement: !ruby/object:Gem::Requirement
-    none: false
-    requirements:
-    - - ! '>='
-      - !ruby/object:Gem::Version
-        version: 3.0.0
-  type: :development
   prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
+  requirement: &id001 !ruby/object:Gem::Requirement 
     none: false
-    requirements:
-    - - ! '>='
-      - !ruby/object:Gem::Version
+    requirements: 
+    - - ">="
+      - !ruby/object:Gem::Version 
+        hash: 7
+        segments: 
+        - 3
+        - 0
+        - 0
         version: 3.0.0
-- !ruby/object:Gem::Dependency
-  name: sqlite3
-  requirement: !ruby/object:Gem::Requirement
-    none: false
-    requirements:
-    - - ! '>='
-      - !ruby/object:Gem::Version
-        version: '0'
   type: :development
+  version_requirements: *id001
+- !ruby/object:Gem::Dependency 
+  name: sqlite3
   prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
+  requirement: &id002 !ruby/object:Gem::Requirement 
     none: false
-    requirements:
-    - - ! '>='
-      - !ruby/object:Gem::Version
-        version: '0'
-- !ruby/object:Gem::Dependency
-  name: mocha
-  requirement: !ruby/object:Gem::Requirement
-    none: false
-    requirements:
-    - - ! '>='
-      - !ruby/object:Gem::Version
-        version: '0'
+    requirements: 
+    - - ">="
+      - !ruby/object:Gem::Version 
+        hash: 3
+        segments: 
+        - 0
+        version: "0"
   type: :development
+  version_requirements: *id002
+- !ruby/object:Gem::Dependency 
+  name: mocha
   prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
-    none: false
-    requirements:
-    - - ! '>='
-      - !ruby/object:Gem::Version
-        version: '0'
-- !ruby/object:Gem::Dependency
-  name: test_declarative
-  requirement: !ruby/object:Gem::Requirement
+  requirement: &id003 !ruby/object:Gem::Requirement 
     none: false
-    requirements:
-    - - ! '>='
-      - !ruby/object:Gem::Version
-        version: '0'
+    requirements: 
+    - - ">="
+      - !ruby/object:Gem::Version 
+        hash: 3
+        segments: 
+        - 0
+        version: "0"
   type: :development
+  version_requirements: *id003
+- !ruby/object:Gem::Dependency 
+  name: test_declarative
   prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
+  requirement: &id004 !ruby/object:Gem::Requirement 
     none: false
-    requirements:
-    - - ! '>='
-      - !ruby/object:Gem::Version
-        version: '0'
+    requirements: 
+    - - ">="
+      - !ruby/object:Gem::Version 
+        hash: 3
+        segments: 
+        - 0
+        version: "0"
+  type: :development
+  version_requirements: *id004
 description: New wave Internationalization support for Ruby.
 email: rails-i18n at googlegroups.com
 executables: []
+
 extensions: []
+
 extra_rdoc_files: []
-files:
+
+files: 
 - ci/Gemfile.no-rails
 - ci/Gemfile.no-rails.lock
 - ci/Gemfile.rails-2.3.x
@@ -179,30 +182,40 @@ files:
 - test/test_helper.rb
 - README.textile
 - MIT-LICENSE
-- CHANGELOG.textile
 homepage: http://github.com/svenfuchs/i18n
-licenses:
+licenses: 
 - MIT
 post_install_message: 
 rdoc_options: []
-require_paths:
+
+require_paths: 
 - lib
-required_ruby_version: !ruby/object:Gem::Requirement
+required_ruby_version: !ruby/object:Gem::Requirement 
   none: false
-  requirements:
-  - - ! '>='
-    - !ruby/object:Gem::Version
-      version: '0'
-required_rubygems_version: !ruby/object:Gem::Requirement
+  requirements: 
+  - - ">="
+    - !ruby/object:Gem::Version 
+      hash: 3
+      segments: 
+      - 0
+      version: "0"
+required_rubygems_version: !ruby/object:Gem::Requirement 
   none: false
-  requirements:
-  - - ! '>='
-    - !ruby/object:Gem::Version
+  requirements: 
+  - - ">="
+    - !ruby/object:Gem::Version 
+      hash: 17
+      segments: 
+      - 1
+      - 3
+      - 5
       version: 1.3.5
 requirements: []
-rubyforge_project: ! '[none]'
-rubygems_version: 1.8.23
+
+rubyforge_project: "[none]"
+rubygems_version: 1.8.6
 signing_key: 
 specification_version: 3
 summary: New wave Internationalization support for Ruby
 test_files: []
+
diff --git a/test/i18n/exceptions_test.rb b/test/i18n/exceptions_test.rb
index 3c2e1cb..098eefe 100644
--- a/test/i18n/exceptions_test.rb
+++ b/test/i18n/exceptions_test.rb
@@ -28,9 +28,13 @@ class I18nExceptionsTest < Test::Unit::TestCase
   end
 
   test "MissingTranslationData html_message is a span with the titlelized last key token" do
-    force_missing_translation_data do |exception|
-      assert_equal '<span class="translation_missing" title="translation missing: de.bar.foo">Foo</span>', exception.html_message
-    end
+    exception = I18n::MissingTranslationData.new(:de, :foo, :scope => :bar)
+    assert_equal '<span class="translation_missing" title="translation missing: de.bar.foo">Foo</span>', exception.html_message
+  end
+
+  test "MissingTranslationData html_message html escapes key names" do
+    exception = I18n::MissingTranslationData.new(:de, '<script>Evil</script>', :scope => '<iframe src="example.com" />')
+    assert_equal '<span class="translation_missing" title="translation missing: de.<iframe src="example.com" />.<script>Evil</script>"><Script>Evil</Script></span>', exception.html_message
   end
 
   test "ExceptionHandler returns the html_message if :rescue_format => :html was given" do
diff --git a/test/i18n_test.rb b/test/i18n_test.rb
index c7e4aad..040d4cb 100644
--- a/test/i18n_test.rb
+++ b/test/i18n_test.rb
@@ -4,6 +4,7 @@ require 'test_helper'
 class I18nTest < Test::Unit::TestCase
   def setup
     I18n.backend.store_translations(:'en', :currency => { :format => { :separator => '.', :delimiter => ',', } })
+    I18n.backend.store_translations(:'nl', :currency => { :format => { :separator => ',', :delimiter => '.', } })
   end
 
   test "exposes its VERSION constant" do
@@ -36,6 +37,15 @@ class I18nTest < Test::Unit::TestCase
     end
   end
 
+  test "raises an I18n::InvalidLocale exception when setting an unavailable default locale" do
+    begin
+      I18n.config.enforce_available_locales = true
+      assert_raise(I18n::InvalidLocale) { I18n.default_locale = :klingon }
+    ensure
+      I18n.config.enforce_available_locales = false
+    end
+  end
+
   test "uses the default locale as a locale by default" do
     assert_equal I18n.default_locale, I18n.locale
   end
@@ -46,6 +56,15 @@ class I18nTest < Test::Unit::TestCase
     assert_equal :de, Thread.current[:i18n_config].locale
     I18n.locale = :en
   end
+  
+  test "raises an I18n::InvalidLocale exception when setting an unavailable locale" do
+    begin
+      I18n.config.enforce_available_locales = true
+      assert_raise(I18n::InvalidLocale) { I18n.locale = :klingon }
+    ensure
+      I18n.config.enforce_available_locales = false
+    end
+  end
 
   test "can set the configuration object" do
     begin
@@ -187,14 +206,56 @@ class I18nTest < Test::Unit::TestCase
     assert_raise(I18n::ArgumentError) { I18n.t("") }
   end
 
+  test "translate given an unavailable locale rases an I18n::InvalidLocale" do
+    begin
+      I18n.config.enforce_available_locales = true
+      assert_raise(I18n::InvalidLocale) { I18n.t(:foo, :locale => 'klingon') }
+    ensure
+      I18n.config.enforce_available_locales = false
+    end
+  end
+
+  test "exists? given an existing key will return true" do
+    assert_equal true, I18n.exists?(:currency)
+  end
+
+  test "exists? given a non-existing key will return false" do
+    assert_equal false, I18n.exists?(:bogus)
+  end
+
+  test "exists? given an existing dot-separated key will return true" do
+    assert_equal true, I18n.exists?('currency.format.delimiter')
+  end
+
+  test "exists? given a non-existing dot-separated key will return false" do
+    assert_equal false, I18n.exists?('currency.format.bogus')
+  end
+
+  test "exists? given an existing key and an existing locale will return true" do
+    assert_equal true, I18n.exists?(:currency, :nl)
+  end
+
+  test "exists? given a non-existing key and an existing locale will return false" do
+    assert_equal false, I18n.exists?(:bogus, :nl)
+  end
+
   test "localize given nil raises an I18n::ArgumentError" do
     assert_raise(I18n::ArgumentError) { I18n.l nil }
   end
 
-  test "localize givan an Object raises an I18n::ArgumentError" do
+  test "localize given an Object raises an I18n::ArgumentError" do
     assert_raise(I18n::ArgumentError) { I18n.l Object.new }
   end
 
+  test "localize given an unavailable locale rases an I18n::InvalidLocale" do
+    begin
+      I18n.config.enforce_available_locales = true
+      assert_raise(I18n::InvalidLocale) { I18n.l(Time.now, :locale => 'klingon') }
+    ensure
+      I18n.config.enforce_available_locales = false
+    end
+  end
+
   test "can use a lambda as an exception handler" do
     begin
       previous_exception_handler = I18n.exception_handler
@@ -251,4 +312,54 @@ class I18nTest < Test::Unit::TestCase
     }
   end
 
+  test "transliterate given an unavailable locale rases an I18n::InvalidLocale" do
+    begin
+      I18n.config.enforce_available_locales = true
+      assert_raise(I18n::InvalidLocale) { I18n.transliterate('string', :locale => 'klingon') }
+    ensure
+      I18n.config.enforce_available_locales = false
+    end
+  end
+
+  test "I18n.locale_available? returns true when the passed locale is available" do
+    I18n.available_locales = [:en, :de]
+    assert_equal true, I18n.locale_available?(:de)
+  end
+
+  test "I18n.locale_available? returns true when the passed locale is a string and is available" do
+    I18n.available_locales = [:en, :de]
+    assert_equal true, I18n.locale_available?('de')
+  end
+
+  test "I18n.locale_available? returns false when the passed locale is unavailable" do
+    assert_equal false, I18n.locale_available?(:klingon)
+  end
+
+  test "I18n.enforce_available_locales! raises an I18n::InvalidLocale when the passed locale is unavailable" do
+    begin
+      I18n.config.enforce_available_locales = true
+      assert_raise(I18n::InvalidLocale) { I18n.enforce_available_locales!(:klingon) }
+    ensure
+      I18n.config.enforce_available_locales = false
+    end
+  end
+
+  test "I18n.enforce_available_locales! does nothing when the passed locale is available" do
+    I18n.available_locales = [:en, :de]
+    begin
+      I18n.config.enforce_available_locales = true
+      assert_nothing_raised { I18n.enforce_available_locales!(:en) }
+    ensure
+      I18n.config.enforce_available_locales = false
+    end
+  end
+
+  test "I18n.enforce_available_locales config can be set to false" do
+    begin
+      I18n.config.enforce_available_locales = false
+      assert_equal false, I18n.config.enforce_available_locales
+    ensure
+      I18n.config.enforce_available_locales = false
+    end
+  end
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-i18n.git



More information about the Pkg-ruby-extras-commits mailing list