This guide will lead you through the integration of Phrase into your Ruby on Rails application.
Rails Phrase Setup for Ruby I18n
- Install the Phrase command line client
- phrase init
- phrase push
- phrase pull
Note: This guide assumes you have signed up for a Phrase account and set up your first project. See the getting started guide for more information.
1. Install the Phrase command line client
2. Configure the command line tool for your project
To initialize the project configuration, just follow the instructions to initialize the Phrase command line tool:
$ phrase init
This will guide you through the necessary steps to configure your sources and targets for your project. Make sure you select yml as your locale file format.
3. Upload locale files
Assuming you have stored your existing localization files in the default location at ./config/locales uploading your data to Phrase is easy. Just execute the push command:
$ phrase push
All existing localization files found in your source path will be uploaded to your Phrase project. Log into Translation Center to see your existing translations and add new languages or keys.
4. Download locale files
Once you have finished working on your translation in Translation Center or the In-Context Editor, you might want to download the data back into your project. This can be done by executing the pull command:
$ phrase pull
Optional: Add your custom locale download directory to your i18n load path
If you downloaded your localization files to a folder other than ./config/locales you might need to configure the i18n load path of your application so that the new localization files can be accessed. To do so, open the application.rb or development/staging/production.rb and add the configuration:
config.i18n.load_path += Dir[Rails.root.join('custom', 'locales', '**', '*.yml').to_s]
This assumes you downloaded the localization files to ./custom/locales.
After restarting your application, the new files you downloaded from Phrase should be visible in your application.
Optional: Install the phraseapp-ruby gem
If you want to write your own workflow using the Phrase API, you can use our phraseapp-ruby gem.
Add the phraseapp-ruby gem to your application by adding it to your Gemfile:
group :staging, :development do
and install it using the bundle command:
$ bundle install
Where to go from here?
Working with Phrase
Learn how to work efficiently with Phrase in this getting started guide.
Enable In-Context Editor
When localizing a web application we recommend using the In-Context Editor. See this guide for installation instructions: In-Context-Editor Documentation