Skip to content

Commit a4ea858

Browse files
batadamnjanovichborisoff
authored andcommitted
Add Leanplum.setLocale (#478)
* Enable custom locale * Update setLocale method comment
1 parent 4fbd461 commit a4ea858

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public class Leanplum {
109109
private static LeanplumDeviceIdMode deviceIdMode = LeanplumDeviceIdMode.MD5_MAC_ADDRESS;
110110
private static String customDeviceId;
111111
private static String customAppVersion = null;
112+
private static String customLocale = null;
112113
private static boolean userSpecifiedDeviceId;
113114
private static boolean locationCollectionEnabled = true;
114115
private static volatile boolean pushDeliveryTrackingEnabled = true;
@@ -326,6 +327,17 @@ public static void setDeviceId(String deviceId) {
326327
userSpecifiedDeviceId = true;
327328
}
328329

330+
/**
331+
* Sets a custom locale. You should call this before {@link Leanplum#start}.
332+
*/
333+
public static void setLocale(String locale) {
334+
if (TextUtils.isEmpty(locale)) {
335+
Log.i("setLocale - Empty locale parameter provided.");
336+
}
337+
338+
customLocale = locale;
339+
}
340+
329341
/**
330342
* Gets the deviceId in the current Leanplum session. This should only be called after
331343
* {@link Leanplum#start}.
@@ -664,6 +676,11 @@ private static void startHelper(
664676
versionName = "";
665677
}
666678

679+
String locale = Util.getLocale();
680+
if (!TextUtils.isEmpty(customLocale)) {
681+
locale = customLocale;
682+
}
683+
667684
TimeZone localTimeZone = TimeZone.getDefault();
668685
Date now = new Date();
669686
int timezoneOffsetSeconds = localTimeZone.getOffset(now.getTime()) / 1000;
@@ -691,7 +708,7 @@ private static void startHelper(
691708
}
692709
params.put(Constants.Keys.TIMEZONE, localTimeZone.getID());
693710
params.put(Constants.Keys.TIMEZONE_OFFSET_SECONDS, Integer.toString(timezoneOffsetSeconds));
694-
params.put(Constants.Keys.LOCALE, Util.getLocale());
711+
params.put(Constants.Keys.LOCALE, locale);
695712
params.put(Constants.Keys.COUNTRY, Constants.Values.DETECT);
696713
params.put(Constants.Keys.REGION, Constants.Values.DETECT);
697714
params.put(Constants.Keys.CITY, Constants.Values.DETECT);

0 commit comments

Comments
 (0)