class R18n::TranslatedString

String, which is translated to some locale and loading from Translation.

Constants

NON_KEYS_METHODS

Attributes

locale[R]

String locale

path[R]

Path for this translation.

Public Class Methods

_load(str) click to toggle source

Load object from Marshalizing.

# File lib/r18n-core/translated_string.rb, line 70
def self._load(str)
  arr = str.split(':', 3)
  new arr[2], R18n.locale(arr[0]), arr[1]
end
new(value, locale, path, filters = nil) click to toggle source

Returns a new string object containing a copy of `str`, which translated for `path` to `locale`

Calls superclass method
# File lib/r18n-core/translated_string.rb, line 33
def initialize(value, locale, path, filters = nil)
  super(value.to_s)
  @filters = filters
  @locale  = locale
  @path    = path
end

Public Instance Methods

_dump(_limit) click to toggle source

Override marshal_dump to avoid Marshalizing filter procs

# File lib/r18n-core/translated_string.rb, line 65
def _dump(_limit)
  [@locale.code, @path, to_str].join(':')
end
as_json(_options = nil) click to toggle source

Define `as_json` for ActiveSupport compatibility.

# File lib/r18n-core/translated_string.rb, line 60
def as_json(_options = nil)
  to_str
end
get_untranslated(key) click to toggle source

Return untranslated for deeper node `key`. It is in separated methods to be used in R18n I18n backend.

# File lib/r18n-core/translated_string.rb, line 77
def get_untranslated(key)
  translated = @path.empty? ? '' : "#{@path}."
  Untranslated.new(translated, key, @locale, @filters)
end
method_missing(name, *_params) click to toggle source

Return untranslated, when user try to go deeper in translation.

Calls superclass method
# File lib/r18n-core/translated_string.rb, line 89
def method_missing(name, *_params)
  return super if NON_KEYS_METHODS.include?(name)

  get_untranslated(name.to_s)
end
respond_to_missing?(name, *args) click to toggle source
Calls superclass method
# File lib/r18n-core/translated_string.rb, line 95
def respond_to_missing?(name, *args)
  return super if NON_KEYS_METHODS.include?(name)

  true
end
to_s() click to toggle source

Override to_s to make string html safe if `html_safe` method is defined.

Calls superclass method
# File lib/r18n-core/translated_string.rb, line 51
def to_s
  if respond_to?(:html_safe)
    super.html_safe
  else
    String.new(super)
  end
end
translated?() click to toggle source

Return true for translated strings.

# File lib/r18n-core/translated_string.rb, line 46
def translated?
  true
end
|(_other) click to toggle source

Return self for translated string.

# File lib/r18n-core/translated_string.rb, line 41
def |(_other)
  self
end