Skip to content

Instantly share code, notes, and snippets.

@HHuckebein
Last active October 12, 2015 20:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HHuckebein/4086341 to your computer and use it in GitHub Desktop.
Save HHuckebein/4086341 to your computer and use it in GitHub Desktop.
Provide localized content for languages not supported by iOS
//
// 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
//
// 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