dateMenu: Use non-capitalized forecasts where appropriate
GWeather now provides us with API to request strings that don't use sentence capitalization, so we can use it for summaries that don't start a sentence to make for more natural phrases. https://bugzilla.gnome.org/show_bug.cgi?id=779873
This commit is contained in:
parent
63bd6efae4
commit
2339351499
@ -233,11 +233,16 @@ var WeatherSection = new Lang.Class({
|
|||||||
this._sync();
|
this._sync();
|
||||||
},
|
},
|
||||||
|
|
||||||
_getSummary: function(info) {
|
_getSummary: function(info, capitalize=false) {
|
||||||
let summary = info.get_conditions();
|
let options = capitalize ? GWeather.FormatOptions.SENTENCE_CAPITALIZATION
|
||||||
if (summary == '-')
|
: GWeather.FormatOptions.NO_CAPITALIZATION;
|
||||||
return info.get_sky();
|
|
||||||
return summary;
|
let [ok, phenom, qualifier] = info.get_value_conditions();
|
||||||
|
if (ok)
|
||||||
|
return GWeather.conditions_to_string_full(phenom, qualifier, options);
|
||||||
|
|
||||||
|
let [, sky] = info.get_value_sky();
|
||||||
|
return GWeather.sky_to_string_full(sky, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
_sameSummary: function(info1, info2) {
|
_sameSummary: function(info1, info2) {
|
||||||
@ -255,10 +260,10 @@ var WeatherSection = new Lang.Class({
|
|||||||
let info = this._weatherClient.info;
|
let info = this._weatherClient.info;
|
||||||
let forecasts = info.get_forecast_list();
|
let forecasts = info.get_forecast_list();
|
||||||
if (forecasts.length == 0) // No forecasts, just current conditions
|
if (forecasts.length == 0) // No forecasts, just current conditions
|
||||||
return '%s.'.format(this._getSummary(info));
|
return '%s.'.format(this._getSummary(info, true));
|
||||||
|
|
||||||
let current = info;
|
let current = info;
|
||||||
let summaries = [this._getSummary(info)];
|
let infos = [info];
|
||||||
for (let i = 0; i < forecasts.length; i++) {
|
for (let i = 0; i < forecasts.length; i++) {
|
||||||
let [ok, timestamp] = forecasts[i].get_value_update();
|
let [ok, timestamp] = forecasts[i].get_value_update();
|
||||||
if (!_isToday(new Date(timestamp * 1000)))
|
if (!_isToday(new Date(timestamp * 1000)))
|
||||||
@ -268,12 +273,12 @@ var WeatherSection = new Lang.Class({
|
|||||||
continue; // Ignore consecutive runs of equal summaries
|
continue; // Ignore consecutive runs of equal summaries
|
||||||
|
|
||||||
current = forecasts[i];
|
current = forecasts[i];
|
||||||
if (summaries.push(this._getSummary(current)) == 3)
|
if (infos.push(current) == 3)
|
||||||
break; // Use a maximum of three summaries
|
break; // Use a maximum of three summaries
|
||||||
}
|
}
|
||||||
|
|
||||||
let fmt;
|
let fmt;
|
||||||
switch(summaries.length) {
|
switch(infos.length) {
|
||||||
/* Translators: %s is a weather condition like "Clear sky"; see
|
/* Translators: %s is a weather condition like "Clear sky"; see
|
||||||
libgweather for the possible condition strings. If at all
|
libgweather for the possible condition strings. If at all
|
||||||
possible, the sentence should match the grammatical case etc. of
|
possible, the sentence should match the grammatical case etc. of
|
||||||
@ -292,6 +297,10 @@ var WeatherSection = new Lang.Class({
|
|||||||
the inserted conditions. */
|
the inserted conditions. */
|
||||||
case 3: fmt = _("%s, then %s, followed by %s later."); break;
|
case 3: fmt = _("%s, then %s, followed by %s later."); break;
|
||||||
}
|
}
|
||||||
|
let summaries = infos.map((info, i) => {
|
||||||
|
let capitalize = i == 0 && fmt.startsWith('%s');
|
||||||
|
return this._getSummary(info, capitalize);
|
||||||
|
});
|
||||||
return String.prototype.format.apply(fmt, summaries);
|
return String.prototype.format.apply(fmt, summaries);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user