Skip to content
This repository has been archived by the owner on Mar 19, 2023. It is now read-only.

laurynas/globalize3_translator

Repository files navigation

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

About

Globalize3 auto-translator using Google Translate (or any other backend)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages