Last active
October 12, 2015 20:58
-
-
Save HHuckebein/4086341 to your computer and use it in GitHub Desktop.
Provide localized content for languages not supported by iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Globals.h | |
// | |
// Created by Rabe Bernd on 03.04.12. | |
// Copyright (c) 2012 RABE_IT Services. All rights reserved. | |
// | |
#ifdef __OBJC__ | |
NSString *CustomLocalized(NSString *stringToken); | |
NSBundle *yourBundle(void); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Globals.m | |
// | |
// Created by Rabe Bernd on 03.04.12. | |
// Copyright (c) 2012 RABE_IT Services. All rights reserved. | |
// | |
#import "Globals.h" | |
NSBundle *yourBundle(void) { | |
static NSBundle* bundle = nil; | |
if (!bundle) { | |
NSString* path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:kYourBundleName]; | |
bundle = [NSBundle bundleWithPath:path]; | |
// gives preference to locale setting | |
// thus supports languages not selectable in iOS | |
NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier]; | |
if ([[bundle localizations] containsObject:localeIdentifier]) | |
{ | |
path = [bundle pathForResource:localeIdentifier ofType:@"lproj"]; | |
bundle = [NSBundle bundleWithPath:path]; | |
} | |
else { | |
localeIdentifier = [[localeIdentifier componentsSeparatedByString:@"-"] objectAtIndex:0]; | |
if (localeIdentifier && [[bundle localizations] containsObject:localeIdentifier]) { | |
path = [bundle pathForResource:localeIdentifier ofType:@"lproj"]; | |
bundle = [NSBundle bundleWithPath:path]; | |
} | |
} | |
} | |
return bundle; | |
} | |
NSString *CustomLocalized(NSString *stringToken) { | |
if (yourBundle()) { | |
return NSLocalizedStringFromTableInBundle(stringToken, @"TableName", yourBundle(), @""); | |
} else { | |
return stringToken; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment