From 16df780314e64b5dce61c6a063f0bd0e42a15b38 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Thu, 25 Nov 2021 13:26:52 +0100 Subject: [PATCH] Fixes: #3866 - Date of datepicker is not localized. --- .../app/controllers/_ui_element/basedate.coffee | 2 +- .../javascripts/app/controllers/layout_ref.coffee | 4 ++-- public/assets/tests/qunit/i18n.js | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/basedate.coffee b/app/assets/javascripts/app/controllers/_ui_element/basedate.coffee index 900e5cbec..5796a2345 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/basedate.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/basedate.coffee @@ -33,7 +33,7 @@ class App.UiElement.basedate autoclose: true todayBtn: 'linked' todayHighlight: true - format: App.i18n.timeFormat().date + format: App.i18n.timeFormat()['FORMAT_DATE'] rtl: App.i18n.dir() is 'rtl' container: item language: 'custom' diff --git a/app/assets/javascripts/app/controllers/layout_ref.coffee b/app/assets/javascripts/app/controllers/layout_ref.coffee index 5af95f7c9..9c9995542 100644 --- a/app/assets/javascripts/app/controllers/layout_ref.coffee +++ b/app/assets/javascripts/app/controllers/layout_ref.coffee @@ -1533,7 +1533,7 @@ class InputsRef extends App.ControllerAppContent @$('.js-datepicker3').datepicker( todayHighlight: true startDate: new Date() - format: App.i18n.timeFormat().date + format: App.i18n.timeFormat()['FORMAT_DATE'] rtl: App.i18n.dir() is 'rtl' container: @$('.js-datepicker3').parent() ) @@ -1542,7 +1542,7 @@ class InputsRef extends App.ControllerAppContent @$('.js-datepicker4').datepicker( todayHighlight: true startDate: new Date() - format: App.i18n.timeFormat().date + format: App.i18n.timeFormat()['FORMAT_DATE'] rtl: App.i18n.dir() is 'rtl' container: @$('.js-datepicker4').parent() ) diff --git a/public/assets/tests/qunit/i18n.js b/public/assets/tests/qunit/i18n.js index c651aedac..54b181777 100644 --- a/public/assets/tests/qunit/i18n.js +++ b/public/assets/tests/qunit/i18n.js @@ -157,6 +157,13 @@ QUnit.test('i18n', assert => { date = App.i18n.translateDate(undefined, 0) assert.equal(date, undefined, 'de-de - date translated correctly') + date = App.i18n.timeFormat() + assert.deepEqual(date, { "FORMAT_DATE": "dd.mm.yyyy", "FORMAT_DATETIME": "dd.mm.yyyy HH:MM" }, 'timeFormat property') + + // Verify that the datepicker gets the correct format too. + el_date = App.UiElement.date.render({name: 'test', value: '2018-07-06'}) + assert.equal(el_date.find('.js-datepicker').get(0).value, '06.07.2018') + // en App.i18n.set('en-us') translated = App.i18n.translateContent('yes') @@ -234,6 +241,13 @@ QUnit.test('i18n', assert => { date = App.i18n.translateDate(undefined, 0) assert.equal(date, undefined, 'en - date translated correctly') + date = App.i18n.timeFormat() + assert.deepEqual(date, { "FORMAT_DATE": "mm/dd/yyyy", "FORMAT_DATETIME": "mm/dd/yyyy HH:MM" }, 'timeFormat property') + + // Verify that the datepicker gets the correct format too. + el_date = App.UiElement.date.render({name: 'test', value: '2018-07-06'}) + assert.equal(el_date.find('.js-datepicker').get(0).value, '07/06/2018') + // locale alias test // de App.i18n.set('de')