• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to ^set^ preferred localizations?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to ^set^ preferred localizations?


  • Subject: Re: How to ^set^ preferred localizations?
  • From: Douglas Davidson <email@hidden>
  • Date: Fri, 28 Mar 2008 11:16:13 -0700


On Mar 28, 2008, at 11:06 AM, Jerry Krinock wrote:

Even though I have included six .lproj/Localizable.strings directories in my framework's Resources, - localizedStringForKey:value:table: always ignores my System Preferences or MiniGlot setting and returns results from the English. From reading the remarks of Douglas Davidson,

http://www.cocoabuilder.com/archive/message/cocoa/2005/8/15/144364

I understand the problem is that Cocoa is getting its candidate localizations from my main bundle which has only English. Douglas proposes two solutions. I like the second solution better, but I don't get it.

This solution is to "use NSBundle methods to load resources in an arbitrary localization, and there is a mechanism (preferredLocalizationsFromArray:forPreferences:) to allow you to select the user's most preferred localization for any given bundle."

Huh? If I give this method an array of candidate localizations, it ^returns^ it back, pruned and reordered, showing its preferred localizations. (In my case, I get an array of one object, "English"). You see, this method is a getter. I need either a method to ^set^ these preferred localizations, or else a version of localizedStringForKey:value:table: that has a localization: argument. What am I missing?

NSBundle has methods for locating resources for a specific localization, but not one for strings. If you want a version of localizedStringForKey:value:table: that has a localization argument, you'll need to write one. It's a few lines of code, maybe something like this:


NSString *localizedString = nil;
NSString *stringsFilePath = [bundle pathForResource:tableName ofType:@"strings" inDirectory:nil forLocalization:localizationName];
if (stringsFilePath) {
NSDictionary *table = [NSDictionary dictionaryWithContentsOfFile:stringsFilePath];
if (table) localizedString = [table objectForKey:key];
}
if (!localizedString) localizedString = key;


Douglas Davidson
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How to ^set^ preferred localizations? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: cocoa http client library
  • Next by Date: Re: changing NSNumber from within another function
  • Previous by thread: How to ^set^ preferred localizations?
  • Next by thread: Core Data and NSOperation
  • Index(es):
    • Date
    • Thread