Skip to content

kabdelhady/translation_center

 
 

Repository files navigation

Translation admin must extend User model and implement a boolean method named can_admin_translations?

Getting started

TranslationCenter works with Rails 3.2 onwards. You can add it to your Gemfile with:

gem 'translation_center', :git => '[email protected]:mahkhaled/translation_center.git'

Run bundle install command.

TranslationCenter depends on Devise, so make sure you installed it successfully https://github.com/plataformatec/devise#starting-with-rails

After you install TranslationCenter and add it to your Gemfile, you need to run the generator:

rails generate translation_center:install en ar de

This will add three languages to the translation center, you need to add them in the config/translation_center.yaml

development:
  lang:
    en: 'English'
    ar: 'Arabic'
    de: 'German'

if you don't supply languages for the generator it will support only English.

And run the migrations

rake db:migrate

In your User model or any other model that should acts as a translator add the following line:

acts_as_translator

In routes file add

mount TranslationCenter::Engine => "/translation_center"

You now need to define who is the translation center admin. Admin can accept translations, manage translation keys and do more things. To define your admin, you need to override User#can_admin_translations? method like the following....

def can_admin_translations?
  self.email == '[email protected]'
end

How to use

To migrate translations from TranslationCenter database to yaml files

rake translation_center:db2yaml

To migrate translations from yaml files to TranslationCenter database

rake translation_center:yaml2db

But imported translations should have translator. You can edit translator email from translation_center.yml The rake task yaml2db will create this user if not exists

yaml_translator_email: '[email protected]'

The imported translations status will be ACCEPTED by default. If you want to disable that, comment the following line in translation_center.yaml

yaml2db_translations_accepted: true

Any I18n.translate method will display translations from database ACCEPTED translations. If you want to skip database translations and set to use yaml translations, comment the following line in translation_center.yaml

i18n_source: 'db' # can be db or yaml; default is yaml

#Add new language

If you want to add a language to the translation center, you need to run the generator:

rails g migration translation_center:add_lang es fr
rake db:migrate

You will also need to add the language to config/translation_center.yml

development:
  lang:
    en: 'English'
    ar: 'Arabic'
    de: 'German'
    es: 'Espaniol'
    fr: 'French'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 51.3%
  • JavaScript 48.7%