class R18n::TranslatedString

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

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 31
def initialize(value, locale, path, filters = nil)
  value = value.to_s if value.is_a? TranslatedString
  super(value)
  @filters = filters
  @locale  = locale
  @value   = value
  @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
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
html_safe?() click to toggle source

Mark translated string as html safe, because R18n has own escape system.

# File lib/r18n-core/translated_string.rb, line 51
def html_safe?
  true
end
method_missing(name, *params) click to toggle source

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

# File lib/r18n-core/translated_string.rb, line 83
def method_missing(name, *params)
  get_untranslated(name.to_s)
end
to_s() click to toggle source

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

# File lib/r18n-core/translated_string.rb, line 56
def to_s
  if respond_to? :html_safe
    @value.html_safe
  else
    @value
  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
|(default) click to toggle source

Return self for translated string.

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