Override default Django translations

前端 未结 4 1351
终归单人心
终归单人心 2020-12-01 13:37

I have a template with this:

{% trans \"Log out\" %}

This is translated automatically by Django to Spanish as Terminar sesión. How

4条回答
  •  情深已故
    2020-12-01 13:51

    Based on Robert Lujo answer, his alternative is totally working. And IMO simpler (keep the overriden locales in a special .po file only). Here are the steps:

    • Add an extra path to the LOCALE_PATHS Django settings.

      • LOCALE_PATHS = (
        # the default one, where the makemessages command will generate the files os.path.join(BASE_DIR, 'myproject', 'locale'),
        # our new, extended locale dir
        os.path.join(BASE_DIR, 'myproject', 'locale_extra'), )

    • find the original Django (or 3rd party) string to be translated

      • ex.: "recent actions" for the Django admin 'recent actions' block
    • Add the new .po file "myproject/locale_extra/en/LC_MESSAGES/django.po" with the alternative translation :
      • msgid "Recent actions"
        msgstr "Last actions"

    • Compile your messages as usual

提交回复
热议问题