cordova-plugin-datepicker
cordova-plugin-datepicker copied to clipboard
Change language
The app is in another language than english, and the days and months are in english.
Is it possible to change the language via javascript? Or does it use the system language?
I tired to do that but I was not successful I used this plugin instead of the native date picker: Datepicker
first u find the name Datepicker file in 'www','src',then find "en_US",just like var defaults = { mode: 'date', date: new Date(), allowOldDates: true, allowFutureDates: true, minDate: '', maxDate: '', doneButtonLabel: 'Done', doneButtonColor: '#007AFF', cancelButtonLabel: 'Cancel', cancelButtonColor: '#007AFF', locale: "NL", x: '0', y: '0', minuteInterval: 1, popoverArrowDirection: this._popoverArrowDirectionIntegerFromString("any"), locale: "en_US" }; NSLocale *loc = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
change the params like locale: "zh_CN" and ...@"zh_CN"
you can add the parameter local: 'zh_CN' it will works
locale: 'zh_CN'
I solved it on Android, Navihgate to plugins\cordova-plugin-datepicker\src\android , Open DatePickerPlugin.java, 1- Add those imports import java.util.Locale; import android.content.res.Configuration;
2 - replace show method with this, ` public synchronized void show(final JSONArray data, final CallbackContext callbackContext) { DatePickerPlugin datePickerPlugin = this; Context currentCtx = cordova.getActivity(); Runnable runnable; JsonDate jsonDate = new JsonDate().fromJson(data);
// Retrieve Android theme
JSONObject options = data.optJSONObject(0);
int theme = options.optInt("androidTheme", 1);
String localeLang = "ar";
try {
Locale locale = new Locale(localeLang);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
currentCtx.getResources().updateConfiguration(config, currentCtx.getResources().getDisplayMetrics());
} catch (Exception e) {
e.printStackTrace();
}
if (ACTION_TIME.equalsIgnoreCase(jsonDate.action)) {
runnable = runnableTimeDialog(datePickerPlugin, theme, currentCtx,
callbackContext, jsonDate, Calendar.getInstance(TimeZone.getDefault()));
} else {
runnable = runnableDatePicker(datePickerPlugin, theme, currentCtx, callbackContext, jsonDate);
}
cordova.getActivity().runOnUiThread(runnable);
}
`