Provide function that could read app current using language

Summary: Provide function that could read the language currently used in the app, so the isRTL is using the app current using language to set isRTL.

Reviewed By: fkgozali

Differential Revision: D3480654

fbshipit-source-id: dea3ef4769296f594f7f32da2961b4fec1b99a7a
This commit is contained in:
Mengjue Wang 2016-06-24 19:32:54 -07:00 коммит произвёл Facebook Github Bot 7
Родитель d055ab548e
Коммит 0e07c36794
1 изменённых файлов: 12 добавлений и 1 удалений

Просмотреть файл

@ -22,9 +22,11 @@
return sharedRCTI18nUtilInstance;
}
// If currnent using language is RTL language and meanwhile set forceRTL on the JS side,
// the RN app will automatically have a RTL layout.
- (BOOL)isRTL
{
if ([self forceRTL] && [self isDevicePreferredLanguageRTL]) {
if ([self forceRTL] && [self isApplicationPreferredLanguageRTL]) {
return YES;
}
return NO;
@ -43,10 +45,19 @@
[[NSUserDefaults standardUserDefaults] synchronize];
}
// Check if the current device language is RTL
- (BOOL)isDevicePreferredLanguageRTL
{
NSLocaleLanguageDirection direction = [NSLocale characterDirectionForLanguage:[[NSLocale preferredLanguages] objectAtIndex:0]];
return direction == NSLocaleLanguageDirectionRightToLeft;
}
// Check if the current application language is RTL
- (BOOL)isApplicationPreferredLanguageRTL
{
NSString *preferredAppLanguage = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
NSLocaleLanguageDirection direction = [NSLocale characterDirectionForLanguage:preferredAppLanguage];
return direction == NSLocaleLanguageDirectionRightToLeft;
}
@end