|
18 | 18 | import com.instabug.library.Instabug;
|
19 | 19 | import com.instabug.library.OnSdkDismissCallback;
|
20 | 20 | import com.instabug.library.extendedbugreport.ExtendedBugReport;
|
| 21 | +import com.instabug.library.internal.module.InstabugLocale; |
21 | 22 | import com.instabug.library.invocation.InstabugInvocationEvent;
|
22 | 23 | import com.instabug.bug.invocation.InvocationMode;
|
23 | 24 | import com.instabug.library.invocation.OnInvokeCallback;
|
|
49 | 50 | import java.util.HashMap;
|
50 | 51 | import java.util.Iterator;
|
51 | 52 | import java.util.List;
|
| 53 | +import java.util.Locale; |
52 | 54 |
|
53 | 55 | /**
|
54 | 56 | * This plugin initializes Instabug.
|
@@ -1133,6 +1135,25 @@ public void setShouldShowSurveysWelcomeScreen(final CallbackContext callbackCont
|
1133 | 1135 | }
|
1134 | 1136 | }
|
1135 | 1137 |
|
| 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 | + |
1136 | 1157 | /**
|
1137 | 1158 | * Adds intent extras for all options passed to activate().
|
1138 | 1159 | */
|
@@ -1193,6 +1214,48 @@ public static int parseInvocationOption(String invocationOption) {
|
1193 | 1214 | } else return -1;
|
1194 | 1215 | }
|
1195 | 1216 |
|
| 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 | + |
1196 | 1259 | /**
|
1197 | 1260 | * Convenience method for converting string to InvocationOption.
|
1198 | 1261 | *
|
|
0 commit comments