Rename pluralize arguments into singular and plural

This commit is contained in:
Guillaume Gomez 2025-04-21 22:46:59 +02:00 committed by René Kijewski
parent 6cea91a9b5
commit 7c5deda4c1
5 changed files with 27 additions and 27 deletions

View File

@ -232,11 +232,11 @@ impl<'a> Generator<'a, '_> {
const ARGUMENTS: &[&FilterArgument; 3] = &[
FILTER_SOURCE,
&FilterArgument {
name: "sg",
name: "singular",
default_value: Some(SINGULAR),
},
&FilterArgument {
name: "pl",
name: "plural",
default_value: Some(PLURAL),
},
];

View File

@ -22,10 +22,10 @@ Built-in filters that take (optional) arguments can be called with named argumen
The order of the named arguments does not matter, but named arguments must come after
positional (i.e. unnamed) arguments.
E.g. the filter `pluralize` takes two optional arguments: `sg` and `pl` (singular and plural),
which are `sg = ""` and `pl = "s"` by default.
E.g. the filter `pluralize` takes two optional arguments: `singular` and `plural`
which are `singular = ""` and `plural = "s"` by default.
If you are fine with the default empty string for the singular, and you only want to set a
specific plural, then you can call the filter like `dog{{ count | pluralize(pl = "gies") }}`.
specific plural, then you can call the filter like `dog{{ count | pluralize(plural = "gies") }}`.
### capitalize
[#capitalize]: #capitalize
@ -415,7 +415,7 @@ hello
```jinja
{{ integer | pluralize }}
{{ integer | pluralize([sg = ""], [pl = "s"]) }}
{{ integer | pluralize([singular = ""], [plural = "s"]) }}
```
<hr style="clear:both; border:0; border-bottom:1pt solid currentColor">

View File

@ -29,7 +29,7 @@ fn test_pluralize_two_positional_args() {
fn test_pluralize_positional_and_named() {
#[derive(Template)]
#[template(
source = r#"I have {{ count }} butterfl{{ count | pluralize("y", pl = "ies") }}."#,
source = r#"I have {{ count }} butterfl{{ count | pluralize("y", plural = "ies") }}."#,
ext = "txt"
)]
struct CountButterflies {
@ -54,7 +54,7 @@ fn test_pluralize_positional_and_named() {
fn test_pluralize_named_reordered() {
#[derive(Template)]
#[template(
source = r#"I have {{ count }} butterfl{{ count | pluralize(pl = "ies", sg = "y") }}."#,
source = r#"I have {{ count }} butterfl{{ count | pluralize(plural = "ies", singular = "y") }}."#,
ext = "txt"
)]
struct CountButterflies {
@ -79,7 +79,7 @@ fn test_pluralize_named_reordered() {
fn test_pluralize_defaulted_and_named() {
#[derive(Template)]
#[template(
source = r#"I have {{ count }} potato{{ count | pluralize(pl = "es") }}."#,
source = r#"I have {{ count }} potato{{ count | pluralize(plural = "es") }}."#,
ext = "txt"
)]
struct CountPotatoes {

View File

@ -2,7 +2,7 @@ use askama::Template;
#[derive(Template)]
#[template(
source = r#"I have {{ count }} butterfl{{ count | pluralize(pl = "ies", "y") }}."#,
source = r#"I have {{ count }} butterfl{{ count | pluralize(plural = "ies", "y") }}."#,
ext = "txt"
)]
struct PositionalAfterNamed {
@ -11,7 +11,7 @@ struct PositionalAfterNamed {
#[derive(Template)]
#[template(
source = r#"I have {{ count }} butterfl{{ count | pluralize(pl = "y", pl = "ies") }}."#,
source = r#"I have {{ count }} butterfl{{ count | pluralize(plural = "y", plural = "ies") }}."#,
ext = "txt"
)]
struct NamedRepeated {
@ -20,7 +20,7 @@ struct NamedRepeated {
#[derive(Template)]
#[template(
source = r#"I have {{ count }} butterfl{{ count | pluralize("y", sg = "ies") }}."#,
source = r#"I have {{ count }} butterfl{{ count | pluralize("y", pl = "ies") }}."#,
ext = "txt"
)]
struct NamedButAlreadyPositional {
@ -29,7 +29,7 @@ struct NamedButAlreadyPositional {
#[derive(Template)]
#[template(
source = r#"I have {{ count }} butterfl{{ count | pluralize("y", plural = "ies") }}."#,
source = r#"I have {{ count }} butterfl{{ count | pluralize("y", sg = "ies") }}."#,
ext = "txt"
)]
struct NoSuchNamedArgument {

View File

@ -1,34 +1,34 @@
error: named arguments must always be passed last
--> <source attribute>:1:47
"(pl = \"ies\", \"y\") }}."
"(plural = \"ies\", \"y\") }}."
--> tests/ui/named_filter_arguments.rs:5:14
|
5 | source = r#"I have {{ count }} butterfl{{ count | pluralize(pl = "ies", "y") }}."#,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 | source = r#"I have {{ count }} butterfl{{ count | pluralize(plural = "ies", "y") }}."#,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: named argument `pl` was passed more than once
error: named argument `plural` was passed more than once
--> <source attribute>:1:47
"(pl = \"y\", pl = \"ies\") }}."
"(plural = \"y\", plural = \"ies\") }}."
--> tests/ui/named_filter_arguments.rs:14:14
|
14 | source = r#"I have {{ count }} butterfl{{ count | pluralize(pl = "y", pl = "ies") }}."#,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14 | source = r#"I have {{ count }} butterfl{{ count | pluralize(plural = "y", plural = "ies") }}."#,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `sg` argument to `pluralize` filter was already set; its arguments are: ([sg], [pl])
error: `pluralize` filter does not have an argument `pl`; its arguments are: ([singular], [plural])
--> NamedButAlreadyPositional.txt:1:47
"(\"y\", sg = \"ies\") }}."
"(\"y\", pl = \"ies\") }}."
--> tests/ui/named_filter_arguments.rs:23:14
|
23 | source = r#"I have {{ count }} butterfl{{ count | pluralize("y", sg = "ies") }}."#,
23 | source = r#"I have {{ count }} butterfl{{ count | pluralize("y", pl = "ies") }}."#,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `pluralize` filter does not have an argument `plural`; its arguments are: ([sg], [pl])
error: `pluralize` filter does not have an argument `sg`; its arguments are: ([singular], [plural])
--> NoSuchNamedArgument.txt:1:47
"(\"y\", plural = \"ies\") }}."
"(\"y\", sg = \"ies\") }}."
--> tests/ui/named_filter_arguments.rs:32:14
|
32 | source = r#"I have {{ count }} butterfl{{ count | pluralize("y", plural = "ies") }}."#,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32 | source = r#"I have {{ count }} butterfl{{ count | pluralize("y", sg = "ies") }}."#,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `uppercase` filter does not have any arguments
--> NamedArgumentButNoArgumentExpected.txt:1:30