Code

#20070 closed New feature (duplicate)

LOCALE_PATHS doesn't support "external" translations

Reported by: nahuel Owned by: nobody
Component: Internationalization Version: 1.5
Severity: Normal Keywords:
Cc: nahuel, bmispelon@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm trying to use LOCALE_PATHS to integrate translations from pycountry, but as I read in the django documentation, django is looking for a django.mo in the LOCALE_PATHS directories.
This is too much restrictive and force developer to make a copy of a sub-project translations or to deal with the django internal API to add the translations manually.
It should be great that django allows to read in any .mo/.po files explicitly specified or not.

Attachments (0)

Change History (6)

comment:1 Changed 13 months ago by aaugustin

  • Component changed from Translations to Internationalization
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 13 months ago by nahuel

  • Cc nahuel added

comment:3 Changed 13 months ago by aaugustin

The feature requested here is a convenient way to load in Django's i18n implementation .mo files from other software and not called django.mo.

Here's the workaround found by the OP:

import pycountry, gettext
from django.utils.translation import get_language, to_locale, trans_real
language = get_language()
locale = to_locale(get_language())
res = trans_real._translations.get(language, None)
t = gettext.translation("iso639", pycountry.LOCALES_DIR, [locale], class_=trans_real.DjangoTranslation)
t.set_language(language)
res.merge(t)

comment:4 Changed 13 months ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

I've heard this request a few times, seems pretty reasonable. --> accepted.

comment:5 follow-up: Changed 12 months ago by bmispelon

  • Cc bmispelon@… added

How does this ticket relate to #6376?
I'm not too familiar with gettext but it seems these two tickets are basically asking for the same feature, no?

comment:6 in reply to: ↑ 5 Changed 10 months ago by ramiro

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

Replying to bmispelon:

How does this ticket relate to #6376?
I'm not too familiar with gettext but it seems these two tickets are basically asking for the same feature, no?

Yes it's the same idea. Thanks bmispelon for catching this.

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.