mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 23:06:40 +00:00
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:
parent
cc64fc9809
commit
57071f7250
@ -117,7 +117,7 @@ Polymer({
|
|||||||
hass.entityHistoryGetters.currentDate,
|
hass.entityHistoryGetters.currentDate,
|
||||||
function (currentDate) {
|
function (currentDate) {
|
||||||
var dateObj = new Date(currentDate);
|
var dateObj = new Date(currentDate);
|
||||||
return dateObj.toLocaleDateString();
|
return window.hassUtil.formatDate(dateObj);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
@ -100,7 +100,7 @@ Polymer({
|
|||||||
hass.logbookGetters.currentDate,
|
hass.logbookGetters.currentDate,
|
||||||
function (currentDate) {
|
function (currentDate) {
|
||||||
var dateObj = new Date(currentDate);
|
var dateObj = new Date(currentDate);
|
||||||
return dateObj.toLocaleDateString();
|
return window.hassUtil.formatDate(dateObj);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
@ -34,6 +34,9 @@ window.hassUtil.HIDE_MORE_INFO = [
|
|||||||
'input_select', 'scene', 'script', 'input_slider',
|
'input_select', 'scene', 'script', 'input_slider',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
window.hassUtil.LANGUAGE = navigator.languages ?
|
||||||
|
navigator.languages[0] : navigator.language || navigator.userLanguage;
|
||||||
|
|
||||||
window.hassUtil.attributeClassNames = function (stateObj, attributes) {
|
window.hassUtil.attributeClassNames = function (stateObj, attributes) {
|
||||||
if (!stateObj) return '';
|
if (!stateObj) return '';
|
||||||
return attributes.map(
|
return attributes.map(
|
||||||
@ -100,7 +103,7 @@ window.fecha.masks.haDateTime = (window.fecha.masks.shortTime + ' ' +
|
|||||||
|
|
||||||
if (toLocaleStringSupportsOptions()) {
|
if (toLocaleStringSupportsOptions()) {
|
||||||
window.hassUtil.formatDateTime = function (dateObj) {
|
window.hassUtil.formatDateTime = function (dateObj) {
|
||||||
return dateObj.toLocaleString(navigator.language, {
|
return dateObj.toLocaleString(window.hassUtil.LANGUAGE, {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: 'long',
|
month: 'long',
|
||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
@ -116,7 +119,7 @@ if (toLocaleStringSupportsOptions()) {
|
|||||||
|
|
||||||
if (toLocaleDateStringSupportsOptions()) {
|
if (toLocaleDateStringSupportsOptions()) {
|
||||||
window.hassUtil.formatDate = function (dateObj) {
|
window.hassUtil.formatDate = function (dateObj) {
|
||||||
return dateObj.toLocaleDateString(navigator.language,
|
return dateObj.toLocaleDateString(window.hassUtil.LANGUAGE,
|
||||||
{ year: 'numeric', month: 'long', day: 'numeric' });
|
{ year: 'numeric', month: 'long', day: 'numeric' });
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@ -127,7 +130,7 @@ if (toLocaleDateStringSupportsOptions()) {
|
|||||||
|
|
||||||
if (toLocaleTimeStringSupportsOptions()) {
|
if (toLocaleTimeStringSupportsOptions()) {
|
||||||
window.hassUtil.formatTime = function (dateObj) {
|
window.hassUtil.formatTime = function (dateObj) {
|
||||||
return dateObj.toLocaleTimeString(navigator.language,
|
return dateObj.toLocaleTimeString(window.hassUtil.LANGUAGE,
|
||||||
{ hour: 'numeric', minute: '2-digit' });
|
{ hour: 'numeric', minute: '2-digit' });
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user