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:
Родитель
d055ab548e
Коммит
0e07c36794
|
@ -22,9 +22,11 @@
|
||||||
return sharedRCTI18nUtilInstance;
|
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
|
- (BOOL)isRTL
|
||||||
{
|
{
|
||||||
if ([self forceRTL] && [self isDevicePreferredLanguageRTL]) {
|
if ([self forceRTL] && [self isApplicationPreferredLanguageRTL]) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
|
@ -43,10 +45,19 @@
|
||||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the current device language is RTL
|
||||||
- (BOOL)isDevicePreferredLanguageRTL
|
- (BOOL)isDevicePreferredLanguageRTL
|
||||||
{
|
{
|
||||||
NSLocaleLanguageDirection direction = [NSLocale characterDirectionForLanguage:[[NSLocale preferredLanguages] objectAtIndex:0]];
|
NSLocaleLanguageDirection direction = [NSLocale characterDirectionForLanguage:[[NSLocale preferredLanguages] objectAtIndex:0]];
|
||||||
return direction == NSLocaleLanguageDirectionRightToLeft;
|
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
|
@end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче