Forked from ariok/[Localization]ForceFallbackLanguage.m
Created
February 21, 2016 16:56
-
-
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 :) )
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
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