#25  Date picker localisaion
Merged
Commits were merged into target branch
Michael Weimann opened 3 years ago

Adds date picker localisation.

  • basically uses the flatpickr locales
  • except for UK, Australia and New Zealand
    • The reason for that is that flatpickr has an incomplete l10n.
    • It works basically on language level. Unfortunately that isn't enough.

resolve issue onedev-server#235

New commits added 3 years ago
add flatpickr locales
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
OneDev referenced from issue 3 years ago
Michael Weimann commented 3 years ago

I think formatting the dates should be extracted to a separate task.

Robin Shen commented 3 years ago

Investigate it further, and it turns out that Wicket i18n support is quite elegant. And we can implement this feature modifying three places:

  1. Modify date-picker.js to detect browser language automatically and configure flatpickr:
  var language = navigator.language;
  var index = language.indexOf('-');
  if (index != -1)
    language = language.substring(0, index);
  var calendar = flatpickr($input[0], {dateFormat: "Y-m-d", "allowInput": true, "locale": language});
  1. Add a new dependency to dependency list of DatePickerResourceReference:
		dependencies.add(JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(DatePickerResourceReference.class, "flatpickr-locale.js")));

With this code, Wicket will load flatpickr-locale_<language>.js automatically based on browser language, and fallback to flatpickr-locale.js if relevant language file does not exist

  1. Add an empty fallback file flatpickr-locale.js under date picker directory. Move various flatpickr language files into the same directory, and rename them as flatpickr-locale_<language>.js. For instance: rename de.js as flatpickr-locale_de.js
Robin Shen commented 3 years ago

Please ignore suggested change #1 above. Your current code of setting flatpickr locale is more robust:

 var locale = (navigator.language || 'en').toLowerCase();
 var shortLocale = locale.substr(0, 2);
 if (flatpickr.l10ns[shortLocale]) {
   flatpickr.localize(flatpickr.l10ns[shortLocale]);
 }
New commits added 3 years ago
add flatpickr locales
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Michael Weimann commented 3 years ago

Investigate it further, and it turns out that Wicket i18n support is quite elegant.

For some reasons I ended up in the 6.x docs. So OneDev uses Wicket 7?

With this code, Wicket will load flatpickr-locale_.js automatically based on browser language, and fallback to flatpickr-locale.js if relevant language file does not exist

Done

Add an empty fallback file flatpickr-locale.js under date picker

And done

ame directory, and rename them as flatpickr-locale_.js. For instance: rename de.js as flatpickr-locale_de.js

I would have placed it in a subfolder since the many files are kind of confusing.

Michael Weimann changed title 3 years ago
Previous Value Current Value
WiP: Date picker localisaion
Date picker localisaion
Robin Shen approved 3 years ago
Robin Shen merged 3 years ago
pull request 1 of 1
Submitter Michael Weimann
Target main
Source onedev-server.mweimann:feature-datepicker-localisation
Reviewers
Assignees
Merge Strategy
Create Merge Commit
Watchers (2)
Reference
pull request onedev/server#25
Please wait...
Page is in error, reload to recover