Class: R18n::UnsupportedLocale

Inherits:
Object
  • Object
show all
Defined in:
lib/r18n-core/unsupported_locale.rb

Overview

Locale without information file. Contain only it code, empty title and data from default locale.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, _base = nil) ⇒ UnsupportedLocale

Create object for unsupported locale with ‘code` and load other locale data from `base` locale.



31
32
33
34
35
# File 'lib/r18n-core/unsupported_locale.rb', line 31

def initialize(code, _base = nil)
  @code = code
  @downcased_code = @code.downcase.tr('-', '_').freeze
  @base = Locale.load(I18n.default) if @code != I18n.default
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *params) ⇒ Object

Proxy to default locale object.



58
59
60
61
62
# File 'lib/r18n-core/unsupported_locale.rb', line 58

def method_missing(name, *params)
  return super unless @base.respond_to? name

  @base.public_send(name, *params)
end

Instance Attribute Details

#baseObject

Locale, to get data and pluralization for unsupported locale.



25
26
27
# File 'lib/r18n-core/unsupported_locale.rb', line 25

def base
  @base
end

#codeObject (readonly)

Returns the value of attribute code.



27
28
29
# File 'lib/r18n-core/unsupported_locale.rb', line 27

def code
  @code
end

#downcased_codeObject (readonly)

Returns the value of attribute downcased_code.



27
28
29
# File 'lib/r18n-core/unsupported_locale.rb', line 27

def downcased_code
  @downcased_code
end

Instance Method Details

#==(other) ⇒ Object

Is another locale has same code.



53
54
55
# File 'lib/r18n-core/unsupported_locale.rb', line 53

def ==(other)
  @code.casecmp(other.code).zero?
end

#inspectObject

Human readable locale code and title.



43
44
45
# File 'lib/r18n-core/unsupported_locale.rb', line 43

def inspect
  "Unsupported locale #{@code}"
end

#respond_to_missing?(name, *args) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/r18n-core/unsupported_locale.rb', line 64

def respond_to_missing?(name, *args)
  @base.send __method__, name, *args
end

#supported?Boolean

Is locale has information file. In this class always return false.

Returns:

  • (Boolean)


38
39
40
# File 'lib/r18n-core/unsupported_locale.rb', line 38

def supported?
  false
end

#titleObject

Locale code as title.



48
49
50
# File 'lib/r18n-core/unsupported_locale.rb', line 48

def title
  @code
end