Reputation: 66505
I think it's not possible to use I18n, so what's the best approach?
From what I see you can use Bubblewrap as so:
# Localization (using NSBundle.mainBundle.localizedStringForKey):
BubbleWrap.localized_string(:foo, 'fallback')
=> "fallback"
But there is no explanations on how to setup the translation keys and is just a mapping of:
NSBundle.mainBundle.localizedStringForKey(key, value:value, table:nil)
... so I'm not sure what to do with it.
Bubblewrap also provides a App.current_locale
method, but this returns an object that seems unusable as far as I can understand.
So, how can I localize my RubyMotion application, or at least get the user's locale to create my own localization system.
Upvotes: 3
Views: 745
Reputation: 10796
I18n is now available to Rubymotion with this wrapper gem: motion-i18n.
Upvotes: 0
Reputation: 356
The way to use it is beatifully explained in colinta's blogpost.
There's also GitHub gist by chsh that shows a reasonable example.
But to answer in detail:
Create resources/en.lproj/Localizable.strings
with content:
/* This is a sample greeting for my app */
"GREETING" = "Hello World!";
(and similarly for other languages: cs.lproj
, de.lproj
, ...).
Then you can use sugarcube's localized support: "HELLO"._
which will result in "Hello World!"
for en
locale and GREETING
for any locale with corresponding lproj
file missing. You can find more detail in sugarcube's docs linked above.
You could most likely also use the BubbleWrap's localized_string support: BW.localized_string("GREETING", "fallback")
. I can't vouch for it as I haven't tested it myself, though.
Upvotes: 1
Reputation: 90
We have just released motion-phrase a gem for RubyMotion that implements a localization workflow using PhraseApp. It is a quite different approach but comes with a lot of advantages.
Upvotes: -2
Reputation: 1499
RubyMotion use CocoaTouch API. You can check apple documentation on localization https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html
Upvotes: 2