Django

Code

Ticket #5494 (assigned)

Opened 10 months ago

Last modified 7 months ago

javascript_catalog generic view only search catalogs in application/locale and not in project/locale

Reported by: anonymous Assigned to: msaelices (accepted)
Milestone: Component: Internationalization
Version: SVN Keywords: javascript i18n
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

In i18n docs said that message files are searched in (fragment copied from i18n.txt):

    * The root ``django`` directory (not a Subversion checkout, but the one
      that is linked-to via ``$PYTHONPATH`` or is located somewhere on that
      path).
    * The root directory of your Django project.
    * The root directory of your Django app.

But it doesn't work for javascript catalogs. If you have a project named blogproj and an aplication named blog , you cannot put javascript catalogs in blogproj/locale . This urls.py doesn't work:

js_info_dict = {
    'domain': 'djangojs',
    'packages': ('blogproj',),
}

urlpatterns = patterns('',
    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),

But if you have message files in blogproject/blog/locale , it works with this urls.py :

js_info_dict = {
    'domain': 'djangojs',
    'packages': ('blogproj.blog',),
}

urlpatterns = patterns('',
    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),

Attachments

jscatalog.diff (1.2 kB) - added by msaelices on 09/15/07 11:58:49.
A patch that fixes bug
root-locale-js-catalog.diff (1.1 kB) - added by trevor@caira.com on 12/06/07 23:34:47.
Patch that supplies the option of specifying an empty string as a package for js l10n.

Change History

09/15/07 11:36:26 changed by msaelices

  • owner changed from nobody to msaelices.
  • needs_better_patch changed.
  • status changed from new to assigned.
  • needs_tests changed.
  • needs_docs changed.

09/15/07 11:36:39 changed by msaelices

I'll try to fix it

09/15/07 11:36:56 changed by msaelices

  • stage changed from Unreviewed to Accepted.

09/15/07 11:58:49 changed by msaelices

  • attachment jscatalog.diff added.

A patch that fixes bug

09/15/07 11:59:08 changed by msaelices

  • has_patch set to 1.

12/01/07 11:58:45 changed by msaelices

  • stage changed from Accepted to Ready for checkin.

12/06/07 23:34:47 changed by trevor@caira.com

  • attachment root-locale-js-catalog.diff added.

Patch that supplies the option of specifying an empty string as a package for js l10n.

12/06/07 23:36:23 changed by trevor@caira.com

The regular localization has the feature of not having to specify the project name. Of course, the javascript localization has to obey the constraint that only requested message catalogs are made available, so I propose a special package name "" (empty string) that refers to the root locale dir, as in

    globalpath = os.path.join(os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')

from the regular translation function (django gettext domain). Thus, one could specify a url like this:

    url(r'^jsi18n/$', javascript_catalog, {'packages': ('', 'apps.blog')}, name='jsi18n'),

This would enable the root catalog in addition to the apps.blog catalog. I've attached a patch against trunk revision 6739 to enable this functionality.

12/17/07 05:20:03 changed by mtredinnick

  • needs_better_patch set to 1.
  • stage changed from Ready for checkin to Accepted.

I think there are problems with both of these solutions. Manuel's one assumes the settings file is in the project directory, which is not really a good assumption. Trevor's solution introduces a string that isn't very Pythonic (there isn't a lot of precedent for the empty string meaning "here" in Python imports).

Let's go for a simple solution here. We're getting into trouble because the i18n framework is trying to enforce the fact that things have to be in INSTALLED_APPS or one of a few special cases. Instead, let's allow any module to specified in the values for the package key, providing that module contains a locale/ subdirectory.

The example given, then becomes

{'packages': ('blogproj', 'blogproj.blog')}

Yes, this means you could potentially include an entirely random translation file. That's relatively harmless and might even make things easier (by imposing less constraints) in some cases.


Add/Change #5494 (javascript_catalog generic view only search catalogs in application/locale and not in project/locale)




Change Properties
Action