Class: Glossync::MissingTranslationHandler::GoogleTranslate
- Inherits:
-
Object
- Object
- Glossync::MissingTranslationHandler::GoogleTranslate
- Defined in:
- lib/glossync/missing_translation_handler.rb
Instance Method Summary collapse
- #handle(_, who, field, locale) ⇒ Object
-
#initialize(key) ⇒ GoogleTranslate
constructor
A new instance of GoogleTranslate.
- #translate(text, to) ⇒ Object
Constructor Details
#initialize(key) ⇒ GoogleTranslate
Returns a new instance of GoogleTranslate.
16 17 18 19 |
# File 'lib/glossync/missing_translation_handler.rb', line 16 def initialize(key) @api_key = key @cache = {} end |
Instance Method Details
#handle(_, who, field, locale) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/glossync/missing_translation_handler.rb', line 30 def handle(_, who, field, locale) key = who.tl_key(field) @cache[key] = translate(who[field], locale) unless @cache.key?(key) @cache[key] end |
#translate(text, to) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/glossync/missing_translation_handler.rb', line 21 def translate(text, to) EasyTranslate.translate( text, from: Glossync.[:base_locale], to: to, key: @api_key ) end |