Merge pull request #2397 from ashishtank/develop

Added support for variables in nunjucks templates for translate filter
This commit is contained in:
Michael Teeuw 2020-12-31 19:57:03 +01:00 committed by GitHub
commit a4ab0cbe09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 4 deletions

View File

@ -18,6 +18,7 @@ _This release is scheduled to be released on 2021-01-01._
- Added SMHI as a provider to Weather module.
- Added Hindi & Gujarati translation.
- Added optional support for DEGREE position in Feels like translation
- Added support for variables in nunjucks templates for translate filter
- Chuvash translation.
- Calendar: new options "limitDays" and "coloredEvents".
- Added new option "limitDays" - limit the number of discreet days displayed.
@ -63,6 +64,7 @@ _This release is scheduled to be released on 2021-01-01._
- update node-ical version again, 0.12.7, change RRULE fix (#2371, #2379), node-ical now throws error (which we catch)
- update simple-git version to 2.31 unhandled promise rejection (#2383)
- Translator variables can have falsy values (e.g. empty string)
- Fix issue with weather module with DEGREE label in FEELS like
## [2.13.0] - 2020-10-01

View File

@ -175,8 +175,8 @@ var Module = Class.extend({
lstripBlocks: true
});
this._nunjucksEnvironment.addFilter("translate", function (str) {
return self.translate(str);
this._nunjucksEnvironment.addFilter("translate", function (str, variables) {
return self.translate(str, variables);
});
return this._nunjucksEnvironment;

View File

@ -69,7 +69,10 @@
<div class="normal medium">
{% if config.showFeelsLike %}
<span class="dimmed">
{{ "FEELS" | translate }} {{ current.feelsLike() | roundValue | unit("temperature") | decimalSymbol }}
{{ "FEELS" | translate({DEGREE: current.feelsLike() | roundValue | unit("temperature") | decimalSymbol }) }}
{% if not config.feelsLikeWithDegree %}
{{ current.feelsLike() | roundValue | unit("temperature") | decimalSymbol }}
{% endif %}
</span>
{% endif %}
{% if config.showPrecipitationAmount %}

View File

@ -52,7 +52,8 @@ Module.register("weather", {
onlyTemp: false,
showPrecipitationAmount: false,
colored: false,
showFeelsLike: true
showFeelsLike: true,
feelsLikeWithDegree: false
},
// Module properties.
@ -88,6 +89,8 @@ Module.register("weather", {
// Let the weather provider know we are starting.
this.weatherProvider.start();
this.config.feelsLikeWithDegree = this.translate("FEELS").indexOf("{DEGREE}") > -1;
// Add custom filters
this.addFilters();