diff options
author | Xavier Noria <fxn@hashref.com> | 2010-05-27 10:57:05 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-05-27 10:57:05 +0200 |
commit | ddec74fb3ab66528ca98ff37ca9b5f4227fdd2e3 (patch) | |
tree | c58ac9162487bdca68342fb2d30730ccfd926378 /actionpack/lib/action_view/helpers/translation_helper.rb | |
parent | 96e2094b8b634e4af0d9d3c8a1db9bbb7023a4a7 (diff) | |
parent | e02db06ece7aeecec7c37f5b0e3de7d65c8684e6 (diff) | |
download | rails-ddec74fb3ab66528ca98ff37ca9b5f4227fdd2e3.tar.gz rails-ddec74fb3ab66528ca98ff37ca9b5f4227fdd2e3.tar.bz2 rails-ddec74fb3ab66528ca98ff37ca9b5f4227fdd2e3.zip |
Merge remote branch 'rails/master'
Diffstat (limited to 'actionpack/lib/action_view/helpers/translation_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/translation_helper.rb | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index 086ad261c8..0d2b2aa7b1 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -3,7 +3,7 @@ require 'action_view/helpers/tag_helper' module ActionView module Helpers module TranslationHelper - # Delegates to I18n#translate but also performs three additional functions. First, it'll catch MissingTranslationData exceptions + # Delegates to I18n#translate but also performs three additional functions. First, it'll catch MissingTranslationData exceptions # and turn them into inline spans that contains the missing key, such that you can see in a view what is missing where. # # Second, it'll scope the key by the current partial if the key starts with a period. So if you call translate(".foo") from the @@ -11,16 +11,14 @@ module ActionView # to translate many keys within the same partials and gives you a simple framework for scoping them consistently. If you don't # prepend the key with a period, nothing is converted. # - # Third, it’ll mark the translation as safe HTML if the key has the suffix "_html" or the last element of the key is the word - # "html". For example, calling translate("footer_html") or translate("footer.html") will return a safe HTML string that won’t - # be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that + # Third, it’ll mark the translation as safe HTML if the key has the suffix "_html" or the last element of the key is the word + # "html". For example, calling translate("footer_html") or translate("footer.html") will return a safe HTML string that won’t + # be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that # you know what kind of output to expect when you call translate in a template. def translate(key, options = {}) - options[:raise] = true - translation = I18n.translate(scope_key_by_partial(key), options) - translation = (translation.respond_to?(:join) ? translation.join : translation) - if html_safe_translation_key?(key) + translation = I18n.translate(scope_key_by_partial(key), options.merge!(:raise => true)) + if html_safe_translation_key?(key) && translation.respond_to?(:html_safe) translation.html_safe else translation @@ -38,12 +36,10 @@ module ActionView alias :l :localize private - def scope_key_by_partial(key) - strkey = key.respond_to?(:join) ? key.join : key.to_s - if strkey.first == "." + if key.to_s.first == "." if @_virtual_path - @_virtual_path.gsub(%r{/_?}, ".") + strkey + @_virtual_path.gsub(%r{/_?}, ".") + key.to_s else raise "Cannot use t(#{key.inspect}) shortcut because path is not available" end @@ -53,8 +49,7 @@ module ActionView end def html_safe_translation_key?(key) - key = key.is_a?(Array) ? key.last : key.to_s - key =~ /(\b|_|\.)html$/ + key.to_s =~ /(\b|_|\.)html$/ end end end |