Class: RealTranslator

Inherits:
Translator show all
Defined in:
lib/translator.rb

Constant Summary

Constants inherited from Translator

Translator::LANG_BREAK

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Translator

default, for

Constructor Details

#initialize(locale_code) ⇒ RealTranslator

Returns a new instance of RealTranslator.



38
39
40
41
42
# File 'lib/translator.rb', line 38

def initialize(locale_code)
  md = locale_code.match(/([^-]+)(-(.*))?/)
  self.lang = md[1]
  self.locale = md[3]
end

Instance Attribute Details

#langObject

Returns the value of attribute lang.



36
37
38
# File 'lib/translator.rb', line 36

def lang
  @lang
end

#localeObject

Returns the value of attribute locale.



36
37
38
# File 'lib/translator.rb', line 36

def locale
  @locale
end

Instance Method Details

#==(other) ⇒ Object



52
53
54
55
56
# File 'lib/translator.rb', line 52

def ==(other)
  return other.kind_of?(RealLocale) &&
         lang == other.lang &&
         locale == other.locale
end

#localize(text) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/translator.rb', line 44

def localize(text)
  md = text.match(/^--- #{lang}-#{locale} ----*\s*$/)
  md = text.match(/^--- #{lang} ----*\s*$/) if md.nil?
  md = text.match(/^--- #{lang}-\S+ ----*\s*$/) if md.nil?
  return default_text_from(text) if md.nil?
  return default_text_from(md.post_match)
end