Author: carljm
Date: 2011-09-16 04:57:03 -0700 (Fri, 16 Sep 2011)
New Revision: 16839
Added:
django/trunk/tests/regressiontests/i18n/contenttypes/
django/trunk/tests/regressiontests/i18n/contenttypes/__init__.py
django/trunk/tests/regressiontests/i18n/contenttypes/locale/
django/trunk/tests/regressiontests/i18n/contenttypes/locale/en/
django/trunk/tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/
django/trunk/tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.mo
django/trunk/tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.po
django/trunk/tests/regressiontests/i18n/contenttypes/locale/fr/
django/trunk/tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/
django/trunk/tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.mo
django/trunk/tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.po
django/trunk/tests/regressiontests/i18n/contenttypes/tests.py
Modified:
django/trunk/django/contrib/contenttypes/models.py
django/trunk/tests/regressiontests/i18n/models.py
django/trunk/tests/regressiontests/i18n/tests.py
Log:
Fixed #16803 -- Use model verbose_name directly as ContentType unicode
representation so it can be translated. Thanks to bronger for the report and
Ivan Sagalaev for the patch.
Modified: django/trunk/django/contrib/contenttypes/models.py
===================================================================
--- django/trunk/django/contrib/contenttypes/models.py 2011-09-16 11:12:35 UTC
(rev 16838)
+++ django/trunk/django/contrib/contenttypes/models.py 2011-09-16 11:57:03 UTC
(rev 16839)
@@ -1,6 +1,6 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_unicode, force_unicode
class ContentTypeManager(models.Manager):
@@ -85,7 +85,18 @@
unique_together = (('app_label', 'model'),)
def __unicode__(self):
- return self.name
+ # self.name is deprecated in favor of using model's verbose_name, which
+ # can be translated. Formal deprecation is delayed until we have DB
+ # migration to be able to remove the field from the database along with
+ # the attribute.
+ #
+ # We return self.name only when users have changed its value from the
+ # initial verbose_name_raw and might rely on it.
+ meta = self.model_class()._meta
+ if self.name != meta.verbose_name_raw:
+ return self.name
+ else:
+ return force_unicode(meta.verbose_name)
def model_class(self):
"Returns the Python model class for this type of content."
Added: django/trunk/tests/regressiontests/i18n/contenttypes/__init__.py
===================================================================
Added:
django/trunk/tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.mo
===================================================================
---
django/trunk/tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.mo
(rev 0)
+++
django/trunk/tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.mo
2011-09-16 11:57:03 UTC (rev 16839)
@@ -0,0 +1,11 @@
+Þ • , < P Q @ Y š
Company Project-Id-Version: PACKAGE VERSION
+Report-Msgid-Bugs-To:
+POT-Creation-Date: 2011-09-15 15:41-0700
+PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
+Last-Translator: FULL NAME <EMAIL@ADDRESS>
+Language-Team: LANGUAGE <[email protected]>
+Language:
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+ Company
\ No newline at end of file
Added:
django/trunk/tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.po
===================================================================
---
django/trunk/tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.po
(rev 0)
+++
django/trunk/tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.po
2011-09-16 11:57:03 UTC (rev 16839)
@@ -0,0 +1,26 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-09-15 15:41-0700\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <[email protected]>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: models.py:6
+msgid "Anything"
+msgstr ""
+
+#: models.py:15
+msgid "Company"
+msgstr "Company"
\ No newline at end of file
Added:
django/trunk/tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.mo
===================================================================
---
django/trunk/tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.mo
(rev 0)
+++
django/trunk/tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.mo
2011-09-16 11:57:03 UTC (rev 16839)
@@ -0,0 +1,12 @@
+Þ • , < P Q i Y Ã
Company Project-Id-Version: PACKAGE VERSION
+Report-Msgid-Bugs-To:
+POT-Creation-Date: 2011-09-15 15:41-0700
+PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
+Last-Translator: FULL NAME <EMAIL@ADDRESS>
+Language-Team: LANGUAGE <[email protected]>
+Language:
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+Plural-Forms: nplurals=2; plural=(n > 1)
+ Société
\ No newline at end of file
Added:
django/trunk/tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.po
===================================================================
---
django/trunk/tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.po
(rev 0)
+++
django/trunk/tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.po
2011-09-16 11:57:03 UTC (rev 16839)
@@ -0,0 +1,27 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-09-15 15:41-0700\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <[email protected]>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1)\n"
+
+#: models.py:6
+msgid "Anything"
+msgstr ""
+
+#: models.py:15
+msgid "Company"
+msgstr "Société"
\ No newline at end of file
Added: django/trunk/tests/regressiontests/i18n/contenttypes/tests.py
===================================================================
--- django/trunk/tests/regressiontests/i18n/contenttypes/tests.py
(rev 0)
+++ django/trunk/tests/regressiontests/i18n/contenttypes/tests.py
2011-09-16 11:57:03 UTC (rev 16839)
@@ -0,0 +1,35 @@
+# coding: utf-8
+from __future__ import with_statement
+
+import os
+
+from django.test import TestCase
+from django.test.utils import override_settings
+from django.utils import translation
+from django.contrib.contenttypes.models import ContentType
+
+
+class ContentTypeTests(TestCase):
+ def test_verbose_name(self):
+ company_type = ContentType.objects.get(app_label='i18n',
model='company')
+ with translation.override('en'):
+ self.assertEqual(unicode(company_type), u'Company')
+ with translation.override('fr'):
+ self.assertEqual(unicode(company_type), u'Société')
+
+ def test_field_override(self):
+ company_type = ContentType.objects.get(app_label='i18n',
model='company')
+ company_type.name = 'Other'
+ self.assertEqual(unicode(company_type), 'Other')
+
+ContentTypeTests = override_settings(
+ USE_I18N=True,
+ LOCALE_PATHS=(
+ os.path.join(os.path.dirname(__file__), 'locale'),
+ ),
+ LANGUAGE_CODE='en',
+ LANGUAGES=(
+ ('en', 'English'),
+ ('fr', 'French'),
+ ),
+)(ContentTypeTests)
Modified: django/trunk/tests/regressiontests/i18n/models.py
===================================================================
--- django/trunk/tests/regressiontests/i18n/models.py 2011-09-16 11:12:35 UTC
(rev 16838)
+++ django/trunk/tests/regressiontests/i18n/models.py 2011-09-16 11:57:03 UTC
(rev 16839)
@@ -10,3 +10,6 @@
date_added = models.DateTimeField(default=datetime(1799,1,31,23,59,59,0))
cents_payed = models.DecimalField(max_digits=4, decimal_places=2)
products_delivered = models.IntegerField()
+
+ class Meta:
+ verbose_name = _('Company')
\ No newline at end of file
Modified: django/trunk/tests/regressiontests/i18n/tests.py
===================================================================
--- django/trunk/tests/regressiontests/i18n/tests.py 2011-09-16 11:12:35 UTC
(rev 16838)
+++ django/trunk/tests/regressiontests/i18n/tests.py 2011-09-16 11:57:03 UTC
(rev 16839)
@@ -26,6 +26,7 @@
from commands.tests import *
from patterns.tests import *
+from contenttypes.tests import *
from test_warnings import DeprecationWarningTests
here = os.path.dirname(os.path.abspath(__file__))
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.