Skip to content
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

Open
bummzack opened this issue Dec 11, 2017 · 8 comments · May be fixed by #5
Open

Calendar localization #2

bummzack opened this issue Dec 11, 2017 · 8 comments · May be fixed by #5

Comments

@bummzack
Copy link

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' via setCalendarConfig has no effect, most likely because the localization files aren't bundled or exposed).

@colintucker
Copy link
Member

Hi @bummzack - hmm, good point! I will have a look into it. 😃

@srigaux
Copy link

srigaux commented Sep 23, 2018

Is there a solution?

@guyvanbael
Copy link

guyvanbael commented Nov 23, 2018

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...

@bhofstaetter
Copy link

bhofstaetter commented Nov 23, 2018

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/flatpickr@4.5.2/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 CMSPageEditController and the use of the updateEditForm function. This works until the page is saved. Afterwards, the configuration didn't get reapplied and the default config is used. So I switched to the Toolbox::flatpickr_field() method

@guyvanbael
Copy link

It's a workaround, but i hope it will take the contentlocale soon, especially for multilingual sites

@wernerkrauss
Copy link

@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

@micschk micschk linked a pull request Jul 2, 2019 that will close this issue
@micschk
Copy link

micschk commented Jul 2, 2019

@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).

@chriszuercher
Copy link

@colintucker Is there any update on this? I like this extension, but without i18n it doesn''t make much sense for Europeans :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants