PHP 7.4.33
Preview: RCTI18nUtil.m Size: 2.72 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/react-native/React/Modules/RCTI18nUtil.m
/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import "RCTI18nUtil.h"

#import <UIKit/UIKit.h>

@implementation RCTI18nUtil

+ (instancetype)sharedInstance
{
  static RCTI18nUtil *sharedInstance;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    sharedInstance = [self new];
    [sharedInstance swapLeftAndRightInRTL:true];
  });

  return sharedInstance;
}

/**
 * Check if the app is currently running on an RTL locale.
 * This only happens when the app:
 * - is forcing RTL layout, regardless of the active language (for development purpose)
 * - allows RTL layout when using RTL locale
 */
- (BOOL)isRTL
{
  if ([self isRTLForced]) {
    return YES;
  }
  if ([self isRTLAllowed] && [self isApplicationPreferredLanguageRTL]) {
    return YES;
  }
  return NO;
}

/**
 * Should be used very early during app start up
 * Before the bridge is initialized
 * @return whether the app allows RTL layout, default is true
 */
- (BOOL)isRTLAllowed
{
  NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"RCTI18nUtil_allowRTL"];
  if (value == nil) {
    return YES;
  }
  return [value boolValue];
}

- (void)allowRTL:(BOOL)rtlStatus
{
  [[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_allowRTL"];
  [[NSUserDefaults standardUserDefaults] synchronize];
}

/**
 * Could be used to test RTL layout with English
 * Used for development and testing purpose
 */
- (BOOL)isRTLForced
{
  BOOL rtlStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_forceRTL"];
  return rtlStatus;
}

- (void)forceRTL:(BOOL)rtlStatus
{
  [[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_forceRTL"];
  [[NSUserDefaults standardUserDefaults] synchronize];
}

- (BOOL)doLeftAndRightSwapInRTL
{
  return [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
}

- (void)swapLeftAndRightInRTL:(BOOL)value
{
  [[NSUserDefaults standardUserDefaults] setBool:value forKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
  [[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
{
  NSWritingDirection direction = [NSParagraphStyle defaultWritingDirectionForLanguage:nil];
  return direction == NSWritingDirectionRightToLeft;
}

@end

Directory Contents

Dirs: 0 × Files: 18
Name Size Perms Modified Actions
1.42 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
3.47 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
745 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.72 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.20 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
5.22 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.06 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.86 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
569 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
9.43 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.63 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
966 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
7.97 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
58.87 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
2.61 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.51 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
3.81 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
3.15 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).