2016-06-21 18:51:44 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
#import "RCTI18nUtil.h"
|
|
|
|
|
|
|
|
@implementation RCTI18nUtil
|
|
|
|
|
|
|
|
+ (id)sharedInstance {
|
|
|
|
static RCTI18nUtil *sharedRCTI18nUtilInstance = nil;
|
|
|
|
@synchronized(self) {
|
|
|
|
if (sharedRCTI18nUtilInstance == nil)
|
|
|
|
sharedRCTI18nUtilInstance = [self new];
|
|
|
|
}
|
|
|
|
return sharedRCTI18nUtilInstance;
|
|
|
|
}
|
|
|
|
|
2016-06-27 19:57:45 +00:00
|
|
|
// If current using language is RTL language and meanwhile set allowRTL on the JS side,
|
2016-06-25 02:32:54 +00:00
|
|
|
// the RN app will automatically have a RTL layout.
|
2016-06-21 18:51:44 +00:00
|
|
|
- (BOOL)isRTL
|
|
|
|
{
|
2016-06-27 19:57:45 +00:00
|
|
|
if ([self allowRTL] && [self isApplicationPreferredLanguageRTL]) {
|
2016-06-24 01:54:01 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2016-06-21 18:51:44 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2016-06-27 19:57:45 +00:00
|
|
|
- (BOOL)allowRTL
|
2016-06-21 18:51:44 +00:00
|
|
|
{
|
|
|
|
BOOL rtlStatus = [[NSUserDefaults standardUserDefaults]
|
2016-06-27 19:57:45 +00:00
|
|
|
boolForKey:@"RCTI18nUtil_allowRTL"];
|
2016-06-21 18:51:44 +00:00
|
|
|
return rtlStatus;
|
|
|
|
}
|
|
|
|
|
2016-06-27 19:57:45 +00:00
|
|
|
- (void)setAllowRTL:(BOOL)rtlStatus
|
2016-06-21 18:51:44 +00:00
|
|
|
{
|
2016-06-27 19:57:45 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_allowRTL"];
|
2016-06-21 18:51:44 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
}
|
|
|
|
|
2016-06-25 02:32:54 +00:00
|
|
|
// Check if the current device language is RTL
|
2016-06-24 01:54:01 +00:00
|
|
|
- (BOOL)isDevicePreferredLanguageRTL
|
|
|
|
{
|
|
|
|
NSLocaleLanguageDirection direction = [NSLocale characterDirectionForLanguage:[[NSLocale preferredLanguages] objectAtIndex:0]];
|
|
|
|
return direction == NSLocaleLanguageDirectionRightToLeft;
|
|
|
|
}
|
|
|
|
|
2016-06-25 02:32:54 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2016-06-21 18:51:44 +00:00
|
|
|
@end
|