Repository is archived
No commit activity in last 3 years
No release in over 3 years
Globalize3 auto-translator using Google Translate (or any other backend).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Globalize3 Translator¶ ↑

  • Automatically adds missing model translations

  • Uses Google Translate by default (you can use your own backend)

  • Marks auto translated data

Installation¶ ↑

To install Globalize3 Translator use:

gem install globalize3_translator

Configuration¶ ↑

If you wish to override default configuration create config/initializers/globalize3.rb

Globalize::Translator.configure do |config|
  # automatically translate only to specified locales
  config.locales = [ :lt, :de ]

  # use custom translator backend
  config.backend = MyTranslatorBackend 
end

Identifying auto translated data with auto_translated?¶ ↑

Example:

post = Post.new :title => "Dog"
post.save!
post.reload

# should be "false" for current locale
post.title.auto_translated?

I18n.locale = :lt

# should be "true" for other locale
post.title.auto_translated?

Writing custom backend¶ ↑

Example:

class MyTranslatorBackend < Globalize::Translator::Backends::Abstract

  def translate(value, from_locale, to_locale)
    # should return translated value
    "test #{value}"          
  end

end

Migrations¶ ↑

Globalize3 Translator uses extra boolean fields in translations table to track automatic translations (with suffix ‘_auto_translated’).

Globalize3 standard method “create_translation_table!” automatically adds <name>_auto_translated fields so you don’t have to worry about that for new tables.

If you want to add auto translated fields to existing translations table, you should do it manually in migration.

Example:

add_column :post_translations, :title_auto_translated, :boolean

Patches, fixes¶ ↑

Please send all patches or fixes as github pull requests. Preferably with tests.

Copyright © 2010 Laurynas Butkus, released under the MIT license