Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5494, #10765, #14924 -- Modified the order in which translatio…

…ns are read when composing the final translation to offer at runtime.

This is slightly backward-incompatible (could result in changed final translations for literals appearing multiple times in different .po files but with different translations).

Translations are now read in the following order (from lower to higher priority):

For the 'django' gettext domain:

 * Django translations
 * INSTALLED_APPS apps translations (with the ones listed first having higher priority)
 * settings/project path translations (deprecated, see below)
 * LOCALE_PATHS translations (with the ones listed first having higher priority)

For the 'djangojs' gettext domain:

 * Python modules whose names are passed to the javascript_catalog view
 * LOCALE_PATHS translations (with the ones listed first having higher priority, previously they weren't included)

Also, automatic loading of translations from the 'locale' subdir of the settings/project path is now deprecated.

Thanks to vanschelven, vbmendes and an anonymous user for reporting issues, to vanschelven, Claude Paroz and an anonymous contributor for their initial work on fixes and to Jannis  Leidel and Claude for review and discussion.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15441 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f6e38f3800f769b6f03799a1792b2cb1a9f42c32 1 parent 5718a67
Ramiro Morales authored February 07, 2011
17  django/utils/translation/__init__.py
... ...
@@ -1,8 +1,11 @@
1 1
 """
2 2
 Internationalization support.
3 3
 """
  4
+from os import path
  5
+
4 6
 from django.utils.encoding import force_unicode
5  
-from django.utils.functional import lazy, curry
  7
+from django.utils.functional import lazy
  8
+from django.utils.importlib import import_module
6 9
 
7 10
 
8 11
 __all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext',
@@ -33,10 +36,22 @@ class Trans(object):
33 36
     performance effect, as access to the function goes the normal path,
34 37
     instead of using __getattr__.
35 38
     """
  39
+
36 40
     def __getattr__(self, real_name):
37 41
         from django.conf import settings
38 42
         if settings.USE_I18N:
39 43
             from django.utils.translation import trans_real as trans
  44
+
  45
+            if settings.SETTINGS_MODULE is not None:
  46
+                import warnings
  47
+                parts = settings.SETTINGS_MODULE.split('.')
  48
+                project = import_module(parts[0])
  49
+                if path.isdir(path.join(path.dirname(project.__file__), 'locale')):
  50
+                    warnings.warn(
  51
+                        "Translations in the project directory aren't supported anymore. Use the LOCALE_PATHS setting instead.",
  52
+                        PendingDeprecationWarning
  53
+                    )
  54
+
40 55
         else:
41 56
             from django.utils.translation import trans_null as trans
42 57
         setattr(self, real_name, getattr(trans, real_name))
14  django/utils/translation/trans_real.py
@@ -125,12 +125,12 @@ def _fetch(lang, fallback=None):
125 125
 
126 126
         global _translations
127 127
 
128  
-        loc = to_locale(lang)
129  
-
130 128
         res = _translations.get(lang, None)
131 129
         if res is not None:
132 130
             return res
133 131
 
  132
+        loc = to_locale(lang)
  133
+
134 134
         def _translation(path):
135 135
             try:
136 136
                 t = gettext_module.translation('django', path, [loc], DjangoTranslation)
@@ -159,11 +159,7 @@ def _merge(path):
159 159
                     res.merge(t)
160 160
             return res
161 161
 
162  
-        for localepath in settings.LOCALE_PATHS:
163  
-            if os.path.isdir(localepath):
164  
-                res = _merge(localepath)
165  
-
166  
-        for appname in settings.INSTALLED_APPS:
  162
+        for appname in reversed(settings.INSTALLED_APPS):
167 163
             app = import_module(appname)
168 164
             apppath = os.path.join(os.path.dirname(app.__file__), 'locale')
169 165
 
@@ -173,6 +169,10 @@ def _merge(path):
173 169
         if projectpath and os.path.isdir(projectpath):
174 170
             res = _merge(projectpath)
175 171
 
  172
+        for localepath in reversed(settings.LOCALE_PATHS):
  173
+            if os.path.isdir(localepath):
  174
+                res = _merge(localepath)
  175
+
176 176
         if res is None:
177 177
             if fallback is not None:
178 178
                 res = fallback
7  django/views/i18n.py
@@ -193,11 +193,15 @@ def javascript_catalog(request, domain='djangojs', packages=None):
193 193
     paths = []
194 194
     en_selected = locale.startswith('en')
195 195
     en_catalog_missing = True
196  
-    # first load all english languages files for defaults
  196
+    # paths of requested packages
197 197
     for package in packages:
198 198
         p = importlib.import_module(package)
199 199
         path = os.path.join(os.path.dirname(p.__file__), 'locale')
200 200
         paths.append(path)
  201
+    # add the filesystem paths listed in the LOCALE_PATHS setting
  202
+    paths.extend(list(reversed(settings.LOCALE_PATHS)))
  203
+    # first load all english languages files for defaults
  204
+    for path in paths:
201 205
         try:
202 206
             catalog = gettext_module.translation(domain, path, ['en'])
203 207
             t.update(catalog._catalog)
@@ -275,4 +279,3 @@ def javascript_catalog(request, domain='djangojs', packages=None):
275 279
     src.append(LibFormatFoot)
276 280
     src = ''.join(src)
277 281
     return http.HttpResponse(src, 'text/javascript')
278  
-
66  docs/howto/i18n.txt
@@ -4,15 +4,36 @@
4 4
 Using internationalization in your own projects
5 5
 ===============================================
6 6
 
7  
-At runtime, Django looks for translations by following this algorithm:
8  
-
9  
-    * First, it looks for a ``locale`` directory in the directory containing
10  
-      your settings file.
11  
-    * Second, it looks for a ``locale`` directory in the project directory.
12  
-    * Third, it looks for a ``locale`` directory in each of the installed apps.
13  
-      It does this in the reverse order of INSTALLED_APPS
14  
-    * Finally, it checks the Django-provided base translation in
15  
-      ``django/conf/locale``.
  7
+At runtime, Django builds an in-memory unified catalog of literals-translations.
  8
+To achieve this it looks for translations by following this algorithm regarding
  9
+the order in which it examines the different file paths to load the compiled
  10
+:term:`message files <message file>` (``.mo``) and the precedence of multiple
  11
+translations for the same literal:
  12
+
  13
+    1. The directories listed in :setting:`LOCALE_PATHS` have the highest
  14
+       precedence, with the ones appearing first having higher precedence than
  15
+       the ones appearing later.
  16
+    2. Then, it looks for and uses if it exists a ``locale`` directory in each
  17
+       of the installed apps listed in :setting:`INSTALLED_APPS`.  The ones
  18
+       appearing first have higher precedence than the ones appearing later.
  19
+    3. Then, it looks for a ``locale`` directory in the project directory, or
  20
+       more accurately, in the directory containing your settings file.
  21
+    4. Finally, the Django-provided base translation in ``django/conf/locale``
  22
+       is used as a fallback.
  23
+
  24
+.. deprecated:: 1.3
  25
+    Lookup in the ``locale`` subdirectory of the directory containing your
  26
+    settings file (item 3 above) is deprecated since the 1.3 release and will be
  27
+    removed in Django 1.5. You can use the :setting:`LOCALE_PATHS` setting
  28
+    instead, by listing the absolute filesystem path of such ``locale``
  29
+    directory in the setting value.
  30
+
  31
+.. seealso::
  32
+
  33
+    The translations for literals included in JavaScript assets are looked up
  34
+    following a similar but not identical algorithm. See the
  35
+    :ref:`javascript_catalog view documentation <javascript_catalog-view>` for
  36
+    more details.
16 37
 
17 38
 In all cases the name of the directory containing the translation is expected to
18 39
 be named using :term:`locale name` notation. E.g. ``de``, ``pt_BR``, ``es_AR``,
@@ -20,8 +41,8 @@ etc.
20 41
 
21 42
 This way, you can write applications that include their own translations, and
22 43
 you can override base translations in your project path. Or, you can just build
23  
-a big project out of several apps and put all translations into one big project
24  
-message file. The choice is yours.
  44
+a big project out of several apps and put all translations into one big common
  45
+message file specific to the project you are composing. The choice is yours.
25 46
 
26 47
 .. note::
27 48
 
@@ -34,10 +55,11 @@ message file. The choice is yours.
34 55
 
35 56
 All message file repositories are structured the same way. They are:
36 57
 
37  
-    * ``$APPPATH/locale/<language>/LC_MESSAGES/django.(po|mo)``
38  
-    * ``$PROJECTPATH/locale/<language>/LC_MESSAGES/django.(po|mo)``
39 58
     * All paths listed in ``LOCALE_PATHS`` in your settings file are
40  
-      searched in that order for ``<language>/LC_MESSAGES/django.(po|mo)``
  59
+      searched for ``<language>/LC_MESSAGES/django.(po|mo)``
  60
+    * ``$PROJECTPATH/locale/<language>/LC_MESSAGES/django.(po|mo)`` --
  61
+      deprecated, see above.
  62
+    * ``$APPPATH/locale/<language>/LC_MESSAGES/django.(po|mo)``
41 63
     * ``$PYTHONPATH/django/conf/locale/<language>/LC_MESSAGES/django.(po|mo)``
42 64
 
43 65
 To create message files, you use the :djadmin:`django-admin.py makemessages <makemessages>`
@@ -50,22 +72,18 @@ You can also run ``django-admin.py compilemessages --settings=path.to.settings``
50 72
 to make the compiler process all the directories in your :setting:`LOCALE_PATHS`
51 73
 setting.
52 74
 
53  
-Application message files are a bit complicated to discover -- they need the
54  
-:class:`~django.middleware.locale.LocaleMiddleware`. If you don't use the
55  
-middleware, only the Django message files and project message files will be
56  
-installed and available at runtime.
57  
-
58 75
 Finally, you should give some thought to the structure of your translation
59 76
 files. If your applications need to be delivered to other users and will
60 77
 be used in other projects, you might want to use app-specific translations.
61  
-But using app-specific translations and project translations could produce
62  
-weird problems with ``makemessages``: It will traverse all directories below
63  
-the current path and so might put message IDs into the project message file
64  
-that are already in application message files.
  78
+But using app-specific translations and project-specific translations could
  79
+produce weird problems with ``makemessages``: It will traverse all directories
  80
+below the current path and so might put message IDs into a unified, common
  81
+message file for the current project that are already in application message
  82
+files.
65 83
 
66 84
 The easiest way out is to store applications that are not part of the project
67 85
 (and so carry their own translations) outside the project tree. That way,
68  
-``django-admin.py makemessages`` on the project level will only translate
  86
+``django-admin.py makemessages``, when ran on a project level will only extract
69 87
 strings that are connected to your explicit project and not strings that are
70 88
 distributed independently.
71 89
 
11  docs/ref/settings.txt
@@ -1149,6 +1149,17 @@ Default: ``()`` (Empty tuple)
1149 1149
 A tuple of directories where Django looks for translation files.
1150 1150
 See :ref:`using-translations-in-your-own-projects`.
1151 1151
 
  1152
+Example::
  1153
+
  1154
+    LOCALE_PATHS = (
  1155
+        '/home/www/project/common_files/locale',
  1156
+        '/var/local/translations/locale'
  1157
+    )
  1158
+
  1159
+Note that in the paths you add to the value of this setting, if you have the
  1160
+typical ``/path/to/locale/xx/LC_MESSAGES`` hierarchy, you should use the path to
  1161
+the ``locale`` directory (i.e. ``'/path/to/locale'``).
  1162
+
1152 1163
 .. setting:: LOGGING
1153 1164
 
1154 1165
 LOGGING
81  docs/releases/1.3.txt
@@ -454,6 +454,52 @@ should either insert it using :ref:`test fixtures
454 454
 <topics-testing-fixtures>`, or using the ``setUp()`` method of your
455 455
 test case.
456 456
 
  457
+Changed priority of translation loading
  458
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  459
+
  460
+Work has been done to homogeneize, simplify, rationalize and properly document
  461
+the algorithm used by Django at runtime to build translations from the
  462
+differents translations found on disk, namely:
  463
+
  464
+For translatable literals found in Python code and templates (``'django'``
  465
+gettext domain):
  466
+
  467
+ * Priorities of translations included with applications listed in the
  468
+   :setting:`INSTALLED_APPS` setting were changed. To provide a behavior
  469
+   consistent with other parts of Django that also use such setting (templates,
  470
+   etc.) now, when building the translation that will be made available, the
  471
+   apps listed first have higher precedence than the ones listed later.
  472
+
  473
+ * Now it is possible to override the translations shipped with applications by
  474
+   using the :setting:`LOCALE_PATHS` setting whose translations have now higher
  475
+   precedence than the translations of ``INSTALLED_APPS`` applications.
  476
+   The relative priority among the values listed in this setting has also been
  477
+   modified so the paths listed first have higher precedence than the
  478
+   ones listed later.
  479
+
  480
+ * The ``locale`` subdirectory of the directory containing the settings, that
  481
+   usually coincides with and is know as the *project directory* is being
  482
+   deprecated in this release as a source of translations. (the precedence of
  483
+   these translations is intermediate between applications and ``LOCALE_PATHS``
  484
+   translations). See the `corresponding deprecated features section`_
  485
+   of this document.
  486
+
  487
+For translatable literals found in Javascript code (``'djangojs'`` gettext
  488
+domain):
  489
+
  490
+ * Similarly to the ``'django'`` domain translations: Overriding of
  491
+   translations shipped with applications by using the :setting:`LOCALE_PATHS`
  492
+   setting is now possible for this domain too. These translations have higher
  493
+   precedence than the translations of Python packages passed to the
  494
+   :ref:`javascript_catalog view <javascript_catalog-view>`.  Paths listed first
  495
+   have higher precedence than the ones listed later.
  496
+
  497
+ * Translations under the ``locale`` sbdirectory of the *project directory* have
  498
+   never been taken in account for JavaScript translations and remain in the
  499
+   same situation considering the deprecation of such location.
  500
+
  501
+.. _corresponding deprecated features section: loading_of_translations_from_the_project_directory_
  502
+
457 503
 .. _deprecated-features-1.3:
458 504
 
459 505
 Features deprecated in 1.3
@@ -631,3 +677,38 @@ Previously, ``django.http`` exposed an undocumented ``CompatCookie`` class,
631 677
 which was a bug-fix wrapper around the standard library ``SimpleCookie``. As the
632 678
 fixes are moving upstream, this is now deprecated - you should use ``from
633 679
 django.http import SimpleCookie`` instead.
  680
+
  681
+.. _loading_of_translations_from_the_project_directory:
  682
+
  683
+Loading of translations from the project directory
  684
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  685
+
  686
+This release of Django starts the deprecation process for inclusion of
  687
+translations located under the *project path* in the translation building
  688
+process performed at runtime. The :setting:`LOCALE_PATHS` setting can be used
  689
+for the same task by including in it the filesystem path to the ``locale``
  690
+directory containing project-level translations.
  691
+
  692
+Rationale for this decision:
  693
+
  694
+ * The *project path* has always been a loosely defined concept (actually, the
  695
+   directory used for locating project-level translations is the directory
  696
+   containing the settings module) and there has been a shift in other parts
  697
+   of the framework to stop using it as a reference for location of assets at
  698
+   runtime.
  699
+
  700
+ * Detection of the ``locale`` subdirectory tends to fail when the deployment
  701
+   scenario is more complex than the basic one. e.g. it fails when the settings
  702
+   module is a directory (ticket #10765).
  703
+
  704
+ * Potential for strange development- and deployment-time problems like the
  705
+   fact that the ``project_dir/locale/`` subdir can generate spurious error
  706
+   messages when the project directory is included in the Python path (default
  707
+   behavior of ``manage.py runserver``) and then it clashes with the equally
  708
+   named standard library module, this is a typical warming message::
  709
+
  710
+     /usr/lib/python2.6/gettext.py:49: ImportWarning: Not importing directory '/path/to/project/dir/locale': missing __init__.py.
  711
+     import locale, copy, os, re, struct, sys
  712
+
  713
+ * This location wasn't included in the translation building process for
  714
+   JavaScript literals.
40  docs/topics/i18n/deployment.txt
@@ -171,16 +171,36 @@ in ``request.LANGUAGE_CODE``.
171 171
 How Django discovers translations
172 172
 ---------------------------------
173 173
 
174  
-As described in :ref:`using-translations-in-your-own-projects`,
175  
-at runtime, Django looks for translations by following this algorithm:
176  
-
177  
-    * First, it looks for a ``locale`` directory in the directory containing
178  
-      your settings file.
179  
-    * Second, it looks for a ``locale`` directory in the project directory.
180  
-    * Third, it looks for a ``locale`` directory in each of the installed apps.
181  
-      It does this in the reverse order of INSTALLED_APPS
182  
-    * Finally, it checks the Django-provided base translation in
183  
-      ``django/conf/locale``.
  174
+As described in :ref:`using-translations-in-your-own-projects`, Django looks for
  175
+translations by following this algorithm regarding the order in which it
  176
+examines the different file paths to load the compiled :term:`message files
  177
+<message file>` (``.mo``) and the precedence of multiple translations for the
  178
+same literal:
  179
+
  180
+    1. The directories listed in :setting:`LOCALE_PATHS` have the highest
  181
+       precedence, with the ones appearing first having higher precedence than
  182
+       the ones appearing later.
  183
+    2. Then, it looks for and uses if it exists a ``locale`` directory in each
  184
+       of the installed apps listed in :setting:`INSTALLED_APPS`.  The ones
  185
+       appearing first have higher precedence than the ones appearing later.
  186
+    3. Then, it looks for a ``locale`` directory in the project directory, or
  187
+       more accurately, in the directory containing your settings file.
  188
+    4. Finally, the Django-provided base translation in ``django/conf/locale``
  189
+       is used as a fallback.
  190
+
  191
+.. deprecated:: 1.3
  192
+    Lookup in the ``locale`` subdirectory of the directory containing your
  193
+    settings file (item 3 above) is deprecated since the 1.3 release and will be
  194
+    removed in Django 1.5. You can use the :setting:`LOCALE_PATHS` setting
  195
+    instead, by listing the absolute filesystem path of such ``locale``
  196
+    directory in the setting value.
  197
+
  198
+.. seealso::
  199
+
  200
+    The translations for literals included in JavaScript assets are looked up
  201
+    following a similar but not identical algorithm. See the
  202
+    :ref:`javascript_catalog view documentation <javascript_catalog-view>` for
  203
+    more details.
184 204
 
185 205
 In all cases the name of the directory containing the translation is expected to
186 206
 be named using :term:`locale name` notation. E.g. ``de``, ``pt_BR``, ``es_AR``,
35  docs/topics/i18n/internationalization.txt
@@ -348,8 +348,6 @@ translation method!
348 348
 Working with lazy translation objects
349 349
 -------------------------------------
350 350
 
351  
-.. highlightlang:: python
352  
-
353 351
 Using ``ugettext_lazy()`` and ``ungettext_lazy()`` to mark strings in models
354 352
 and utility functions is a common operation. When you're working with these
355 353
 objects elsewhere in your code, you should ensure that you don't accidentally
@@ -633,6 +631,8 @@ There are also simple filters available for convenience:
633 631
 Specifying translation strings: In JavaScript code
634 632
 ==================================================
635 633
 
  634
+.. highlightlang:: python
  635
+
636 636
 Adding translations to JavaScript poses some problems:
637 637
 
638 638
     * JavaScript code doesn't have access to a ``gettext`` implementation.
@@ -647,6 +647,8 @@ Django provides an integrated solution for these problems: It passes the
647 647
 translations into JavaScript, so you can call ``gettext``, etc., from within
648 648
 JavaScript.
649 649
 
  650
+.. _javascript_catalog-view:
  651
+
650 652
 The ``javascript_catalog`` view
651 653
 -------------------------------
652 654
 
@@ -657,8 +659,9 @@ The ``javascript_catalog`` view
657 659
 The main solution to these problems is the :meth:`django.views.i18n.javascript_catalog`
658 660
 view, which sends out a JavaScript code library with functions that mimic the
659 661
 ``gettext`` interface, plus an array of translation strings. Those translation
660  
-strings are taken from the application, project or Django core, according to what
661  
-you specify in either the info_dict or the URL.
  662
+strings are taken from applications or Django core, according to what you
  663
+specify in either the info_dict or the URL. Paths listed in
  664
+:setting:`LOCALE_PATHS` are also included.
662 665
 
663 666
 You hook it up like this::
664 667
 
@@ -676,6 +679,11 @@ that contains a ``locale`` directory. If you specify multiple packages, all
676 679
 those catalogs are merged into one catalog. This is useful if you have
677 680
 JavaScript that uses strings from different applications.
678 681
 
  682
+The precedence of translations is such that the packages appearing later in the
  683
+``packages`` argument have higher precedence than the ones appearing at the
  684
+beginning, this is important in the case of clashing translations for the same
  685
+literal.
  686
+
679 687
 By default, the view uses the ``djangojs`` gettext domain. This can be
680 688
 changed by altering the ``domain`` argument.
681 689
 
@@ -691,10 +699,25 @@ different apps and this changes often and you don't want to pull in one big
691 699
 catalog file. As a security measure, these values can only be either
692 700
 ``django.conf`` or any package from the :setting:`INSTALLED_APPS` setting.
693 701
 
  702
+The JavaScript translations found in the paths listed in the
  703
+:setting:`LOCALE_PATHS` setting are also always included. To keep consistency
  704
+with the translations lookup order algorithm used for Python and templates, the
  705
+directories listed in :setting:`LOCALE_PATHS` have the highest precedence with
  706
+the ones appearing first having higher precedence than the ones appearing
  707
+later.
  708
+
  709
+.. versionchanged:: 1.3
  710
+    Directories listed in ``LOCALE_PATHS`` weren't included in the lookup
  711
+    algorithm until version 1.3.
  712
+
694 713
 Using the JavaScript translation catalog
695 714
 ----------------------------------------
696 715
 
697  
-To use the catalog, just pull in the dynamically generated script like this::
  716
+.. highlightlang:: javascript
  717
+
  718
+To use the catalog, just pull in the dynamically generated script like this:
  719
+
  720
+.. code-block:: html+django
698 721
 
699 722
     <script type="text/javascript" src="{% url django.views.i18n.javascript_catalog %}"></script>
700 723
 
@@ -751,6 +774,8 @@ to produce proper pluralizations).
751 774
 The ``set_language`` redirect view
752 775
 ==================================
753 776
 
  777
+.. highlightlang:: python
  778
+
754 779
 .. function:: set_language(request)
755 780
 
756 781
 As a convenience, Django comes with a view, :meth:`django.views.i18n.set_language`,
BIN  tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.mo
Binary file not shown
13  tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgstr ""
8 8
 "Project-Id-Version: django tests\n"
9 9
 "Report-Msgid-Bugs-To: \n"
10 10
 "POT-Creation-Date: 2010-02-14 17:33+0100\n"
11  
-"PO-Revision-Date: 2011-01-16 17:14+0100\n"
  11
+"PO-Revision-Date: 2011-01-21 21:37-0300\n"
12 12
 "Last-Translator: Jannis Leidel <jannis@leidel.info>\n"
13 13
 "Language-Team: de <de@li.org>\n"
14 14
 "MIME-Version: 1.0\n"
@@ -18,22 +18,25 @@ msgstr ""
18 18
 
19 19
 #: models.py:3
20 20
 msgid "Time"
21  
-msgstr "Time (LOCALE_PATHS)"
  21
+msgstr "Zeit (LOCALE_PATHS)"
22 22
 
23 23
 #: models.py:5
  24
+msgid "Date/time"
  25
+msgstr "Datum/Zeit (LOCALE_PATHS)"
  26
+
  27
+#: models.py:7
24 28
 msgctxt "month name"
25 29
 msgid "May"
26 30
 msgstr "Mai"
27 31
 
28  
-#: models.py:7
  32
+#: models.py:9
29 33
 msgctxt "verb"
30 34
 msgid "May"
31 35
 msgstr "Kann"
32 36
 
33  
-#: models.py:9
  37
+#: models.py:11
34 38
 msgctxt "search"
35 39
 msgid "%d result"
36 40
 msgid_plural "%d results"
37 41
 msgstr[0] "%d Resultat"
38 42
 msgstr[1] "%d Resultate"
39  
-
BIN  tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.mo
Binary file not shown
9  tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.po
@@ -3,13 +3,12 @@
3 3
 # This file is distributed under the same license as the PACKAGE package.
4 4
 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5 5
 #
6  
-#, fuzzy
7 6
 msgid ""
8 7
 msgstr ""
9  
-"Project-Id-Version: PACKAGE VERSION\n"
  8
+"Project-Id-Version: django tests\n"
10 9
 "Report-Msgid-Bugs-To: \n"
11 10
 "POT-Creation-Date: 2010-02-14 17:33+0100\n"
12  
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
  11
+"PO-Revision-Date: 2011-02-07 13:12-0300\n"
13 12
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14 13
 "Language-Team: LANGUAGE <LL@li.org>\n"
15 14
 "MIME-Version: 1.0\n"
@@ -18,5 +17,9 @@ msgstr ""
18 17
 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
19 18
 
20 19
 #: models.py:3
  20
+msgid "Time"
  21
+msgstr "Zeit (APP)"
  22
+
  23
+#: models.py:5
21 24
 msgid "Date/time"
22 25
 msgstr "Datum/Zeit (APP)"
34  tests/regressiontests/i18n/tests.py
@@ -668,14 +668,14 @@ def tearDown(self):
668 668
 
669 669
     def assertUgettext(self, msgid, msgstr):
670 670
         result = ugettext(msgid)
671  
-        self.assert_(msgstr in result, ("The string '%s' isn't in the "
  671
+        self.assertTrue(msgstr in result, ("The string '%s' isn't in the "
672 672
             "translation of '%s'; the actual result is '%s'." % (msgstr, msgid, result)))
673 673
 
674 674
 class AppResolutionOrderI18NTests(ResolutionOrderI18NTests):
675 675
 
676 676
     def setUp(self):
677 677
         self.old_installed_apps = settings.INSTALLED_APPS
678  
-        settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.resolution']
  678
+        settings.INSTALLED_APPS = ['regressiontests.i18n.resolution'] + list(settings.INSTALLED_APPS)
679 679
         super(AppResolutionOrderI18NTests, self).setUp()
680 680
 
681 681
     def tearDown(self):
@@ -699,6 +699,22 @@ def tearDown(self):
699 699
     def test_locale_paths_translation(self):
700 700
         self.assertUgettext('Time', 'LOCALE_PATHS')
701 701
 
  702
+    def test_locale_paths_override_app_translation(self):
  703
+        old_installed_apps = settings.INSTALLED_APPS
  704
+        settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.resolution']
  705
+        try:
  706
+            self.assertUgettext('Time', 'LOCALE_PATHS')
  707
+        finally:
  708
+            settings.INSTALLED_APPS = old_installed_apps
  709
+
  710
+    def test_locale_paths_override_project_translation(self):
  711
+        old_settings_module = settings.SETTINGS_MODULE
  712
+        settings.SETTINGS_MODULE = 'regressiontests'
  713
+        try:
  714
+            self.assertUgettext('Date/time', 'LOCALE_PATHS')
  715
+        finally:
  716
+            settings.SETTINGS_MODULE = old_settings_module
  717
+
702 718
 class ProjectResolutionOrderI18NTests(ResolutionOrderI18NTests):
703 719
 
704 720
     def setUp(self):
@@ -716,19 +732,15 @@ def test_project_translation(self):
716 732
     def test_project_override_app_translation(self):
717 733
         old_installed_apps = settings.INSTALLED_APPS
718 734
         settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.resolution']
719  
-        self.assertUgettext('Date/time', 'PROJECT')
720  
-        settings.INSTALLED_APPS = old_installed_apps
721  
-
722  
-    def test_project_override_locale_paths_translation(self):
723  
-        old_locale_paths = settings.LOCALE_PATHS
724  
-        settings.LOCALE_PATHS += (os.path.join(os.path.dirname(os.path.abspath(__file__)), 'other', 'locale'),)
725  
-        self.assertUgettext('Date/time', 'PROJECT')
726  
-        settings.LOCALE_PATHS = old_locale_paths
  735
+        try:
  736
+            self.assertUgettext('Date/time', 'PROJECT')
  737
+        finally:
  738
+            settings.INSTALLED_APPS = old_installed_apps
727 739
 
728 740
 class DjangoFallbackResolutionOrderI18NTests(ResolutionOrderI18NTests):
729 741
 
730 742
     def test_django_fallback(self):
731  
-        self.assertUgettext('Date/time', 'Datum/Zeit')
  743
+        self.assertEqual(ugettext('Date/time'), 'Datum/Zeit')
732 744
 
733 745
 
734 746
 class TestModels(TestCase):
BIN  tests/regressiontests/locale/de/LC_MESSAGES/django.mo
Binary file not shown
9  tests/regressiontests/locale/de/LC_MESSAGES/django.po
@@ -3,13 +3,12 @@
3 3
 # This file is distributed under the same license as the PACKAGE package.
4 4
 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5 5
 #
6  
-#, fuzzy
7 6
 msgid ""
8 7
 msgstr ""
9  
-"Project-Id-Version: PACKAGE VERSION\n"
  8
+"Project-Id-Version: django tests\n"
10 9
 "Report-Msgid-Bugs-To: \n"
11 10
 "POT-Creation-Date: 2010-02-14 17:33+0100\n"
12  
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
  11
+"PO-Revision-Date: 2011-02-07 13:13-0300\n"
13 12
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14 13
 "Language-Team: LANGUAGE <LL@li.org>\n"
15 14
 "MIME-Version: 1.0\n"
@@ -18,5 +17,9 @@ msgstr ""
18 17
 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
19 18
 
20 19
 #: models.py:3
  20
+msgid "Time"
  21
+msgstr "Zeit (PROJECT)"
  22
+
  23
+#: models.py:5
21 24
 msgid "Date/time"
22 25
 msgstr "Datum/Zeit (PROJECT)"
9  tests/regressiontests/views/tests/i18n.py
... ...
@@ -1,5 +1,6 @@
1 1
 # -*- coding:utf-8 -*-
2 2
 import gettext
  3
+from os import path
3 4
 
4 5
 from django.conf import settings
5 6
 from django.test import TestCase
@@ -150,3 +151,11 @@ def testI18NDifferentNonEnLangs(self):
150 151
         response = self.client.get('/views/jsi18n_multi_packages2/')
151 152
         self.assertContains(response, javascript_quote('este texto de app3 debe ser traducido'))
152 153
         deactivate()
  154
+
  155
+    def testI18NWithLocalePaths(self):
  156
+        settings.LANGUAGE_CODE = 'es-ar'
  157
+        self.old_locale_paths = settings.LOCALE_PATHS
  158
+        settings.LOCALE_PATHS += (path.join(path.dirname(path.dirname(path.abspath(__file__))), 'app3', 'locale'),)
  159
+        response = self.client.get('/views/jsi18n/')
  160
+        self.assertContains(response, javascript_quote('este texto de app3 debe ser traducido'))
  161
+        settings.LOCALE_PATHS = self.old_locale_paths

0 notes on commit f6e38f3

Please sign in to comment.
Something went wrong with that request. Please try again.