Opened 10 years ago

Closed 9 years ago

#24230 closed New feature (fixed)

Add language name translated into active language to LANG_INFO dictionary

Reported by: Tomáš Ehrlich Owned by: Tomáš Ehrlich
Component: Internationalization Version: dev
Severity: Normal Keywords: filter tag translated language lang_code
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

get_language_info tag returns english name and local name of language:

language.local_name == česky
language.name == Czech

Neither depends on active language, but sometimes there's need for translated language name, ex. tchèque (in French). The only way how to do it right now is to take the english name and run it through gettext since Django already has all languages translated.

This would be very handy filter tag:

@register.filter
def language_translated(code):
    """
    Return language name translated into active language
    """

    name = translation.get_language_info(code)['name'].capitalize()
    return translation.gettext(name)

Maybe we could also extend dictionary returned by the get_language_info tag with name_translated to keep API consistent. All keys from get_language_info have matching filter variants (language_name, language_name_local and language_bidi).

Change History (5)

comment:1 by Wim Feijen, 10 years ago

Triage Stage: UnreviewedAccepted

Accepted because not all people are English.

comment:2 by Tomáš Ehrlich, 10 years ago

Has patch: set
Needs documentation: set
Needs tests: set
Owner: changed from nobody to Tomáš Ehrlich
Status: newassigned
Summary: Filter: language_translated returns translated name of languageAdd language name translated into active language to LANG_INFO dictionary

Added PR https://github.com/django/django/pull/3997 with proposal.

I'm not sure if we should name it name_translated. It's a bit log and it would make sense to simply translate name directly. However, that would be backward incompatible. Add new item to LANG_INFO dictionary is less invasive.

Missing documentation update and tests for filter.

comment:3 by Claude Paroz, 10 years ago

Needs tests: unset

comment:4 by Tomáš Ehrlich, 9 years ago

Needs documentation: unset

Documentation updated, but there's some build error. I can't see it now, the page is blocked at Cardiff University

comment:5 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 002b3d8:

Fixed #24230 -- Added translated language name for i18n template tag/filter.

Note: See TracTickets for help on using tickets.
Back to Top