Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alemar11/92729c3148889d65fca8 to your computer and use it in GitHub Desktop.
Save alemar11/92729c3148889d65fca8 to your computer and use it in GitHub Desktop.
Force the translation to a defined language. (I use this function to force the fallback language to Italian. I didn't find a way to make NSLocalizedString work with italian as fallback. your comments/suggestions are welcome :) )
NSString * L(NSString * translation_key, NSString * lang) {
NSString * s = NSLocalizedString(translation_key, nil);
// Force translation as "Lang" language if no translations are found
if ([s isEqualToString:translation_key]) {
NSString * path = [[NSBundle mainBundle] pathForResource:lang ofType:@"lproj"];
NSBundle * languageBundle = [NSBundle bundleWithPath:path];
s = [languageBundle localizedStringForKey:translation_key value:@"" table:nil];
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment