Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shortcuts for localisation #35

Open
benilovj opened this issue Oct 16, 2011 · 1 comment
Open

shortcuts for localisation #35

benilovj opened this issue Oct 16, 2011 · 1 comment

Comments

@benilovj
Copy link
Member

Currently, in order to internationalise the menus of the app i'm doing, I have the following in the menu.rb file:

module I18n
  def self.t key
    NSBundle.mainBundle.localizedStringForKey(key, value: nil, table: nil)
  end
end

module HotCocoa
  def application_menu
    menu do |main|
      main.submenu :apple do |apple|
        apple.item :about, title: I18n.t("apple:about")
        ...
      end
    end
  end
end

("apple:about" then references values in the Localizable.strings files for each country, yadda yadda)

I think it might be useful for hotcocoa to have certain localisation shortcuts built-in, especially since the NSLocalizedString macro (http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/macro/NSLocalizedString) doesn't appear to work in MacRuby.

I was thinking of having something like this (ahem, 'inspired' by http://guides.rubyonrails.org/i18n.html#the-public-i18n-api):

module I18n
  class << self    
    def translate key, fallback: fallback
      NSBundle.mainBundle.localizedStringForKey(key, value: fallback, table: nil)
    end
    alias_method "t:fallback", "translate:fallback"

    def translate key
      translate key, fallback: nil
    end
    alias_method :t, :translate
  end
end

What would also be neat is to not have to always put I18n in front, but I don't know the innards of hotcocoa well enough yet to accomplish that.

Anyway,

  1. Do you think that this is a good candidate for inclusion into hotcocoa?
  2. If so, how is it best accomplished technically?
@ferrous26
Copy link
Member

Sounds good. If you wanted to drop the I18n part, you could create a mapping for the I18n class that you wrote; however, I'm not sure use of the I18n class is complicated enough to warrant a mapping.

Perhaps just using #extend in the class that implements the app would be enough, just like how apps include HotCocoa right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants