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.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Path to translation.
-
#translated_path ⇒ Object
readonly
Path, that exists in translation.
-
#untranslated_path ⇒ Object
readonly
Path, that isn’t in translation.
Instance Method Summary collapse
- #[](*params) ⇒ Object
-
#initialize(path, untranslated_path) ⇒ Untranslated
constructor
A new instance of Untranslated.
- #method_missing(*params) ⇒ Object
- #nil? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(path, untranslated_path) ⇒ Untranslated
Returns a new instance of Untranslated.
36 37 38 39 40 |
# File 'lib/r18n-core/untranslated.rb', line 36 def initialize(path, untranslated_path) @path = path @untranslated_path = untranslated_path @translated_path = path[0...(-untranslated_path.length)] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*params) ⇒ Object
46 47 48 |
# File 'lib/r18n-core/untranslated.rb', line 46 def method_missing(*params) self[params.first] end |
Instance Attribute Details
#path ⇒ Object (readonly)
Path to translation.
28 29 30 |
# File 'lib/r18n-core/untranslated.rb', line 28 def path @path end |
#translated_path ⇒ Object (readonly)
Path, that exists in translation.
34 35 36 |
# File 'lib/r18n-core/untranslated.rb', line 34 def translated_path @translated_path end |
#untranslated_path ⇒ Object (readonly)
Path, that isn’t in translation.
31 32 33 |
# File 'lib/r18n-core/untranslated.rb', line 31 def untranslated_path @untranslated_path end |
Instance Method Details
#[](*params) ⇒ Object
50 51 52 53 |
# File 'lib/r18n-core/untranslated.rb', line 50 def [](*params) Untranslated.new("#{@path}.#{params.first}", "#{@untranslated_path}.#{params.first}") end |
#nil? ⇒ Boolean
42 43 44 |
# File 'lib/r18n-core/untranslated.rb', line 42 def nil? true end |
#to_s ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/r18n-core/untranslated.rb', line 55 def to_s if R18n.untranslated.respond_to? :gsub R18n.untranslated.gsub('%1', @path).gsub('%2', @translated_path). gsub('%3', @untranslated_path) else R18n.untranslated end end |