Module: ToLang

Defined in:
lib/to_lang.rb,
lib/to_lang/codemap.rb,
lib/to_lang/version.rb,
lib/to_lang/connector.rb,
lib/to_lang/translatable.rb

Overview

ToLang is a Ruby library that adds language translation methods to strings and arrays, backed by the Google Translate API.

See Also:

Author:

  • Jimmy Cuadra

Defined Under Namespace

Modules: Translatable Classes: Connector

Constant Summary collapse

CODEMAP =

A list of all the languages ToLang supports and the language code each maps to. Strings and arrays will gain to_language, to_language_from_language, and from_language_to_language methods for any language in this list.

{
  'afrikaans' => 'af',
  'albanian' => 'sq',
  'arabic' => 'ar',
  'belarusian' => 'be',
  'bulgarian' => 'bg',
  'catalan' => 'ca',
  'simplified_chinese' => 'zh-CN',
  'traditional_chinese' => 'zh-TW',
  'croatian' => 'hr',
  'czech' => 'cs',
  'danish' => 'da',
  'dutch' => 'nl',
  'english' => 'en',
  'estonian' => 'et',
  'filipino' => 'tl',
  'finnish' => 'fi',
  'french' => 'fr',
  'galician' => 'gl',
  'german' => 'de',
  'greek' => 'el',
  'haitian_creole' => 'ht',
  'hebrew' => 'iw',
  'hindi' => 'hi',
  'hungarian' => 'hu',
  'icelandic' => 'is',
  'indonesian' => 'id',
  'irish' => 'ga',
  'italian' => 'it',
  'japanese' => 'ja',
  'latvian' => 'lv',
  'lithuanian' => 'lt',
  'macedonian' => 'mk',
  'malay' => 'ms',
  'maltese' => 'mt',
  'norwegian' => 'no',
  'persian' => 'fa',
  'polish' => 'pl',
  'portuguese' => 'pt',
  'romanian' => 'ro',
  'russian' => 'ru',
  'serbian' => 'sr',
  'slovak' => 'sk',
  'slovenian' => 'sl',
  'spanish' => 'es',
  'swahili' => 'sw',
  'swedish' => 'sv',
  'thai' => 'th',
  'turkish' => 'tr',
  'ukrainian' => 'uk',
  'vietnamese' => 'vi',
  'welsh' => 'cy',
  'yiddish' => 'yi',
}
VERSION =

The current version of the Ruby gem.

"0.3.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.connectorToLang::Constructor, NilClass (readonly)

A Connector object to use for translation requests.

Returns:

  • (ToLang::Constructor, NilClass)

    An initialized connector or nil.



17
18
19
# File 'lib/to_lang.rb', line 17

def connector
  @connector
end

Class Method Details

.start(key) ⇒ Class, Boolean

Initializes ToLang, after which the translation methods will be available from strings and arrays.

Parameters:

  • key (String)

    A Google Translate API key.

Returns:

  • (Class, Boolean)

    Array if initialization succeeded, false if this method has already been called successfully.



25
26
27
28
29
30
# File 'lib/to_lang.rb', line 25

def start(key)
  return false if defined?(@connector) && !@connector.nil?
  @connector = Connector.new key
  String.send :include, Translatable
  Array.send :include, Translatable
end