Fix locale for non-english users (#170)

* Take navigator.languages into account when determining the preferred language

* Lookup language only once, use it also for other date/time functions

* Show the date picker value in localized date

* Show the date picker value in localized date (in history)
This commit is contained in:
Michaël Arnauts 2017-01-05 14:38:27 +01:00 committed by Paulus Schoutsen
parent cc64fc9809
commit 57071f7250
3 changed files with 8 additions and 5 deletions

View File

@ -117,7 +117,7 @@ Polymer({
hass.entityHistoryGetters.currentDate,
function (currentDate) {
var dateObj = new Date(currentDate);
return dateObj.toLocaleDateString();
return window.hassUtil.formatDate(dateObj);
},
];
},

View File

@ -100,7 +100,7 @@ Polymer({
hass.logbookGetters.currentDate,
function (currentDate) {
var dateObj = new Date(currentDate);
return dateObj.toLocaleDateString();
return window.hassUtil.formatDate(dateObj);
},
];
},

View File

@ -34,6 +34,9 @@ window.hassUtil.HIDE_MORE_INFO = [
'input_select', 'scene', 'script', 'input_slider',
];
window.hassUtil.LANGUAGE = navigator.languages ?
navigator.languages[0] : navigator.language || navigator.userLanguage;
window.hassUtil.attributeClassNames = function (stateObj, attributes) {
if (!stateObj) return '';
return attributes.map(
@ -100,7 +103,7 @@ window.fecha.masks.haDateTime = (window.fecha.masks.shortTime + ' ' +
if (toLocaleStringSupportsOptions()) {
window.hassUtil.formatDateTime = function (dateObj) {
return dateObj.toLocaleString(navigator.language, {
return dateObj.toLocaleString(window.hassUtil.LANGUAGE, {
year: 'numeric',
month: 'long',
day: 'numeric',
@ -116,7 +119,7 @@ if (toLocaleStringSupportsOptions()) {
if (toLocaleDateStringSupportsOptions()) {
window.hassUtil.formatDate = function (dateObj) {
return dateObj.toLocaleDateString(navigator.language,
return dateObj.toLocaleDateString(window.hassUtil.LANGUAGE,
{ year: 'numeric', month: 'long', day: 'numeric' });
};
} else {
@ -127,7 +130,7 @@ if (toLocaleDateStringSupportsOptions()) {
if (toLocaleTimeStringSupportsOptions()) {
window.hassUtil.formatTime = function (dateObj) {
return dateObj.toLocaleTimeString(navigator.language,
return dateObj.toLocaleTimeString(window.hassUtil.LANGUAGE,
{ hour: 'numeric', minute: '2-digit' });
};
} else {