#walter_code

1 messages ยท Page 1 of 1 (latest)

clear epochBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1458432188172341535

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

vestal marsh
#

Adding CFBundleLocalizations on the app's plist and only adding a single language there, to force the PaymentSheet to use that
Yes this is the only workaround availble

#

Otherwise, you can't force the PaymentSheet to use a particular local programmatically.

tawdry tartan
#

This is not working

#

am I doing something wrong?

vestal marsh
#

What language are you getting ?

#

You are using the ios SDK or ReactNative ?

tawdry tartan
#

the ios SDK

#

I set the phone to Finnish, and set the BundleLocalizations to english

#

the sheet is still Finnish

vestal marsh
#

Ok let me do a quick test with the native IOs SDK. I had done this with ReactNative before...

tawdry tartan
#

thanks!

vestal marsh
tawdry tartan
#

thanks!

vestal marsh
#

Found it. Try to override the local in your main AppDelegate:

@_spi(STP) import StripeCore

class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {


        // Force English locale for the example app
        STPLocalizationUtils.overrideLanguage(to: "en") // <= ADD THIS LINE
tawdry tartan
#

thanks, let me try

#

'overrideLanguage' is inaccessible due to 'internal' protection level

#

I can see the method on the core, but looks like I can't access it

vestal marsh
#

Yes indeed, and it's in core and can't be exposed publically

tawdry tartan
#

I added the import according to your code

vestal marsh
#

Yes yes, you need to modify the core, which isn't possible

tawdry tartan
#

yep

vestal marsh
#

Ok I think another option, is to use Bundle extension

#

Create a file in your root directory Bundle+ForceEnglish.swift (same level with your AppDelegate)

//
//  Bundle+ForceEnglish.swift
//  PaymentSheet Example
//
//  Created to force English localization in the example app
//

import Foundation
import ObjectiveC

private var bundleKey: UInt8 = 0

extension Bundle {
    static func swizzleLocalization() {
        // Swizzle the preferredLocalizations property to always return English
        DispatchQueue.once(token: "com.stripe.bundleSwizzle") {
            object_setClass(Bundle.main, PrivateBundle.self)
        }
    }
}

private class PrivateBundle: Bundle {
    override var preferredLocalizations: [String] {
        return ["en"]
    }
    
    override var localizations: [String] {
        return ["en"]
    }
}

extension DispatchQueue {
    private static var _onceTracker = [String]()
    
    class func once(token: String, block: () -> Void) {
        objc_sync_enter(self)
        defer { objc_sync_exit(self) }
        
        if _onceTracker.contains(token) {
            return
        }
        
        _onceTracker.append(token)
        block()
    }
}

#

Then in your AppDelegate called Bundle.swizzleLocalization()

tawdry tartan
#

thanks, I'll try

#

it did not work

vestal marsh
#

I just tested it and it works actually

#

Can you try it on our official IOS sample?

clear epochBOT
tawdry tartan
#

I can see that the preferredLocalizations method is called

#

but the sheet is still in Finnish

#

hopefully I'm not doing anything else on the app that messes with it

vestal marsh
#

There must be something else in your integration that ignoring the forcing of the local

tawdry tartan
#

just a moment

#

I'm having trouble compiling the example

vestal marsh
#

You should open the main project stripe-ios via Stripe.xcworkspace then run the PaymentSheet Example

tawdry tartan
#

ah! thanks!

#

still Finnish

#

I'm running on a simulator, does that make any difference?

vestal marsh
#

Mm, I'm running it on a simulator too ๐Ÿค”

tawdry tartan
#

I added a breakpoint and the preferredLocalizations is called

vestal marsh
#

Ah sorry, I didn't revert part of the code that is changing the core lib

#

Well, I think there is no possibility to override this. The PaymentSheet is aligning with the device default local

tawdry tartan
#

ok

#

thank you very much for your help