Class: I27r::Translator

Inherits:
Object
  • Object
show all
Includes:
BabelFish
Defined in:
lib/generators/i18n/translation/lib/translator.rb

Instance Method Summary collapse

Methods included from BabelFish

#_translate

Constructor Details

#initialize(lang) ⇒ Translator

Returns a new instance of Translator.



39
40
41
# File 'lib/generators/i18n/translation/lib/translator.rb', line 39

def initialize(lang)
  @lang, @cache = lang, {}
end

Instance Method Details

#translate(word) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/i18n/translation/lib/translator.rb', line 43

def translate(word)
  return @cache[word] if @cache[word]

  translated = _translate word, @lang
  if translated.blank? || (translated == word)
    word
  else
    @cache[word] = translated
    translated
  end
rescue => e
  Rails.logger.debug e
  puts %Q[failed to translate "#{word}" into "#{@lang}" language.]
  word
end