RubyMotion Blog


This is the official blog of RubyMotion, a toolchain for iOS, OS X and Android development that lets you do iPhone, iPad, Mac and Android apps in Ruby.

Follow us on Twitter to stay tuned with everything that's happening in the community!

Not a RubyMotion user yet? Give it a spin today!

MotionPhrase: Next Level Localization for RubyMotion Applications

(This is a guest post from Manuel Boy, lead developer of PhraseApp)

As the team behind PhraseApp we work really hard to make internationalization of web and mobile applications less painful. Especially when building iOS apps developers typically spend a lot of time managing localization files, entering new translations and sending translations back and forth. At the same time, localizing an app becomes more and more essential for the success of a mobile software project as translated user interfaces increase the reach and customer satisfaction of those apps.

Multi-language iOS apps

Localizing an iOS application sounds simple: Just replace all occurences of NSString with NSLocalizedString, copy all translations into text files (or let some tool generate them for you) and keep all of your Localizable.strings files in order.

But this can get quite tedious and difficult when you are dealing with larger apps, lots of languages and frequent updates. After all, no developer likes managing translations in text files, constantly changing texts and translations for their clients or dealing with corrupted files caused by a missing semicolon. Instead they would like to focus on the actual development of beautiful user interfaces and the app’s business logic.

This is where PhraseApp shines. Clients, translators and managers edit their translations in the web-based editor. And developers just get their valid translation files directly from the API via a command line tool. Happy Developers!

Adding the gem

To get started, you need to sign up for a (free) account with PhraseApp. A wizard will guide you through the first steps of the registration process. You can skip the wizard after you have selected the locales for your project since we will add all translation resources later without any effort at all. Instead, grab the auth token from the PhraseApp project you have just created. You find your auth token on the project overview page.

Next, add the motion-phrase gem to your project using bundler:

gem 'motion-phrase'

or manually:

$ gem install motion-phrase

and require it in your Rakefile.

Initializing your project

Now, let’s tell PhraseApp a little bit about the app we’re building. With a simple rake task we will tell PhraseApp that we want to connect our RubyMotion project to the service:

$ rake phrase:init AUTH_TOKEN=YOUR_AUTH_TOKEN

Let’s add the auth token to the app’s Rakefile as well and enable the service in development mode only:

Motion::Project::App.setup do |app| = "MyApplication"

  app.development do
    app.phrase do
      app.phrase.enabled = true
      app.phrase.auth_token = "YOUR_AUTH_TOKEN"

Strings go global!

We have to tell the strings in our app that they should be translatable into other languages. Fortunately, this can easily be done by calling the #.__ method on the String/NSString class that is implemented by motion-phrase:

"Hello World"

now becomes:

"Hello World".__

Call that method on every string in your app that requires to be localized.

Talking to PhraseApp

When you start your app in the simulator motion-phrase automatically sends all strings (and all translations that are found in your Localizable.strings files) to PhraseApp. All you have to do is to browse the views that contain localizable strings. As soon as they are accessed, PhraseApp knows about them and allows your team to translate them within the web editor.

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 simply by using the following rake command:

$ rake phrase:pull

It will download valid localization files and create a LANGUAGE-NAME.lproj folder for each locale that contains a Localizable.strings file with all the translations you have stored in PhraseApp.

If you already own completed translation files, it would be a good idea to tell PhraseApp about them:

$ rake phrase:push

This will upload all Localizable.strings files inside your resources folder to your PhraseApp project. A good way to get started quickly if you already have some translations in your project that you want to keep.

Your app is now officially localized ;-)

More Information

Read some more detailed instructions in the README.

About PhraseApp

PhraseApp speeds up the translation of web- and mobile applications. The cloud-service is developed by the engineers of Dynport GmbH, located in Hamburg, Germany.

PhraseApp is free for small and open source projects.


Interested in giving RubyMotion a try? We offer a 30 days money back guarantee. Download it today!
Follow us on Twitter to stay tuned with everything that is happening in the community.

By Laurent Sansonetti.