From a3a3c64d23f1ae6ecbfd3b68eb2d6ed15167ff0a Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Mon, 29 Aug 2016 09:35:54 +0200 Subject: [PATCH] Make datetimepicker locale aware - Set the moment locale when setting user language - Pass the moment locale to datepicker instances issue5797 review21201002 --- CHANGELOG | 1 + index.html | 1 + src/sao.js | 13 ++++++++----- src/screen.js | 4 +++- src/view/form.js | 7 +++++-- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6d6a896491..395a1e5ca6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Make datetimepicker locale aware * Restore tab default order when no manual change * Add support for column sorting * Manage confirm attribute on buttons diff --git a/index.html b/index.html index a2f1dad8e7..17c2724416 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,7 @@ this repository contains the full copyright notices and license terms. --> + diff --git a/src/sao.js b/src/sao.js index d4cb8cedc3..a6ce7b9655 100644 --- a/src/sao.js +++ b/src/sao.js @@ -189,7 +189,14 @@ var Sao = {}; Sao.i18n = i18n(); Sao.i18n.setlang = function(lang) { + if (!lang) { + lang = (navigator.language || + navigator.browserLanguage || + navigator.userLanguage || + 'en_US').replace('-', '_'); + } Sao.i18n.setLocale(lang); + moment.locale(lang.slice(0, 2)); return jQuery.getJSON('locale/' + lang + '.json', function(data) { if (!data[''].language) { data[''].language = lang; @@ -210,11 +217,7 @@ var Sao = {}; Sao.i18n.getlang = function() { return Sao.i18n.getLocale(); }; - Sao.i18n.setlang( - (navigator.language || - navigator.browserLanguge || - navigator.userLanguage || - 'en_US').replace('-', '_')); + Sao.i18n.setlang(); Sao.get_preferences = function() { var session = Sao.Session.current_session; diff --git a/src/screen.js b/src/screen.js index 8dd4e2db15..0aebf9129b 100644 --- a/src/screen.js +++ b/src/screen.js @@ -537,7 +537,9 @@ }).append(jQuery('', { 'class': 'glyphicon glyphicon-calendar' }))).appendTo(entry); - entry.datetimepicker(); + entry.datetimepicker({ + 'locale': moment.locale() + }); entry.data('DateTimePicker').format(format); return entry; }; diff --git a/src/view/form.js b/src/view/form.js index a655f73ee0..9f23d138c8 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -1056,7 +1056,9 @@ }).append(jQuery('', { 'class': 'glyphicon glyphicon-calendar' }))).appendTo(this.date); - this.date.datetimepicker(); + this.date.datetimepicker({ + 'locale': moment.locale() + }); this.date.css('width', this._width); this.date.on('dp.hide', this.focus_out.bind(this)); }, @@ -3647,7 +3649,8 @@ 'class': 'glyphicon glyphicon-calendar' })).prependTo(group); this.input.datetimepicker({ - 'format': Sao.common.moment_format(this.format) + 'format': Sao.common.moment_format(this.format), + 'locale': moment.locale() }); this.input.on('dp.hide', this.parent_widget.focus_out.bind(this.parent_widget));