From aedc0a2eaa4de9f337a4878173e803db835d0262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bratislav=20Damnjanovic=CC=81?= Date: Thu, 9 Dec 2021 15:57:20 +0100 Subject: [PATCH 1/2] Enable custom locale --- .../src/main/java/com/leanplum/Leanplum.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java b/AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java index 34441f41..9605cd7e 100644 --- a/AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java +++ b/AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java @@ -111,6 +111,7 @@ public class Leanplum { private static LeanplumDeviceIdMode deviceIdMode = LeanplumDeviceIdMode.MD5_MAC_ADDRESS; private static String customDeviceId; private static String customAppVersion = null; + private static String customLocale = null; private static boolean userSpecifiedDeviceId; private static boolean locationCollectionEnabled = true; private static volatile boolean pushDeliveryTrackingEnabled = true; @@ -328,6 +329,18 @@ public static void setDeviceId(String deviceId) { userSpecifiedDeviceId = true; } + /** + * Sets a custom locale. + * Must be called before Leanplum.start(). + */ + public static void setLocale(String locale) { + if (TextUtils.isEmpty(locale)) { + Log.i("setLocale - Empty locale parameter provided."); + } + + customLocale = locale; + } + /** * Gets the deviceId in the current Leanplum session. This should only be called after * {@link Leanplum#start}. @@ -666,6 +679,11 @@ private static void startHelper( versionName = ""; } + String locale = Util.getLocale(); + if (!TextUtils.isEmpty(customLocale)) { + locale = customLocale; + } + TimeZone localTimeZone = TimeZone.getDefault(); Date now = new Date(); int timezoneOffsetSeconds = localTimeZone.getOffset(now.getTime()) / 1000; @@ -698,7 +716,7 @@ private static void startHelper( } params.put(Constants.Keys.TIMEZONE, localTimeZone.getID()); params.put(Constants.Keys.TIMEZONE_OFFSET_SECONDS, Integer.toString(timezoneOffsetSeconds)); - params.put(Constants.Keys.LOCALE, Util.getLocale()); + params.put(Constants.Keys.LOCALE, locale); params.put(Constants.Keys.COUNTRY, Constants.Values.DETECT); params.put(Constants.Keys.REGION, Constants.Values.DETECT); params.put(Constants.Keys.CITY, Constants.Values.DETECT); From 5d531943bc44459307a4be7d3848823e63fc8e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bratislav=20Damnjanovic=CC=81?= Date: Thu, 9 Dec 2021 16:16:27 +0100 Subject: [PATCH 2/2] Update setLocale method comment --- AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java b/AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java index 9605cd7e..afa837e1 100644 --- a/AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java +++ b/AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java @@ -330,8 +330,7 @@ public static void setDeviceId(String deviceId) { } /** - * Sets a custom locale. - * Must be called before Leanplum.start(). + * Sets a custom locale. You should call this before {@link Leanplum#start}. */ public static void setLocale(String locale) { if (TextUtils.isEmpty(locale)) {