Module: I18nliner::Extensions::Core
- Defined in:
- lib/i18nliner/extensions/core.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#interpolate_hash_with_html_safety(string, values) ⇒ Object
can’t super this one yet :-/.
- #translate(*args) ⇒ Object (also: #t, #t!, #translate!)
Class Method Details
.extended(base) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/i18nliner/extensions/core.rb', line 57 def self.extended(base) base.instance_eval do alias :interpolate_hash_without_html_safety :interpolate_hash alias :interpolate_hash :interpolate_hash_with_html_safety end end |
Instance Method Details
#interpolate_hash_with_html_safety(string, values) ⇒ Object
can’t super this one yet :-/
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/i18nliner/extensions/core.rb', line 45 def interpolate_hash_with_html_safety(string, values) if string.html_safe? || values.values.any?{ |v| v.is_a?(ActiveSupport::SafeBuffer) } string = ERB::Util.h(string) unless string.html_safe? values.each do |key, value| values[key] = ERB::Util.h(value) unless value.html_safe? end interpolate_hash_without_html_safety(string.to_str, values).html_safe else interpolate_hash_without_html_safety(string, values) end end |
#translate(*args) ⇒ Object Also known as: t, t!, translate!
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/i18nliner/extensions/core.rb', line 8 def translate(*args) key, = *CallHelpers.infer_arguments(args) scope = .delete(:i18nliner_scope) || Scope.root inferred_key = .delete(:i18nliner_inferred_key) key = CallHelpers.normalize_key(key, scope, inferred_key, [:scope]) if default = [:default] [:default] = CallHelpers.normalize_default(default, ) end wrappers = .delete(:wrappers) || .delete(:wrapper) result = super(key, **) # Exit now unless we have a string or a thing that delegates to a string return result unless result.respond_to?(:gsub) was_html_safe = result.html_safe? # If you are actually using nonprintable characters in your source string, you should feel ashamed result = result.gsub("\\\\", "\uE124").gsub("\\*", "\uE123") result = result.html_safe if was_html_safe if wrappers result = apply_wrappers(result, wrappers) end was_html_safe = result.html_safe? result = result.gsub("\uE123", '*').gsub("\uE124", "\\") result = result.html_safe if was_html_safe result rescue ArgumentError raise end |