Use locale in toLocaleString(), needed since gnome-shell 3.24to get correct localization of deciaml values.

merge-requests/218/head
Jens Lody 8 years ago
parent 34506a6557
commit 648d491e57
  1. 22
      src/extension.js

@ -151,6 +151,12 @@ const OpenweatherMenuButton = new Lang.Class({
_init: function() { _init: function() {
this.owmCityId = 0; this.owmCityId = 0;
// Get locale, needed for toLocaleString, workaround for gnome-shell 3.24
this.locale = GLib.get_language_names()[0];
if (this.locale.indexOf('_') != -1)
this.locale = this.locale.split("_")[0];
// Create user-agent string from uuid and (if present) the version // Create user-agent string from uuid and (if present) the version
this.user_agent = Me.metadata.uuid; this.user_agent = Me.metadata.uuid;
if (Me.metadata.version !== undefined && Me.metadata.version.toString().trim() !== '') { if (Me.metadata.version !== undefined && Me.metadata.version.toString().trim() !== '') {
@ -429,13 +435,9 @@ const OpenweatherMenuButton = new Lang.Class({
'zh', 'zh',
'zh-tw' 'zh-tw'
]; ];
let locale = GLib.get_language_names()[0];
if (locale.indexOf('_') != -1)
locale = locale.split("_")[0];
if (fc_locales.indexOf(locale) != -1) if (fc_locales.indexOf(this.locale) != -1)
this.fc_locale = locale; this.fc_locale = this.locale;
} }
if (this._appid_fc.toString().trim() === '') if (this._appid_fc.toString().trim() === '')
@ -1284,7 +1286,7 @@ const OpenweatherMenuButton = new Lang.Class({
pressure_unit = _("mbar"); pressure_unit = _("mbar");
break; break;
} }
return parseFloat(pressure).toLocaleString() + ' ' + pressure_unit; return parseFloat(pressure).toLocaleString(this.locale) + ' ' + pressure_unit;
}, },
formatTemperature: function(temperature) { formatTemperature: function(temperature) {
@ -1321,7 +1323,7 @@ const OpenweatherMenuButton = new Lang.Class({
temperature = this.toNewton(temperature); temperature = this.toNewton(temperature);
break; break;
} }
return parseFloat(temperature).toLocaleString() + ' ' + this.unit_to_unicode(); return parseFloat(temperature).toLocaleString(this.locale) + ' ' + this.unit_to_unicode();
}, },
formatWind: function(speed, direction) { formatWind: function(speed, direction) {
@ -1361,9 +1363,9 @@ const OpenweatherMenuButton = new Lang.Class({
if (!speed) if (!speed)
return '\u2013'; return '\u2013';
else if (speed === 0 || !direction) else if (speed === 0 || !direction)
return parseFloat(speed).toLocaleString() + ' ' + unit; return parseFloat(speed).toLocaleString(this.locale) + ' ' + unit;
else // i.e. speed > 0 && direction else // i.e. speed > 0 && direction
return direction + ' ' + parseFloat(speed).toLocaleString() + ' ' + unit; return direction + ' ' + parseFloat(speed).toLocaleString(this.locale) + ' ' + unit;
}, },
reloadWeatherCurrent: function(interval) { reloadWeatherCurrent: function(interval) {

Loading…
Cancel
Save