Localization

372 views
Skip to first unread message

Joe

unread,
May 8, 2012, 9:54:57 AM5/8/12
to rubymotion
I tried to localize an app. Unfortunately NSLocalizedString is not
working.
Can somebody give me a short recipe on how to localize an app in
RubyMotion?

Greg Pasquariello

unread,
May 8, 2012, 9:56:02 AM5/8/12
to rubym...@googlegroups.com, rubymotion
Can you be more specific with "not working"?

Sent from my iPad

Eloy Durán

unread,
May 8, 2012, 10:04:40 AM5/8/12
to rubym...@googlegroups.com
NSLocalizedString is a macro and thus isn't available by default. Use code like the following to implement it yourself: https://github.com/foeken/CarenMotion/blob/master/app/extentions/kernel.rb#L5

Ian Phillips

unread,
May 8, 2012, 4:43:46 PM5/8/12
to rubym...@googlegroups.com
The BubbleWrap library already has a wrapper for this, see https://github.com/mattetti/BubbleWrap/blob/master/lib/kernel.rb for details.

Cheers,
Ian.

Mateus

unread,
May 9, 2012, 6:59:29 AM5/9/12
to rubym...@googlegroups.com
Has anyone tested the YAML library in Rubymotion? 
It would be nice to have a library like https://github.com/ai/r18n for Rubymotion.
Apples localization features are great, but it could be better!

someone interested to co-recreate it?

Eloy Durán

unread,
May 9, 2012, 7:16:14 AM5/9/12
to rubym...@googlegroups.com
FYI: If you’re going to take a look at making it work, be sure to check the one that comes with MacRuby, *not* the one that’s in MRI 1.9 (Psych).

Joe

unread,
May 11, 2012, 7:05:57 AM5/11/12
to rubymotion
I'm already using BubbleWrap, which is already very useful. Thanks
btw.

I added the language files in the resources folder, but it doesn't
work. Have you tested localization in your apps?

resources/English.lproj/Localizable.strings
resources/German.lproj/Localizable.strings

I also tried to name the folders en.lproj and de.lproj, with the same
result.

The Localizable.strings file have the key / value pairs as usual:
"Turn on" = "Anschalten";

The files are being added to the project, but it seems that they are
not used by the bundle.

Any ideas?

Cheers,
Joe

Aaron H

unread,
May 20, 2012, 7:41:12 PM5/20/12
to rubym...@googlegroups.com
Just doing some testing and while the fix I posted earlier for localized XIB files also takes care of including the string tables, it seems that NSLocalizedString is not implemented in RubyMotion at this point since I get a method missing error.

Laurent?

Aaron H

unread,
May 20, 2012, 7:55:46 PM5/20/12
to rubym...@googlegroups.com
OK, while the NSLocalizedString method isn't implemented, the method this calls is part of NSBundle and does get called.  So, you can get the functionality by adding this somewhere to your app.

module Kernel
  # you could name this NSLocalizedString() for compatibility's sake
  def localized_string(*args)
    key     = args.shift
    default = args.shift || key
    NSBundle.mainBundle.localizedStringForKey(key, value:default, table:nil)
  end
end

Manuel Boy

unread,
Jun 5, 2013, 11:13:28 AM6/5/13
to rubym...@googlegroups.com
We have put quite some effort in our own localization solution and provided a RubyMotion gem for it: motion-phrase 

It allows a quite sophisticated localization workflow for RubyMotion app in combination with our localization service PhraseApp. Would be great to have some other RubyMotion devs try it out :)
Message has been deleted

Bruce McTigue

unread,
Jun 6, 2013, 1:16:28 PM6/6/13
to rubym...@googlegroups.com
Hi Manuel,

Tried this today, but I'm getting an error:

