Class: I18n::Scope
- Inherits:
-
Object
show all
- Defined in:
- lib/i18n/scope.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(scope = []) ⇒ Scope
Returns a new instance of Scope.
17
18
19
|
# File 'lib/i18n/scope.rb', line 17
def initialize(scope=[])
@scope = Array(scope)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/i18n/scope.rb', line 22
def method_missing(method_name, *args, &block)
if method_name.to_s =~ /^[A-Za-z0-9_]+$/
self.scoped(method_name)
else
super(method_name, *args, &block)
end
end
|
Instance Attribute Details
#scope ⇒ Object
Returns the value of attribute scope.
20
21
22
|
# File 'lib/i18n/scope.rb', line 20
def scope
@scope
end
|
Instance Method Details
#scoped(key) ⇒ Object
39
40
41
42
43
|
# File 'lib/i18n/scope.rb', line 39
def scoped(key)
next_scope = self.scope.dup
next_scope << key
I18n::Scope.new(next_scope)
end
|
#t(value) ⇒ Object
31
32
33
|
# File 'lib/i18n/scope.rb', line 31
def t(value)
I18n.t(value, :scope => self.scope)
end
|
#to_s ⇒ Object
35
36
37
|
# File 'lib/i18n/scope.rb', line 35
def to_s
I18n.t(translation_key)
end
|
#translation_key ⇒ Object
45
46
47
|
# File 'lib/i18n/scope.rb', line 45
def translation_key
self.scope.map{|s| s.to_s }.join(".")
end
|