Localize RubyMotion Projects with PhraseApp

Summary

This guide describes how to set up your first project as well how to setup and configure the PhraseApp RubyMotion gem.


TL;DR

  1. Add Project in PhraseApp
  2. Setup PhraseApp Rubymotion gem
  3. Browse RubyMotion app to upload new keys and translations

General

RubyMotion is a toolchain for iOS, OS X and Android development that lets you create iPhone, iPad, Mac and Android apps in Ruby.

Our phraseapp-rubymotion gem lets you connect your RubyMotion application to PhraseApp and benefit from the best internationalization workflow for your (iOS) projects.

Installing the gem

Add the phraseapp-rubymotion gem to your project using bundler:

gem 'phraseapp-rubymotion'

or manually:

$ gem install phraseapp-rubymotion

and require it in your Rakefile.

Initialize your project

Let’s tell PhraseApp a little bit about the app we’re building. Add the Access Token and Project ID to your application’s Rakefile:

Motion::Project::App.setup do |app|
  app.name = "Test Application"
  app.development do
    app.phraseapp do
      app.phraseapp.enabled = true
      app.phraseapp.access_token = "YOUR_ACCESS_TOKEN"
      app.phraseapp.project_id = "YOUR_PROJECT_ID"
    end
  end
end

You will find the Project ID in your project settings and you can generate Access Tokens in your profile settings.

This will automatically create the phraseapp_config.rb configuration file in your app folder during every build process.

Please make sure that you only enable PhraseApp in development mode and never in release mode!

Usage

Using PhraseApp with phraseapp-rubymotion lets you send new translations to the PhraseApp API automatically without having to write them into your Localizable.strings file or uploading them - just by browsing the app.

Localizing Strings

The first step towards a localized app is to localize all strings by extending them with their localized counterparts. This can be done by simply calling the #__ method on each string that is implemented by phraseapp-rubymotion:

"Hello World"

now becomes:

"Hello World".__

or (when using a fallback translation):

"Hello World".__("My fallback translation")

Of course you can use more generic names for your keys as well, such as:

"HOME_WELCOME_BUTTON_LABEL".__

Learn more about localization in iOS

API communication

Simply build and run your app (in the simulator). When in development mode, phraseapp-rubymotion will send all of your localized strings to PhraseApp automatically! Log into your PhraseApp account and check your newly created keys. If you already have your localization files in the correct place, it will transmit translations as well.

When all of your translations are completed in PhraseApp, it’s time to bundle them with your app. You can fetch all translations from the API and store them in our RubyMotion project by using our command line client.

1. Install the PhraseApp command line client

Download the latest PhraseApp Client and follow the setup instructions.

2. Configure the command line tool for your project

To initialize the project configuration, just follow the instructions to initialize the PhraseApp command line tool:

$ phraseapp init

This will guide you through the necessary steps to configure your sources and targets for your project. Make sure you select strings as your locale file format.

3. Download locale files

Once you have finished working on your translation in Translation Center you might want to download the data back into your project. This can be done by executing the pull command:

$ phraseapp pull

Optional: Upload locale files

Besides adding translations magically through browsing the app, you can of course also upload your existing locale files to PhraseApp. Just execute the push command:

$ phraseapp push

All existing locale files will be uploaded to your PhraseApp project. Log into Translation Center to see your existing translations and add new languages or keys.


Further reading