Question

I've got an app that has all content regardless of language displaying content in English. In the products section of the app product content is displayed based on a plist. Products available for purchased are based on location, not all products are available in every market.

In the settings of my simulator I've got my language set to English and my Region Format set to Singapore.

Above my loading of the plist which has been localized, I first do a log to check that I am in fact seeing SG (Singapore) as my region.

NSString *locale = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];
NSLog(@"LOCALE: %@", locale);
if([locale isEqualToString:@"SG"]){
    NSLog(@"singapore do something?");
    productCategory = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] 
                                    pathForResource:@"Products" ofType:@"plist"]];  
}

The current result is showing my log statement logging LOCALE: SG which is expected, however my Singapore specific content is not loading.

I have tried both cleaning the project, and deleting the app from the simulator.

This is how my plist files appear in my project navigator Products.plist image

What am I doing incorrectly that is preventing my localized plist from being displayed?

Était-ce utile?

La solution

Localization (the process of loading translated resources from the relevant language folders in your application bundle) is based exclusively on the language setting. So pathForResource only cares about the language setting and ignores the region format setting.

The region format setting affects the conversion between strings and locale-dependent data types (in both directions: parsing input and formatting output). For example if you convert a NSDate to a string for display, depending on the region format setting you might get the month before the day (as in the US) or the opposite (as in the UK).

[NSLocale currentLocale] refers to the region format, so you were simply looking at the wrong thing in your debugging.

There is plenty more info on this here: https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPInternational/BPInternational.html#//apple_ref/doc/uid/10000171i

Edit See the comments below, this appears to be more complex. It looks like Region does affect localisation when the language is set to a neutral language (e.g. "en" but not "en-US").

Autres conseils

I had once the same problem, somehow a non-localized file was found. What worked for me was to use:

[[NSBundle mainBundle] pathForResource:@"Products" ofType:@"plist" inDirectory:nil]

This will always search for all localized files and return the correct one based on the users settings

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top