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
-
#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(translated_path, untranslated_path, locale) ⇒ Untranslated
constructor
A new instance of Untranslated.
- #method_missing(*params) ⇒ Object
-
#path ⇒ Object
Path to translation.
- #to_s ⇒ Object
- #translated? ⇒ Boolean
- #|(default) ⇒ Object
Constructor Details
#initialize(translated_path, untranslated_path, locale) ⇒ Untranslated
Returns a new instance of Untranslated.
49 50 51 52 53 |
# File 'lib/r18n-core/untranslated.rb', line 49 def initialize(translated_path, untranslated_path, locale) @translated_path = translated_path @untranslated_path = untranslated_path @locale = locale end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*params) ⇒ Object
64 65 66 |
# File 'lib/r18n-core/untranslated.rb', line 64 def method_missing(*params) self[params.first] end |
Instance Attribute Details
#translated_path ⇒ Object (readonly)
Path, that exists in translation.
47 48 49 |
# File 'lib/r18n-core/untranslated.rb', line 47 def translated_path @translated_path end |
#untranslated_path ⇒ Object (readonly)
Path, that isn’t in translation.
44 45 46 |
# File 'lib/r18n-core/untranslated.rb', line 44 def untranslated_path @untranslated_path end |
Instance Method Details
#[](*params) ⇒ Object
68 69 70 71 |
# File 'lib/r18n-core/untranslated.rb', line 68 def [](*params) Untranslated.new(translated_path, "#{@untranslated_path}.#{params.first}", @locale) end |
#path ⇒ Object
Path to translation.
56 57 58 |
# File 'lib/r18n-core/untranslated.rb', line 56 def path "#{@translated_path}#{@untranslated_path}" end |
#to_s ⇒ Object
77 78 79 80 |
# File 'lib/r18n-core/untranslated.rb', line 77 def to_s Filters.process(Filters.enabled, Untranslated, path, @locale, path, [@translated_path, @untranslated_path, path]) end |
#translated? ⇒ Boolean
60 61 62 |
# File 'lib/r18n-core/untranslated.rb', line 60 def translated? false end |
#|(default) ⇒ Object
73 74 75 |
# File 'lib/r18n-core/untranslated.rb', line 73 def |(default) default end |