Skip to content

Commit bed9739

Browse files
authored
Add setLocale to android (#105)
1 parent a6f1307 commit bed9739

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/android/IBGPlugin.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.instabug.library.Instabug;
1919
import com.instabug.library.OnSdkDismissCallback;
2020
import com.instabug.library.extendedbugreport.ExtendedBugReport;
21+
import com.instabug.library.internal.module.InstabugLocale;
2122
import com.instabug.library.invocation.InstabugInvocationEvent;
2223
import com.instabug.bug.invocation.InvocationMode;
2324
import com.instabug.library.invocation.OnInvokeCallback;
@@ -49,6 +50,7 @@
4950
import java.util.HashMap;
5051
import java.util.Iterator;
5152
import java.util.List;
53+
import java.util.Locale;
5254

5355
/**
5456
* This plugin initializes Instabug.
@@ -1133,6 +1135,25 @@ public void setShouldShowSurveysWelcomeScreen(final CallbackContext callbackCont
11331135
}
11341136
}
11351137

1138+
/**
1139+
* Change Locale of Instabug UI elements(defaults to English)
1140+
*
1141+
*
1142+
* @param args .optString(0) locale name
1143+
*
1144+
* @param callbackContext Used when calling back into JavaScript
1145+
*/
1146+
public void setLocale(final CallbackContext callbackContext, JSONArray args) {
1147+
String locale = args.optString(0);
1148+
try {
1149+
InstabugLocale instabugLocale = parseLocale(locale);
1150+
Instabug.setLocale(new Locale(instabugLocale.getCode(), instabugLocale.getCountry()));
1151+
callbackContext.success();
1152+
} catch (IllegalStateException e) {
1153+
callbackContext.error(errorMsg);
1154+
}
1155+
}
1156+
11361157
/**
11371158
* Adds intent extras for all options passed to activate().
11381159
*/
@@ -1193,6 +1214,48 @@ public static int parseInvocationOption(String invocationOption) {
11931214
} else return -1;
11941215
}
11951216

1217+
/**
1218+
* Convenience method for converting string to Locale.
1219+
*
1220+
* @param locale
1221+
* String shortcode for locale
1222+
*/
1223+
public static InstabugLocale parseLocale(String locale) {
1224+
if ("arabic".equals(locale)) {
1225+
return InstabugLocale.ARABIC;
1226+
} else if ("chineseSimplified".equals(locale)) {
1227+
return InstabugLocale.SIMPLIFIED_CHINESE;
1228+
} else if ("chineseTraditional".equals(locale)) {
1229+
return InstabugLocale.TRADITIONAL_CHINESE;
1230+
} else if ("english".equals(locale)) {
1231+
return InstabugLocale.ENGLISH;
1232+
} else if ("french".equals(locale)) {
1233+
return InstabugLocale.FRENCH;
1234+
} else if ("german".equals(locale)) {
1235+
return InstabugLocale.GERMAN;
1236+
} else if ("italian".equals(locale)) {
1237+
return InstabugLocale.ITALIAN;
1238+
} else if ("japanese".equals(locale)) {
1239+
return InstabugLocale.JAPANESE;
1240+
} else if ("korean".equals(locale)) {
1241+
return InstabugLocale.KOREAN;
1242+
} else if ("polish".equals(locale)) {
1243+
return InstabugLocale.POLISH;
1244+
} else if ("portugueseBrazil".equals(locale)) {
1245+
return InstabugLocale.PORTUGUESE_BRAZIL;
1246+
} else if ("russian".equals(locale)) {
1247+
return InstabugLocale.RUSSIAN;
1248+
} else if ("spanish".equals(locale)) {
1249+
return InstabugLocale.SPANISH;
1250+
} else if ("swedish".equals(locale)) {
1251+
return InstabugLocale.SWEDISH;
1252+
} else if ("turkish".equals(locale)) {
1253+
return InstabugLocale.TURKISH;
1254+
} else if ("czech".equals(locale)) {
1255+
return InstabugLocale.CZECH;
1256+
} else return InstabugLocale.ENGLISH;
1257+
}
1258+
11961259
/**
11971260
* Convenience method for converting string to InvocationOption.
11981261
*

0 commit comments

Comments
 (0)