Ruby on Rails

This guide provides a step by step tutorial on how to integrate the Translation Exchange SDK with your Rails based web applications and allow you to translate your site into multiple languages.

Before Getting Started

Make sure you have a Translation Exchange account, and have created a project in your dashboard.

1. Install the SDK

Add the following gem to your app's Gemfile:

gem 'tml-rails'  

And make sure to install it by running:

bundle install  

2. Configure the SDK

Create a new tml initializer file in config/initializers/tml.rb with the following configuration:

Tml.configure do |config|  
  config.application = {
  config.cache = {  
    :enabled    => true,
    :adapter    => 'rails'

For the best performance, translations should be cached in your application. Multiple cache adapters are supported.

To learn more about configuring the SDK, go to the Rails Configuration section of the docs.

3. Add the Translation Exchange Script

Copy and paste the following code between the <head> and </head> tags of your layout file(s).

<%= tml_scripts_tag %>  

Use the following code anywhere on your page to add a language selector. Optionally, you can pass the type of selector you want.

<%= tml_language_selector_tag(:default) %>  

There are a few language selectors to choose from. You can view all the available selectors or learn how to create your own in the Language Selectors section of the docs.

4. Mark Up Your Content

<%= tr("Hello World") %>  
# Hello World

<%= tr("You have {count || message}", count: 5) %>  
# You have 5 messages

<%= tr("{user} sent {target} [bold: {count || gift}]", user: current_user, target: target_user, count: 5) %>  
# Michael sent Anna 5 gifts

<%= tr("{user} uploaded [bold: {count || photo}] to {actor | his, her} album.", user: current_user, count: 1) %>  
# Michael uploaded 1 photo to his album.

Learn more about marking up your content in the Translation Markup section of the docs

5. Activate Translation Mode

Once the script has been added to your layout you can start using translation mode. To activate translation mode, press CTRL+Shift+i on your keyboard.

Once translation mode has been activated, the content of your application will be synchronized with Translation Exchange and your strings will appear in your Dashboard.

Make sure to browse your entire application while in translation mode to ensure that all your content gets sent to the Translation Exchange service.

Now that your strings have been synchronized, you can start translating. Go to the Translation Options section of the docs to learn more about the different ways your content can be translated.

Make sure to Publish your translations so that they can be seen by your users.