Coming from FastGettext
If you are currently using FastGettext and/or gettexti18nrails to translate your Rails application and you would like to switch to Translation.io, this article will help you with the process of updating your codebase to make it work.
If you are not sure what you are doing, consider working in branch :-)
Gemfile should only contain the
translation gem for all environments :
Make sure to remove any references to other gems like :
gem 'gettext_i18n_rails' gem 'gettext', :require => false gem 'ruby_parser', :require => false gem 'gettext'
You don't have to include
translation already depends
on its right version and will therefore include it for you.
You probably have a
fast_gettext.rb or a
gettext.rb initializer file
containing this kind of configuration :
FastGettext.add_text_domain 'app', :path => 'config/gettext_locales', :type => :po FastGettext.default_available_locales = ['en', 'fr', 'de', 'nl'] FastGettext.default_text_domain = 'app'
You won't of course need it anymore.
When you create a project on
Translation.io, you will be
asked to create an initializer named
TranslationIO.configure do |config| config.api_key = 'xxxxxxxxxxxxxxxxxxxxxxxx' config.source_locale = 'en' config.target_locales = ['fr', 'de', 'nl'] # Uncomment this if you don't want to use gettext # config.disable_gettext = true # Uncomment this if you already use gettext or fast_gettext # config.locales_path = File.join('path', 'to', 'gettext_locale') end
There you have to correclty set
config.target_locales to the former
It is very likely that your existing POT/PO files are not in
config/locales/gettext. In that case, just move them there (keeping
the right structure) or set
config.locales_path to the correct base
location used by
Translation.io only supports
textdomain named app. If you were using multiple
textdomains, you will have to merge them. If your domain was not
named app you will have to rename all the PO/POT files to app.xx.
Controllers and before filter
You probably have a
before_action somewhere in your controller
hierarchy to set the current locale (
I18n.locale) according to the
URL, the session, a cookie, etc.
translation ships with a
that can be called directly from all
ActionController::Base descendants :
But you can of course continue to use your own method if you need custom behaviour by defining it. For instance :
before_action :set_locale def set_locale I18n.locale = current_user.locale || I18n.default_locale end