cordova-plugin-datepicker icon indicating copy to clipboard operation
cordova-plugin-datepicker copied to clipboard

Change language

Open napcat opened this issue 9 years ago • 5 comments

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?

napcat avatar May 10 '16 08:05 napcat

I tired to do that but I was not successful I used this plugin instead of the native date picker: Datepicker

chandanch avatar Jul 02 '16 14:07 chandanch

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"

TimWu0101 avatar Jul 09 '16 08:07 TimWu0101

you can add the parameter local: 'zh_CN' it will works

maximekl avatar Aug 20 '16 14:08 maximekl

locale: 'zh_CN'

dericeira avatar Aug 27 '16 19:08 dericeira

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);
}
`

OmarHassan25 avatar Aug 21 '17 08:08 OmarHassan25