2013-06-06 11:59:29.641 Pixsee[20107:c07] nsstring.rb:16:in `development?': uninitialized constant NSString::RUBYMOTION_ENV (NameError)
from nsstring.rb:4:in `_localized:'
2013-06-06 11:59:29.643 Pixsee[20107:c07] *** Terminating app due to uncaught exception 'NameError', reason: 'nsstring.rb:16:in `development?': uninitialized constant NSString::RUBYMOTION_ENV (NameError)
from nsstring.rb:4:in `_localized:'

Seems RUBYMOTION_ENV isn't defined in the development? method. Any work around?

Thanks,

Bruce

Manuel Boy

unread,
Jun 7, 2013, 4:17:49 AM6/7/13
to rubym...@googlegroups.com
Hi Bruce,

we're currently trying to figure this out. Which version of RM do you use? And can you share your Gemfile? We would love to reproduce the issue because I can't imagine why the constant should be undefined.

Thanks!
Manuel

Manuel Boy

unread,
Jun 7, 2013, 5:26:41 AM6/7/13
to rubym...@googlegroups.com
We've just released version 0.0.4 of the Gem and shifted some things around regarding the load order. Could you check and see if this version works better for you?

Please note that we have changed the configuration options a little: https://github.com/phrase/motion-phrase#configure-phraseapp

:)

Bruce McTigue

unread,
Jun 7, 2013, 11:52:16 AM6/7/13
to rubym...@googlegroups.com
Hi Manuel,

Thanks for the update. I removed the old gems and reinstalled with 0.0.4. I did get through the init fine and the new config file is created, but there is essentially the same problem, App.delegate?, line 20 in nsstring.rb, is referencing delegate? in BubbleWrap. My version of bubble-wrap is 1.3.0. Here's the exception:

Simulate ./build/iPhoneSimulator-6.0-Development/Pixsee.app
2013-06-07 10:38:09.351 Pixsee[34193:c07] app.rb:70:in `environment': uninitialized constant BubbleWrap::App::RUBYMOTION_ENV (NameError)
from app.rb:74:in `development?'
from nsstring.rb:20:in `development?'
from nsstring.rb:16:in `phraseEnabled?'
from nsstring.rb:4:in `_localized:'
2013-06-07 10:38:09.353 Pixsee[34193:c07] *** Terminating app due to uncaught exception 'NameError', reason: 'app.rb:70:in `environment': uninitialized constant BubbleWrap::App::RUBYMOTION_ENV (NameError)
from app.rb:74:in `development?'
from nsstring.rb:20:in `development?'
from nsstring.rb:16:in `phraseEnabled?'
from nsstring.rb:4:in `_localized:'
'
*** First throw call stack:

Hope that helps.

Thanks,

Bruce

Manuel Boy

unread,
Jun 7, 2013, 12:31:38 PM6/7/13
to rubym...@googlegroups.com
That is really strange. Which version of RubyMotion do you currently use? Are you already on 2.0?

Bruce McTigue

unread,
Jun 7, 2013, 1:27:52 PM6/7/13
to rubym...@googlegroups.com
Hi Manuel,

Yeah, 2.0. I think I have a fairly vanilla RM app installation. That's why I'm trying to just do the install as I normally would. No one else having any issues?

Thanks,

Bruce

Manuel Boy

unread,
Jun 10, 2013, 6:38:08 AM6/10/13
to rubym...@googlegroups.com
Hey Bruce,

can you share your Gemfile?

Please try to add motion-phrase as the last Gem in the Gemfile. We run it successfully in multiple (vanilla) RubyMotion apps so there must be a way :)

Best regards,
Manuel

Bruce McTigue

unread,
Jun 10, 2013, 11:25:00 AM6/10/13
to rubym...@googlegroups.com
Hi Manuel,

Here ya go...

# A sample Gemfile

gem 'rake'
gem 'bubble-wrap'
gem 'sugarcube'
gem 'cocoapods', '>= 0.17.0'
gem 'motion-cocoapods', '>=1.3.0.rc1'
gem 'rubymotion_generators'
gem 'geomotion'
gem 'motion-phrase'

By the way, just upgraded to RM 2.1 and same result.

Thanks,

Bruce

Manuel Boy

unread,
Jun 10, 2013, 12:06:59 PM6/10/13
to rubym...@googlegroups.com
I've tried the exact same setup and I don't receive any errors: https://github.com/docstun/rubymotion_test

Can you reproduce it with my repository?

Bruce McTigue

unread,
Jun 13, 2013, 10:29:47 AM6/13/13
to rubym...@googlegroups.com
HI Manuel,

I can't replicate it with your repository. Afraid I'm going to have to abandon the effort. 

Thanks for the help.

Bruce

Manuel Boy

unread,
Jun 13, 2013, 10:32:23 AM6/13/13
to rubym...@googlegroups.com
Hey Bruce,

just got a message from the RubyMotion guys that they're looking at the issue you're describing and are about to fix it.

So stay tuned :)

Best regards,
Manuel
Reply all
Reply to author
Forward
0 new messages