Rails-style translations for RubyMotion apps.
This gem allows you to specify your RubyMotion translations as .yml files. The translations are automatically converted to Cocoa's native format for translations.
gem install motion-i18n
and in your Rakefile:
require 'motion-i18n'or using bundler:
gem "motion-i18n"Put your translations in YAML files in config/locales/. For each locale there should be a file named as the locale with the extension .yml, e.g. en.yml, de.yml etc.
For a guide on how the translation files should look like, see http://guides.rubyonrails.org/i18n.html#adding-translations
To translate a string, use I18n.translate or the shortcut I18n.t like this:
I18n.t("main_screen.title")To substitute variables in the string, specify the substitutions in second a hash argument
I18n.t("maps.directions", :from => origin, :to => destination)You can get the current locale by calling
I18n.localeSetting the locale is done by changing the language settings on the mobile device or simulator. Setting the locale via code or in the Rakefile will have no effect or generate an error.
This gem works perfectly together with the i18n_tools gem:
gem install i18n_tools
or in Gemfile;
gem "i18n_tools", :require => "i18n_tools/tasks"The gem will give you the tasks rake translations:missing which shows untranslated strings as well as rake translations:unused which shows strings which are translated but not used in the code. For more information, see i18n_tools.
For each locale loc, this gem overwrites the file resources/loc.lproj/Localizable.strings before building. Make sure you don't edit this file. Also, you should add these files to .gitignore:
Localizable.strings
Feel free to fork and submit pull requests!