diff --git a/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt b/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt index 1c194a36..aadeb5f5 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 9b1338e3..93c7f119 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 76ea57ed..0dc2cab0 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 ce471fc9..467777f1 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 d16164b9..445b8b98 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)