Translation Center Status
Translation Center is a multi lingual web engine for Rails 3 apps. It builds a translation center community with translators and admins from your system users.
Translation Center can be used by:
Contribute in translating your app in different locales using easy web interface.
Avoid updating many yaml files as you will just use the easy web interface to manage translations.
Manage all app translations; collect stats, accept, add, edit, remove translations...etc
- Different roles: translators and admins
- Add new locales easily
- Support right-to-left and left-to-right translations
- Detect new translation keys in code and store them in DB for users to translate
- Inspect translation keys from your application view directly
- Import and Export translations in yaml format
- Switch translations backend between DB and yaml
- Admin dashboard for languages status and activity
- Users can vote up translations
- Default translation in English for keys
TranslationCenter works with Rails 3.1 onwards. You can add it to your Gemfile with:
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: name: 'English' direction: 'ltr' ar: name: 'Arabic' direction: 'rtl' de: name: 'German' direction: 'ltr'
if you don't supply languages for the generator it will support only English.
And run the migrations
And then run this rake to get all current translations to the db
In your User model or any other model that should acts as a translator add the following line:
In routes file add
mount TranslationCenter::Engine => "/translation_center"
By default, all users are admins, you 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 == 'firstname.lastname@example.org' end
How to use
Add new key to your views, for example:
When you visit the page where this key is rendered, a new translation key will be stored with name 'index.title' under category 'posts'. You then visit the TranslationCenter and translate the key (by default translations added by admins are considered accepted).
To migrate translations from TranslationCenter database to yaml files
To migrate translations from yaml files to TranslationCenter database
If you want to export or import just one locale, provide the locale as an attribute to the rakes, for example:
Or you could use the Controls section in the Dashboard page to run these rakes
Imported translations should have a translator. You can edit translator identifier (usually email address) in
translation_center.yml The rake task
yaml2db will create this user if it doesn't exist.
The imported translations status will be accepted by default. If you want to disable this, comment the following line in
You can control the translations source by changing the value of
i18n_source: 'yaml' # can be db or yaml; default is yaml
If your application doesn't use devise for authentication then you have to
provide helper named
current_user that returns the current user in the session and a before_filter named
authenticate_user! that redirects a user
to login page if not already signed in.
You also need to add these methods in an initialize, for example
class ApplicationController < ActionController::Base
# current_user is needed in views helper_method :current_user def authenticate_user! # redirect to login if user not signed in end def current_user # write code that returns the current user in session end
Translation Center assumes that the translator model (for example
User) has an
User model has no
identifier_type in your
translation_center.yml to a unique attribute of your translator model (
User), for example to use username instead of email:
identifier_type: 'username' # Uncomment and change the identifier if your User model has no email attribute
Another nice option is the inspector that allows the users to go directly to the key from your application view.
inspector option in
all if you want to inspect all keys otherwise set it to
missing to inspect only untranslated keys, and then add this line to your
*= require translation_center/inspector
and this line to your
//= require translation_center/inspector
Now when you reload your page you will see a small icon beside your keys.
In the previous image, if you click on the icon of 'Betrachten', you will be directed to the key page, where you can add/edit translations directly.
Add new language
If you want to add a language to the translation center, you need to run the generator:
rails g 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'
When you visit
/translation_center you will see the list of all categories and how many keys they have.
Click on category to view all the keys, keys are divided into untranslated (has no translations), pending (has translations but not approved yet), translated (has accepted translations)
Click on a key to view all translations for that key, then you can add or edit your translation for that key, users can also vote for translations.
As an admin you can accept pending translations that have been added by other users, you can also edit and remove keys.
Admin also can view the dashboard to know the status of every language
or monitor activity of changes to translations.
We have added translation_center to the Tracks app:
You can play with the demo here: http://translation-center.herokuapp.com/translation_center/
Visit the Tracks app at http://translation-center.herokuapp.com
Translation Center is maintained and developed by BadrIT
Help us make this engine better by submitting any bugs or enhancments in the issues page for this project. We also added an error page that will appear to you if any error goes with translation_center.