Class: R18n::TranslatedString
- Inherits:
-
String
- Object
- String
- R18n::TranslatedString
- Defined in:
- lib/r18n-core/translated_string.rb
Overview
String, which is translated to some locale and loading from Translation.
Instance Attribute Summary collapse
-
#locale ⇒ Object
readonly
String locale.
-
#path ⇒ Object
readonly
Path for this translation.
Class Method Summary collapse
-
._load(str) ⇒ Object
Load object from Marshalizing.
Instance Method Summary collapse
-
#_dump(limit) ⇒ Object
Override marshal_dump to avoid Marshalizing filter procs.
-
#get_untranslated(key) ⇒ Object
Return untranslated for deeper node ‘key`.
-
#html_safe? ⇒ Boolean
Mark translated string as html safe, because R18n has own escape system.
-
#initialize(str, locale, path, filters = nil) ⇒ TranslatedString
constructor
Returns a new string object containing a copy of
str
, which translated forpath
tolocale
. -
#method_missing(name, *params) ⇒ Object
Return untranslated, when user try to go deeper in translation.
-
#to_s ⇒ Object
Override to_s to make string html safe if ‘html_safe` method is defined.
-
#translated? ⇒ Boolean
Return true for translated strings.
-
#|(default) ⇒ Object
Return self for translated string.
Constructor Details
#initialize(str, locale, path, filters = nil) ⇒ TranslatedString
Returns a new string object containing a copy of str
, which translated for path
to locale
32 33 34 35 36 37 |
# File 'lib/r18n-core/translated_string.rb', line 32 def initialize(str, locale, path, filters = nil) super(str) @filters = filters @locale = locale @path = path end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *params) ⇒ Object
Return untranslated, when user try to go deeper in translation.
82 83 84 |
# File 'lib/r18n-core/translated_string.rb', line 82 def method_missing(name, *params) get_untranslated(name.to_s) end |
Instance Attribute Details
#locale ⇒ Object (readonly)
String locale
25 26 27 |
# File 'lib/r18n-core/translated_string.rb', line 25 def locale @locale end |
#path ⇒ Object (readonly)
Path for this translation.
28 29 30 |
# File 'lib/r18n-core/translated_string.rb', line 28 def path @path end |
Class Method Details
Instance Method Details
#_dump(limit) ⇒ Object
Override marshal_dump to avoid Marshalizing filter procs
64 65 66 |
# File 'lib/r18n-core/translated_string.rb', line 64 def _dump(limit) [@locale.code, @path, to_str].join(":") end |
#get_untranslated(key) ⇒ Object
Return untranslated for deeper node ‘key`. It is in separated methods to be used in R18n I18n backend.
76 77 78 79 |
# File 'lib/r18n-core/translated_string.rb', line 76 def get_untranslated(key) translated = @path.empty? ? '' : "#{@path}." Untranslated.new(translated, key, @locale, @filters) end |
#html_safe? ⇒ Boolean
Mark translated string as html safe, because R18n has own escape system.
50 51 52 |
# File 'lib/r18n-core/translated_string.rb', line 50 def html_safe? true end |
#to_s ⇒ Object
Override to_s to make string html safe if ‘html_safe` method is defined.
55 56 57 58 59 60 61 |
# File 'lib/r18n-core/translated_string.rb', line 55 def to_s if respond_to? :html_safe html_safe else String.new(self) end end |
#translated? ⇒ Boolean
Return true for translated strings.
45 46 47 |
# File 'lib/r18n-core/translated_string.rb', line 45 def translated? true end |
#|(default) ⇒ Object
Return self for translated string.
40 41 42 |
# File 'lib/r18n-core/translated_string.rb', line 40 def |(default) self end |