i18n')), my view is: django
2 Answers Sorted by: 78 From the docs, if you have a template variable called num_countries, you could just write something like: countr { { num_countries|pluralize:"y,ies" }} Share Improve this answer Follow answered Nov 15, 2010 at 14:42 Spike 5,080 5 33 48 Yes, look at the note here docs
They tell Django: "This text should be translated into the end user's language, if a translation for this text is available in that language
Example: A set of Django template filters useful for adding a "human touch" to data
simple_tag def plural (n_str, singular, plural=None): """ A better pluralization template tag
You can handle this by using the pluralize filter
Run Example » For words with different single and plural endings, you can add both by separating them by a comma: Example It looks like this
If a plural suffix isn't specified pluralize defaults to 's'
This simple version only works with template variable since we will use blocktrans for strings
translation import pgettext class News (models
We can add an app using the startapp command, so let's add the posts app now
For example: Person
views
I am using Django and cannot get the correct plural form in my template using French, whatever text I use in my blocktrans tag
urls
The first template is working: I select the language, click the 'go' button (boring) and the page is traslated without changes in url (off course verbose_name of meta data for models should allow dynamical translation based on a number of elements through ungettext and not just two possibilities of verbose_name and verbose_name_plural which is not enough for languages with complex plural forms
conf import settings if settings
translation Here is a simple example to reproduce the bug: template file: index
How do I get django to realize that the singular form of countries is country and not countrie
In English it's just 'group' for singular and 'groups' for plural, so verbose_name, and verbose_name_plural is enough
Add following line at the top of your template: {% load i18n %} After you fix that, note that for a blocktrans tag after count a variable, whose value will serve for plural detection, should be specified, so you probably need something like
So we can access Model
verbose_name_raw will return the original text in your sources without any translation
The pluralize filter returns the empty string in such cases, for instance when it receives more than two forms (singular, plural)
The @cached_property decorator caches the result of a method with a single self argument as a property
translation
py, I assign features for templates: 1 Answer
also should have a short name and it can be a plural and singular name
This part is redundant since you already encapsulate with the same condition: and ins
Overview; Download; I had emailed the author of plural_to_python (linked in the thread) when I found the link without any answer for now
Django's pluralization support is fine for English, since we only have two number forms, singular and plural
Django follows the Model View Template (MVT) architecture
Django supports this peculiarity and specifies plural form using this algorithm (django
Django ships built-in backends for its own template system, creatively called the Django template language (DTL), and for the popular alternative Jinja2
vs
Sample input dict: data = {'tree': 1, 'bush': 2, 'flower': 3, 'cactus': 0} Sample output str: 'My garden has 1 tree, 2 bushes, 3 flowers, and 0 cacti'
The following English grammar rules apply when turning a singular noun into a regular Django templates use their own mini-language that's inspired by Python
You then pass the current namespace as the current_app argument, and the hard-coded app_name will resolve to the current namespace
Django Discord Server Join the Django Discord Community
For this example,"old_app" is our old name and "new_app" is our new name"
Update all imports referencing the old folder to reference the new
Break long lines using parentheses and indent continuation lines by 4 spaces
You can pass arguments to your custom tag, process them a bit in Python, then bounce back to a template
Suppose you want
Tips and Tricks Django Django's pluralize template filter Django tip: Sometimes you need to use the single or plural form based on the number you're displaying
In Django templates, there are two ways to solve similar problems: pluralize filter
You can specify another suffix with the suffix argument: Example You have { { x }} kiss{ {
By default admin will show the name of your model appended with an “s”, aka the plural form of your model
No, in English zero uses the plural form, see: The current behavior is correct and
Namely, it should be short, all-lowercase, and not include numbers, dashes, periods, spaces, or special characters