0
votes

I want to translate in any language django permission names. To do this i extend django.contrib.auth.models.Permission model in django like this :

class ExtendedPermission(Permission):
    translation_name = models.CharField(_('translation_name'),max_length=255)

Then i want to update this table in management commands. First 'name' field taken from Permission model, than it must be translated into another language for instance tr to use in ExtendedPermission model as translation_name field.This function in management/commands:

def try_translate(self,permission):
    translation.activate(settings.LANGUAGE_CODE)
    translation.activate('tr')
    translated_str =translation.ugettext(permission)
    translation.deactivate()
    return translated_str

When run this command the variable does not appear in .po file.But if i give string that i want to translate like this : ugettext("name")

msgid = "name" appears in .po file and i can edit msgstr but i can not get the translated msgstr from .mo file with using ugettext.

I add 'django.middleware.locale.LocaleMiddleware', to settings file.I also run commands makemessages and compilemessages.

1
and no 'fuzzy' command around the string that i want to translate.xxx34

1 Answers

0
votes

As I understand it, the Django i18n support works off static data, which you pre-generate running makemessages. It looks for _(), {% trains %}, etc, which require static strings.

If permissions is not know statically ( e.g. Without reading a database ), then it cannot process it during makemessages.