Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setLocale method #478

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -328,6 +329,17 @@ public static void setDeviceId(String deviceId) {
userSpecifiedDeviceId = true;
}

/**
* Sets a custom locale. You should call this before {@link 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}.
Expand Down Expand Up @@ -666,6 +678,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;
Expand Down Expand Up @@ -698,7 +715,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);
Expand Down