1

I've got an iOS app where I need to use the same resources for the en_NZ (New Zealand) localization as the en_AU (Australian) localization.

Instead of duplicating my resource files is there a way I can make it so if somebody with a locale of en_NZ uses the app it will default to the en_AU resources?

SomeGuy
  • 9,670
  • 3
  • 32
  • 35

2 Answers2

1

Try this:

1) Get lang

    NSUserDefaults* apple_defaults = [NSUserDefaults standardUserDefaults]; 
    NSArray* languagesList = [apple_defaults objectForKey: @"AppleLanguages"];
    NSString* lang = [languagesList objectAtIndex: 0];

2) Then convert him

    if ([lang isEqualToString:@"en_NZ"])
    {
        lang = @"en_AU";
    }

And you can use lang for your app as en_AU instead en_NZ

CReaTuS
  • 2,593
  • 1
  • 19
  • 31
0

You can use the following approach:
1) Create en_AU resources

2) check if your current locale is en_NZ

NSString *currentLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];
// or 
NSString *langID = [[NSLocale preferredLanguages] objectAtIndex:0];
NSString *lang = [[NSLocale currentLocale] displayNameForKey:NSLocaleLanguageCode value:langID];

NSBundle *xBundle; 

3) in case en_NZ:

// find the path to the bundle based on the locale
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings" inDirectory:nil forLocalization:@"en_AU"];

// load it!
xBundle = [[NSBundle alloc] initWithPath:[bundlePath stringByDeletingLastPathComponent]];

4) in case other than en_NZ:

xBundle = nil;

5) use in your code:

NSLocalizedStringFromTableInBundle(@"yourStr2Localize", nil, xBundle, nil);     
ra.
  • 1,798
  • 14
  • 15