Найти - Пользователи
Полная версия: trans в yesno и default_if_none
Начало » Django » trans в yesno и default_if_none
1
Remoteroot
Подскажите, как правильно перевести с помочу trans слово “Неизвестно” в данном коде?
{{ institution.city|default_if_none:"Неизвестно" }}
Аналогично и для yesno:
{{ hotel.cafe_availability|yesno:"Да, Нет, Неизвестно" }}
tmt
Обращаемся к документации. http://docs.djangoproject.com/en/1.2/topics/i18n/internationalization/#other-tags

Translation hooks are also available within any template block tag that accepts constant strings. In those cases, just use _() syntax to specify a translation string:

{% some_special_tag _("Page not found") value|yesno:_("yes,no") %}
In this case, both the tag and the filter will see the already-translated string, so they don't need to be aware of translations.

Note
In this example, the translation infrastructure will be passed the string “yes,no”, not the individual strings “yes” and “no”. The translated string will need to contain the comma so that the filter parsing code knows how to split up the arguments. For example, a German translator might translate the string “yes,no” as “ja,nein” (keeping the comma intact).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB