Class: R18n::Untranslated
- Inherits:
-
Object
- Object
- R18n::Untranslated
- Defined in:
- lib/r18n-core/untranslated.rb
Overview
Return if translation isn’t exists. Unlike nil, it didn’t raise error when you try to access for subtranslations.
You can set format to print untranslated string by filters. For example: Disable standart output:
R18n::Filters.off(:untranslated)
For development environment:
R18n::Filters.add(R18n::Untranslated, :untranslated_html) do
|content, config, translated_path, untranslated_path, path|
"#{translated_path}<span style='color: red'>#{untranslated_path}</span>"
end
For production environment:
R18n::Filters.add(R18n::Untranslated, :hide_untranslated) { '' }
Instance Attribute Summary collapse
-
#locale ⇒ Object
readonly
Main locale, where string was try to find.
-
#translated_path ⇒ Object
readonly
Path, that exists in translation.
-
#untranslated_path ⇒ Object
readonly
Path, that isn’t in translation.
Class Method Summary collapse
-
._load(str) ⇒ Object
Load object from Marshalizing.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Is another locale has same code.
- #[](*params) ⇒ Object
-
#_dump(_limit) ⇒ Object
Override marshal_dump to avoid Marshalizing filter procs.
-
#initialize(translated_path, untranslated_path, locale, filters) ⇒ Untranslated
constructor
A new instance of Untranslated.
- #method_missing(name, *_params) ⇒ Object
-
#path ⇒ Object
Path to translation.
- #to_s ⇒ Object (also: #to_str)
- #translated? ⇒ Boolean
- #|(other) ⇒ Object
Constructor Details
#initialize(translated_path, untranslated_path, locale, filters) ⇒ Untranslated
Returns a new instance of Untranslated.
49 50 51 52 53 54 |
# File 'lib/r18n-core/untranslated.rb', line 49 def initialize(translated_path, untranslated_path, locale, filters) @translated_path = translated_path @untranslated_path = untranslated_path @locale = locale @filters = filters end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *_params) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/r18n-core/untranslated.rb', line 76 def method_missing(name, *_params) # It is need to fix some hack in specs if name == :to_ary raise NoMethodError, "undefined method `to_ary' for #{self}" end self[name] end |
Instance Attribute Details
#locale ⇒ Object (readonly)
Main locale, where string was try to find
47 48 49 |
# File 'lib/r18n-core/untranslated.rb', line 47 def locale @locale end |
#translated_path ⇒ Object (readonly)
Path, that exists in translation.
44 45 46 |
# File 'lib/r18n-core/untranslated.rb', line 44 def translated_path @translated_path end |
#untranslated_path ⇒ Object (readonly)
Path, that isn’t in translation.
41 42 43 |
# File 'lib/r18n-core/untranslated.rb', line 41 def untranslated_path @untranslated_path end |
Class Method Details
._load(str) ⇒ Object
Load object from Marshalizing.
71 72 73 74 |
# File 'lib/r18n-core/untranslated.rb', line 71 def self._load(str) arr = str.split(':', 3) new arr[1], arr[2], R18n.locale(arr[0]), GlobalFilterList.instance end |
Instance Method Details
#==(other) ⇒ Object
Is another locale has same code.
104 105 106 107 108 109 110 |
# File 'lib/r18n-core/untranslated.rb', line 104 def ==(other) return false unless other.is_a? Untranslated return false unless locale == other.locale return false unless translated_path == other.translated_path return false unless untranslated_path == other.untranslated_path true end |
#[](*params) ⇒ Object
85 86 87 88 |
# File 'lib/r18n-core/untranslated.rb', line 85 def [](*params) Untranslated.new(translated_path, "#{@untranslated_path}.#{params.first}", @locale, @filters) end |
#_dump(_limit) ⇒ Object
Override marshal_dump to avoid Marshalizing filter procs
66 67 68 |
# File 'lib/r18n-core/untranslated.rb', line 66 def _dump(_limit) [@locale.code, @translated_path, @untranslated_path].join(':') end |
#path ⇒ Object
Path to translation.
57 58 59 |
# File 'lib/r18n-core/untranslated.rb', line 57 def path "#{@translated_path}#{@untranslated_path}" end |
#to_s ⇒ Object Also known as: to_str
94 95 96 97 98 99 |
# File 'lib/r18n-core/untranslated.rb', line 94 def to_s @filters.process( :all, Untranslated, path, @locale, path, [@translated_path, @untranslated_path, path] ).to_s end |
#translated? ⇒ Boolean
61 62 63 |
# File 'lib/r18n-core/untranslated.rb', line 61 def translated? false end |
#|(other) ⇒ Object
90 91 92 |
# File 'lib/r18n-core/untranslated.rb', line 90 def |(other) other end |