Code

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#3832 closed (duplicate)

i18n of application names in admin

Reported by: omat@… Owned by: adrian
Component: contrib.admin Version: master
Severity: Keywords: admin i18n
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This may be trivial, but, the admin application does not allow internationalization of the application names, it always uses the name in the INSTALLED_APPS setting.

If the line 21 of contrib/admin/templatetags/adminapplist.py is changed to:

app_label = _(app_models[0]._meta.app_label)

users will have control on the application name displayed in the admin application by i18n.

Attachments (0)

Change History (3)

comment:1 Changed 7 years ago by Simon G. <dev@…>

  • Component changed from Contrib apps to Admin interface
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by mtredinnick

  • Resolution set to duplicate
  • Status changed from new to closed

This has come up before (#1668). The part you identify (doing the string exchange) is not the difficult part of this problem. The hard part is how to extract the application names in the first place. Somebody would need to modify the gettext extraction program to work out the application names. For a number of practical and security reasons, gettext should generally never run any code in the application, so you can't just import the modules and use Python introspection, unfortunately. You also can't expect everybody to have to write their module names out by hand: having an arbitrary technical phrase such as the module name translated isn't important enough to require that to be done by default.

I suspect there are solutions to this problem (maybe using the Python compile function and bytecode inspection), but it's not a trivial fix.

I'm going to close this as a dupe of #1668, but I wanted to explain what the real problem that has to be solved here is.

By the way, if you want translation of specific model names to happen, write something like

    class Meta:
        verbose_name = _("SuperWidget")
        verbose_name_plural = _("SuperWidgets")

in your code.

comment:3 Changed 7 years ago by simonbun <simonbun@…>

For what it's worth, there's a trivial workaround for this problem.

1) put your app name with gettext_lazy call in your model file. I just put it at the top of my models.py file: _('myappname')
2) override the admin's index.html template and change out

<caption>{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</caption>

with

<caption>{% trans app.name %}</caption>

in the app_list loop.

Hackish & not so elegant, but it does work.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.