diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/i18n_fixes.rb | 41 | ||||
-rw-r--r-- | lib/make_html_4_compliant.rb | 3 | ||||
-rw-r--r-- | lib/use_spans_for_errors.rb | 2 |
3 files changed, 21 insertions, 25 deletions
diff --git a/lib/i18n_fixes.rb b/lib/i18n_fixes.rb index 6e684d44a..a85faddcb 100644 --- a/lib/i18n_fixes.rb +++ b/lib/i18n_fixes.rb @@ -5,39 +5,36 @@ # override behaviour in fast_gettext/translation.rb # so that we can interpolate our translation strings nicely +# TODO: We could simplify a lot of this code (as in remove it) if we moved from using the {{value}} +# convention in the translation strings for interpolation to %{value}. This is apparently the newer +# convention. + def _(key, options = {}) - translation = FastGettext._(key) || key + translation = (FastGettext._(key) || key).html_safe gettext_interpolate(translation, options) end -INTERPOLATION_RESERVED_KEYS = %w(scope default) -MATCH = /(\\\\)?\{\{([^\}]+)\}\}/ +MATCH = /\{\{([^\}]+)\}\}/ def gettext_interpolate(string, values) return string unless string.is_a?(String) - if values.is_a?(Hash) - string.gsub(MATCH) do - escaped, pattern, key = $1, $2, $2.to_sym - - if escaped - pattern - elsif INTERPOLATION_RESERVED_KEYS.include?(pattern) - raise I18n::ReservedInterpolationKey.new(pattern, string) - elsif !values.include?(key) - raise I18n::MissingInterpolationArgument.new(pattern, string) + # $1, $2 don't work with SafeBuffer so casting to string as workaround + safe = string.html_safe? + string = string.to_str.gsub(MATCH) do + pattern, key = $1, $1.to_sym + + if !values.include?(key) + raise I18n::MissingInterpolationArgument.new(pattern, string) + else + v = values[key].to_s + if safe && !v.html_safe? + ERB::Util.h(v) else - values[key].to_s + v end end - else - reserved_keys = if defined?(I18n::RESERVED_KEYS) # rails 3+ - I18n::RESERVED_KEYS - else - I18n::Backend::Base::RESERVED_KEYS - end - - string % values.except(*reserved_keys) end + safe ? string.html_safe : string end diff --git a/lib/make_html_4_compliant.rb b/lib/make_html_4_compliant.rb index 214eb9f1f..8926d5873 100644 --- a/lib/make_html_4_compliant.rb +++ b/lib/make_html_4_compliant.rb @@ -3,7 +3,6 @@ ActionView::Helpers::TagHelper.module_eval do def tag(name, options = nil, open = false, escape = true) - "<#{name}#{tag_options(options, escape) if options}" + (open ? ">" : ">") + "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : ">"}".html_safe end end - diff --git a/lib/use_spans_for_errors.rb b/lib/use_spans_for_errors.rb index cda05c588..135453f78 100644 --- a/lib/use_spans_for_errors.rb +++ b/lib/use_spans_for_errors.rb @@ -8,5 +8,5 @@ # # See http://dev.rubyonrails.org/ticket/2210 -ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| %(<span class="fieldWithErrors">#{html_tag}</span>)} +ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| %(<span class="fieldWithErrors">#{html_tag}</span>).html_safe} |