Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Customizing Django Templates Template Tags and Filters Using Template Libraries

Lukas Baumgartner
Lukas Baumgartner
14,817 Points

Pluralize for German

Hey, is there any way to make the |pluralize filter work for the German language?

I changed the language in the layout.html file to german, but it still adds just an 's' to the word. Pluralizing words in german is somewhat more difficult then in english, so I'm wondering if it's at all possible.

For example: en: step --> steps | ger: Schritt --> Schritte en: apple --> apples | ger: Apfel --> Äpfel

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hallo Lukas,

From the django documentation on pluralize:

pluralize

Returns a plural suffix if the value is not 1. By default, this suffix is 's'.

Example:

You have `{{ num_messages }} message{{ num_messages|pluralize }}`.

If num_messages is 1, the output will be You have 1 message. If num_messages is 2 the output will be You have 2 messages.

For words that require a suffix other than 's', you can provide an alternate suffix as a parameter to the filter.

Example:

You have {{ num_walruses }} walrus{{ num_walruses|pluralize:"es" }}.

For words that don’t pluralize by simple suffix, you can specify both a singular and plural suffix, separated by a comma.

Example:

You have {{ num_cherries }} cherr{{ num_cherries|pluralize:"y,ies" }}.

So, for Schritt --> Schritte, you would use that second example:

Du hast {{ num_steps }} Schritt{{ num_steps|pluralize:"e" }}

And for Apfel --> Äpfel, you have to write out the whole word:

Du hast {{ num_apples }} {{ num_apples|pluralize:"Apfel,Äpfel" }}.

Hope that makes sense!

Prost! :beers:

-Greg

Lukas Baumgartner
Lukas Baumgartner
14,817 Points

Okay, yeah that's what i found too.

Thougth there might be an easier way to to that.

Thank you :)