From f330f57a4214d8f67813a9844f5a102fb297e915 Mon Sep 17 00:00:00 2001 From: funCapital Date: Sat, 7 Feb 2026 20:23:15 +0300 Subject: [PATCH] feat: add setLocaleIdentifier for runtime locale changes Expose Superwall.shared.localeIdentifier as a runtime-settable property across iOS, Android, TypeScript module, Zustand store, and compat layer. This allows changing the paywall language at runtime without needing to reconfigure the SDK. Previously, localeIdentifier could only be set via SuperwallOptions at configure time, making dynamic language switching impossible. Co-Authored-By: Claude Opus 4.6 --- .../modules/superwallexpo/SuperwallExpoModule.kt | 4 ++++ ios/SuperwallExpoModule.swift | 4 ++++ src/SuperwallExpoModule.ts | 1 + src/compat/index.ts | 11 +++++++++++ src/useSuperwall.ts | 12 ++++++++++++ 5 files changed, 32 insertions(+) diff --git a/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt b/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt index 1c194a3..aadeb5f 100644 --- a/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt +++ b/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt @@ -463,6 +463,10 @@ class SuperwallExpoModule : Module() { } } + Function("setLocaleIdentifier") { localeIdentifier: String? -> + Superwall.instance.localeIdentifier = localeIdentifier + } + AsyncFunction("setIntegrationAttributes") { attributes: Map, promise: Promise -> scope.launch { try { diff --git a/ios/SuperwallExpoModule.swift b/ios/SuperwallExpoModule.swift index 9b1338e..93c7f11 100644 --- a/ios/SuperwallExpoModule.swift +++ b/ios/SuperwallExpoModule.swift @@ -360,6 +360,10 @@ public class SuperwallExpoModule: Module { } } + Function("setLocaleIdentifier") { (localeIdentifier: String?) in + Superwall.shared.localeIdentifier = localeIdentifier + } + AsyncFunction("setIntegrationAttributes") { (attributes: [String: String], promise: Promise) in var converted: [IntegrationAttribute: String] = [:] diff --git a/src/SuperwallExpoModule.ts b/src/SuperwallExpoModule.ts index 76ea57e..0dc2cab 100644 --- a/src/SuperwallExpoModule.ts +++ b/src/SuperwallExpoModule.ts @@ -65,6 +65,7 @@ declare class SuperwallExpoModule extends NativeModule getIntegrationAttributes(): Promise> diff --git a/src/compat/index.ts b/src/compat/index.ts index ce471fc..467777f 100644 --- a/src/compat/index.ts +++ b/src/compat/index.ts @@ -720,6 +720,17 @@ export default class Superwall { await SuperwallExpoModule.setLogLevel(level.toString()) } + /** + * Sets the locale identifier for the Superwall SDK. + * This determines the language used when presenting paywalls. + * Can be changed at runtime without needing to reconfigure. + * + * @param localeIdentifier - The locale identifier (e.g., "en_US", "es_ES"), or `null` to reset to the device locale. + */ + async setLocaleIdentifier(localeIdentifier: string | null): Promise { + SuperwallExpoModule.setLocaleIdentifier(localeIdentifier) + } + /** * Sets attributes for third-party integrations. * @param attributes - Object mapping IntegrationAttribute string values to their IDs diff --git a/src/useSuperwall.ts b/src/useSuperwall.ts index d16164b..445b8b9 100644 --- a/src/useSuperwall.ts +++ b/src/useSuperwall.ts @@ -163,6 +163,15 @@ export interface SuperwallStore { */ setLogLevel: (level: string) => Promise + /** + * Sets the locale identifier for the Superwall SDK. + * This determines the language used when presenting paywalls. + * Can be changed at runtime without needing to reconfigure. + * @param localeIdentifier - The locale identifier (e.g., "en", "es", "fr"), or `null` to reset to the device locale. + * @returns A promise that resolves when the locale identifier is set. + */ + setLocaleIdentifier: (localeIdentifier: string | null) => Promise + /** * Sets attributes for third-party integrations. * @param attributes - Object mapping IntegrationAttribute string values to their IDs @@ -320,6 +329,9 @@ export const useSuperwallStore = create((set, get) => ({ setLogLevel: async (level) => { SuperwallExpoModule.setLogLevel(level) }, + setLocaleIdentifier: async (localeIdentifier) => { + SuperwallExpoModule.setLocaleIdentifier(localeIdentifier) + }, setIntegrationAttributes: async (attributes) => { await SuperwallExpoModule.setIntegrationAttributes(attributes)