react-native-localize icon indicating copy to clipboard operation
react-native-localize copied to clipboard

[iOS] Get store locale country code

Open jonluca opened this issue 5 months ago • 2 comments

Why it is needed?

It would be nice if this library exposed the iOS countryCode for the App Store, as this can change the localization of content as well.

Something like https://developer.apple.com/documentation/storekit/storefront/countrycode

Possible implementation

import Foundation
import React
import StoreKit

@objc(AppStoreRegion)
class AppStoreRegion: NSObject {
  
  @objc
  static func requiresMainQueueSetup() -> Bool {
    return false
  }
  
  @objc
  func getAppStoreRegion(_ resolve: @escaping RCTPromiseResolveBlock,
                        rejecter reject: @escaping RCTPromiseRejectBlock) {
    
    // Get the actual App Store storefront country code
    if let countryCode = SKPaymentQueue.default().storefront?.countryCode {
      resolve(countryCode)
    } else {
      // Fallback to device locale if storefront is unavailable
      let fallbackCode = Locale.current.regionCode ?? "US"
      resolve(fallbackCode)
    }
  }
}
#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE(AppStoreRegion, NSObject)

RCT_EXTERN_METHOD(getAppStoreRegion:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)

@end

Code sample


jonluca avatar Jul 02 '25 03:07 jonluca

@jonluca Do you know if this feature also exists on Android? (and the Play Store)

zoontek avatar Jul 12 '25 07:07 zoontek

Not super easily I think - https://stackoverflow.com/questions/19288379/how-to-get-the-google-play-store-locale

jonluca avatar Jul 13 '25 19:07 jonluca