ihower / i18n_google_translate

Google translate powered backend for Rails-2.2 i18n

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rails i18n Google Translate Backend

I18n is not painful anymore. Let’s google translate help you do it.

Install

    sudo gem install htmlentities
    sudo gem install json
    script/plugin install git://github.com/ihower/i18n_google_translate.git

Usage Example

environment.rb

    I18n.backend = I18n::Backend::GoogleTranslate.new
    I18n.default_locale = 'en' # your source language
    LOCALES_AVAILABLE = I18n::Backend::GoogleTranslate::GOOGLE_LANGUAGES.map.sort

application.rb

  before_filter :set_locale

  def set_locale
    session[:locale] = params[:locale] if params[:locale]
    I18n.locale = session[:locale] || I18n.default_locale
  end

view example

  <%= I18n.t "Login" %>
  <%= I18n.l Time.now %>
  
  <% form_tag '', :method => :get do %>
    <%= select_tag("locale", options_for_select(LOCALES_AVAILABLE, I18n.locale), { :index => nil, :onchange => 'this.form.submit()'}) %>
  <% end %>

Author & License

About

Google translate powered backend for Rails-2.2 i18n


Languages

Language:Ruby 100.0%