-
Notifications
You must be signed in to change notification settings - Fork 9
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
Calendar localization #2
Comments
Hi @bummzack - hmm, good point! I will have a look into it. 😃 |
Is there a solution? |
yeah... since ss4 is using native html, this module is the only way to get datefields working in safari. It would be fantastic for us europeans if it picked up the contentlocale too... |
As a workaround, I'm loading the required localisation file inside my LeftAndMain extension with the onAfterInit() function. public function onAfterInit() {
Requirements::javascript('https://npmcdn.com/[email protected]/dist/l10n/de.js');
} Also I have two helper functions to easily create those fields and append the correct config to it /**
* Returns the matching config for the given field type
*
* @param string $fieldType Could be DateField, TimeField or DateTimeField
*
* @return mixed
*/
public static function flatpickr_config($fieldType) {
$calConfigs = Config::inst()->get(LeftAndMain::class, 'calendar_configs');
return $calConfigs[$fieldType];
}
/**
* Create DateField, TimeField and DateTimeField with the correct flatpickr config
*
* @param $fieldType
* @param $fieldName
* @param $fieldTitle
*
* @return bool|string
*/
public static function flatpickr_field($fieldType, $fieldName, $fieldTitle) {
$field = false;
if ($fieldType == 'DateField') {
$field = 'SilverStripe\Forms\DateField';
} else if ($fieldType == 'DateTimeField') {
$field = 'SilverStripe\Forms\DateTimeField';
} else if ($fieldType == 'TimeField') {
$field = 'SilverStripe\Forms\TimeField';
}
if ($field) {
$field = $field::create($fieldName, $fieldTitle);
$field->setCalendarConfig(self::flatpickr_config($fieldType));
return $field;
}
} This code is located inside a class I named "Toolbox" so to create fields, I'll do Toolbox::flatpickr_field('DateTimeField, 'Date', 'Datum & Uhrzeit') The configuration is stored in yml, for german fields mine looks like this SilverStripe\Admin\LeftAndMain:
calendar_highlight_color: '#43536d'
calendar_configs:
DateField:
altInput: true
allowInput: true
altFormat: 'd.m.Y'
dateFormat: 'Y/m/d'
locale: de
weekNumbers: true
DateTimeField:
altInput: true
allowInput: true
time_24hr: true
altFormat: 'd.m.Y H:i'
dateFormat: 'Y/m/d H:i'
locale: de
weekNumbers: true
TimeField:
locale: de,
time_24hr: true
allowInput: true
dateFormat: 'H:i'
altFormat: 'H:i' Quite sure that's not the nicest solution and a little bit more than just localisation, but perhaps it will help someone ;) I've also tried to apply this "global" to all of the three fields with an extension of |
It's a workaround, but i hope it will take the contentlocale soon, especially for multilingual sites |
@colintucker any progress on i18n? Your flatpicker modules are very popular, but setting first day of week to monday for a european site is a major pain |
@wernerkrauss could you please try & review my PR, this automatically sets the first day of the week to monday (based on the current locale). If you're editing using the en_US locale (like me), you may still force the first weekday to monday using standard YAML config (for all instances). |
@colintucker Is there any update on this? I like this extension, but without i18n it doesn''t make much sense for Europeans :-( |
There seems to be no way to localize the calendar.
In the CMS, it would ideally pick up the locale-setting of the currently logged in user and apply that. For frontend usage, a config-option could be used (currently, setting a
'locale'
viasetCalendarConfig
has no effect, most likely because the localization files aren't bundled or exposed).The text was updated successfully, but these errors were encountered: