Class: R18n::Untranslated

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#pathObject (readonly)

Path to translation.



28
29
30
# File 'lib/r18n-core/untranslated.rb', line 28

def path
  @path
end

#translated_pathObject (readonly)

Path, that exists in translation.



34
35
36
# File 'lib/r18n-core/untranslated.rb', line 34

def translated_path
  @translated_path
end

#untranslated_pathObject (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

Returns:

  • (Boolean)


42
43
44
# File 'lib/r18n-core/untranslated.rb', line 42

def nil?
  true
end

#to_sObject



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