jbasdf / babelphish

Translate your yaml files using Google Translate

This URL has Read+Write access

jbasdf (author)
Wed Dec 16 10:54:09 -0800 2009
commit  35d68e8c329301f627ea276aa2ca08fa51cf1637
tree    e8063a29f0be778be1cd77bd6e58b3cc1ff6c9d9
parent  ad442079cf3add6e5b2176a9f5de86d0efc035ba
name age message
file .gitignore Sat Jul 04 00:47:15 -0700 2009 setup gitignore [jbasdf]
file LICENSE Tue Oct 27 15:20:23 -0700 2009 switched to jeweler [jbasdf]
file README.rdoc Sat Aug 15 09:48:58 -0700 2009 added ability to specifiy languages to translat... [jbasdf]
file Rakefile Wed Dec 16 10:54:09 -0800 2009 added dependency [jbasdf]
file VERSION Wed Dec 16 10:52:34 -0800 2009 Version bump to 0.2.7 [jbasdf]
file babelphish.gemspec Wed Dec 16 10:54:09 -0800 2009 added dependency [jbasdf]
directory bin/ Sat Aug 15 09:48:58 -0700 2009 added ability to specifiy languages to translat... [jbasdf]
directory config/ Sat May 30 16:34:02 -0700 2009 added basic website for rubyforge [jbasdf]
directory doc/ Sat Aug 15 11:03:36 -0700 2009 released gem [jbasdf]
directory lib/ Thu Nov 12 14:52:56 -0800 2009 Released new gem [jbasdf]
directory script/ Sat May 30 16:34:02 -0700 2009 added basic website for rubyforge [jbasdf]
directory test/ Sat Aug 15 10:59:27 -0700 2009 fixed regex used for string substitutions in ym... [jbasdf]
README.rdoc

babelphish

DESCRIPTION:

babelphish makes it simple to translate you yaml files into all the languages supported by Google Translate

USAGE:

Translate the en.yml file into all supported languages:

  babelphish -y ./my/locales/en.yml

Translate the en.yml file into all supported languages and overwrite other yml files:

  babelphish -y ./my/locales/en.yml -o

Using in your application

Babelphish can be used to translate content programmatically within your application. Use it thus:

Translate content into a single language:

  from = 'en'
  to = 'es'
  translation = Babelphish::Translator.translate('hello world', to, from)

Translate content into all supported languages at once. This will return a hash table with the locale as keys (ie ‘en’, ‘es’, etc).

  translations = Babelphish::Translator.multiple_translate('hello world', Babelphish::GoogleTranslate::LANGUAGES, self.locale)

Here’s a more extensive example

  # Translate title and body using Google
  def translate()
    translate_from_locale = 'en'
    title_translations = Babelphish::Translator.multiple_translate(self.title, Babelphish::GoogleTranslate::LANGUAGES, translate_from_locale)
    body_translations = Babelphish::Translator.multiple_translate(self.body, Babelphish::GoogleTranslate::LANGUAGES, translate_from_locale)

    Babelphish::GoogleTranslate::LANGUAGES.each do |language|
      self.content_translations.create!(:title => title_translations[language],
                                        :body => body_translations[language],
                                        :locale => language)
      end
    end
  end

INSTALL:

ya2yaml should be automatically installed when you install babelphish, but is isn’t:

  • sudo gem install ya2yaml
  • sudo gem install babelphish

Related Blog Posts

www.justinball.com/2009/05/19/babelphish-yml-translation-made-simple/

Language Codes:

AFRIKAANS = ‘af’ ALBANIAN = ‘sq’ AMHARIC = ‘am’ ARABIC = ‘ar’ ARMENIAN = ‘hy’ AZERBAIJANI = ‘az’ BASQUE = ‘eu’ BELARUSIAN = ‘be’ BENGALI = ‘bn’ BIHARI = ‘bh’ BULGARIAN = ‘bg’ BURMESE = ‘my’ CATALAN = ‘ca’ CHEROKEE = ‘chr’ CHINESE = ‘zh’ CHINESE_SIMPLIFIED = ‘zh-CN’ CHINESE_TRADITIONAL = ‘zh-TW’ CROATIAN = ‘hr’ CZECH = ‘cs’ DANISH = ‘da’ DHIVEHI = ‘dv’ DUTCH = ‘nl’ ENGLISH = ‘en’ ESPERANTO = ‘eo’ ESTONIAN = ‘et’ FILIPINO = ‘tl’ FINNISH = ‘fi’ FRENCH = ‘fr’ GALICIAN = ‘gl’ GEORGIAN = ‘ka’ GERMAN = ‘de’ GREEK = ‘el’ GUARANI = ‘gn’ GUJARATI = ‘gu’ HEBREW = ‘iw’ HINDI = ‘hi’ HUNGARIAN = ‘hu’ ICELANDIC = ‘is’ INDONESIAN = ‘id’ INUKTITUT = ‘iu’ ITALIAN = ‘it’ JAPANESE = ‘ja’ KANNADA = ‘kn’ KAZAKH = ‘kk’ KHMER = ‘km’ KOREAN = ‘ko’ KURDISH = ‘ku’ KYRGYZ = ‘ky’ LAOTHIAN = ‘lo’ LATVIAN = ‘lv’ LITHUANIAN = ‘lt’ MACEDONIAN = ‘mk’ MALAY = ‘ms’ MALAYALAM = ‘ml’ MALTESE = ‘mt’ MARATHI = ‘mr’ MONGOLIAN = ‘mn’ NEPALI = ‘ne’ NORWEGIAN = ‘no’ ORIYA = ‘or’ PASHTO = ‘ps’ PERSIAN = ‘fa’ POLISH = ‘pl’ PORTUGUESE = ‘pt-PT’ PUNJABI = ‘pa’ ROMANIAN = ‘ro’ RUSSIAN = ‘ru’ SANSKRIT = ‘sa’ SERBIAN = ‘sr’ SINDHI = ‘sd’ SINHALESE = ‘si’ SLOVAK = ‘sk’ SLOVENIAN = ‘sl’ SPANISH = ‘es’ SWAHILI = ‘sw’ SWEDISH = ‘sv’ TAJIK = ‘tg’ TAMIL = ‘ta’ TAGALOG = ‘tl’ TELUGU = ‘te’ THAI = ‘th’ TIBETAN = ‘bo’ TURKISH = ‘tr’ UKRAINIAN = ‘uk’ URDU = ‘ur’ UZBEK = ‘uz’ UIGHUR = ‘ug’ VIETNAMESE = ‘vi’

LICENSE:

(The MIT License)

Copyright © 2009 Justin Ball

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.