Author: garcia_marc
Date: 2009-06-08 08:46:06 -0500 (Mon, 08 Jun 2009)
New Revision: 10956

Added:
   django/branches/soc2009/i18n-improvements/django/conf/locale/__init__.py
   django/branches/soc2009/i18n-improvements/django/conf/locale/ca/__init__.py
   django/branches/soc2009/i18n-improvements/django/conf/locale/ca/formats.py
   django/branches/soc2009/i18n-improvements/django/conf/locale/en/__init__.py
   django/branches/soc2009/i18n-improvements/django/conf/locale/en/formats.py
   django/branches/soc2009/i18n-improvements/django/utils/formats.py
Modified:
   django/branches/soc2009/i18n-improvements/django/conf/global_settings.py
   
django/branches/soc2009/i18n-improvements/django/contrib/admin/templates/admin/object_history.html
   
django/branches/soc2009/i18n-improvements/django/contrib/admin/templatetags/admin_list.py
   
django/branches/soc2009/i18n-improvements/django/contrib/databrowse/datastructures.py
   
django/branches/soc2009/i18n-improvements/django/utils/translation/trans_null.py
   
django/branches/soc2009/i18n-improvements/django/utils/translation/trans_real.py
   django/branches/soc2009/i18n-improvements/docs/ref/settings.txt
   django/branches/soc2009/i18n-improvements/tests/regressiontests/i18n/tests.py
Log:
[soc2009/i18n-improvements] Created a specific function to get locale formats 
(to avoid using gettext), and updated the code that used gettext.

Modified: 
django/branches/soc2009/i18n-improvements/django/conf/global_settings.py
===================================================================
--- django/branches/soc2009/i18n-improvements/django/conf/global_settings.py    
2009-06-08 13:35:39 UTC (rev 10955)
+++ django/branches/soc2009/i18n-improvements/django/conf/global_settings.py    
2009-06-08 13:46:06 UTC (rev 10956)
@@ -103,6 +103,10 @@
 LOCALE_PATHS = ()
 LANGUAGE_COOKIE_NAME = 'django_language'
 
+# If you set this to True, Django will format dates, numbers and calendars
+# according to user current locale
+USE_FORMAT_I18N = False
+
 # Not-necessarily-technical managers of the site. They get broken link
 # notifications and other various e-mails.
 MANAGERS = ADMINS
@@ -277,6 +281,25 @@
 # http://docs.djangoproject.com/en/dev/ref/templates/builtins/#now
 MONTH_DAY_FORMAT = 'F j'
 
+# Default shortformatting for date objects. See all available format strings 
here:
+# http://docs.djangoproject.com/en/dev/ref/templates/builtins/#now
+SHORT_DATE_FORMAT = 'N j, Y'
+
+# Default short formatting for datetime objects.
+# See all available format strings here:
+# http://docs.djangoproject.com/en/dev/ref/templates/builtins/#now
+SHORT_DATETIME_FORMAT = 'N j, Y, P'
+
+# Default first day of week, to be used on calendars
+# 0 means Sunday
+FIRST_DAY_OF_WEEK = 0
+
+# Default decimal separator symbol
+DECIMAL_SEPARATOR = '.'
+
+# Default thousand separator symbol
+THOUSAND_SEPARATOR = ','
+
 # Do you want to manage transactions manually?
 # Hint: you really don't!
 TRANSACTIONS_MANAGED = False

Added: django/branches/soc2009/i18n-improvements/django/conf/locale/__init__.py
===================================================================

Added: 
django/branches/soc2009/i18n-improvements/django/conf/locale/ca/__init__.py
===================================================================

Added: 
django/branches/soc2009/i18n-improvements/django/conf/locale/ca/formats.py
===================================================================
--- django/branches/soc2009/i18n-improvements/django/conf/locale/ca/formats.py  
                        (rev 0)
+++ django/branches/soc2009/i18n-improvements/django/conf/locale/ca/formats.py  
2009-06-08 13:46:06 UTC (rev 10956)
@@ -0,0 +1,18 @@
+# This file is distributed under the same license as the Django package.
+#
+
+DATE_FORMAT = 'j \de F \de Y'
+DATETIME_FORMAT = 'j \de F \de Y \\a \le\s H:i'
+TIME_FORMAT = 'P'
+YEAR_MONTH_FORMAT = 'F \de Y'
+MONTH_DAY_FORMAT = 'j \de F'
+
+SHORT_DATE_FORMAT = 'd/m/Y'
+SHORT_DATETIME_FORMAT = 'd/m/Y H:i'
+
+FIRST_DAY_OF_WEEK = 1 # 0 means Sunday
+
+DECIMAL_SEPARATOR = ','
+THOUSAND_SEPARATOR = '.'
+
+

Added: 
django/branches/soc2009/i18n-improvements/django/conf/locale/en/__init__.py
===================================================================

Added: 
django/branches/soc2009/i18n-improvements/django/conf/locale/en/formats.py
===================================================================
--- django/branches/soc2009/i18n-improvements/django/conf/locale/en/formats.py  
                        (rev 0)
+++ django/branches/soc2009/i18n-improvements/django/conf/locale/en/formats.py  
2009-06-08 13:46:06 UTC (rev 10956)
@@ -0,0 +1,18 @@
+# This file is distributed under the same license as the Django package.
+#
+
+DATE_FORMAT = 'N j, Y'
+DATETIME_FORMAT = 'N j, Y, P'
+TIME_FORMAT = 'P'
+YEAR_MONTH_FORMAT = 'F Y'
+MONTH_DAY_FORMAT = 'F j'
+
+SHORT_DATE_FORMAT = 'm/d/Y'
+SHORT_DATETIME_FORMAT = 'm/d/Y h:i A'
+
+FIRST_DAY_OF_WEEK = 0 # 0 means Sunday
+
+DECIMAL_SEPARATOR = '.'
+THOUSAND_SEPARATOR = ','
+
+

Modified: 
django/branches/soc2009/i18n-improvements/django/contrib/admin/templates/admin/object_history.html
===================================================================
--- 
django/branches/soc2009/i18n-improvements/django/contrib/admin/templates/admin/object_history.html
  2009-06-08 13:35:39 UTC (rev 10955)
+++ 
django/branches/soc2009/i18n-improvements/django/contrib/admin/templates/admin/object_history.html
  2009-06-08 13:46:06 UTC (rev 10956)
@@ -27,7 +27,7 @@
         <tbody>
         {% for action in action_list %}
         <tr>
-            <th scope="row">{{ action.action_time|date:_("DATETIME_FORMAT") 
}}</th>
+            <th scope="row">{{ action.action_time|date }}</th>
             <td>{{ action.user.username }}{% if action.user.get_full_name %} 
({{ action.user.get_full_name }}){% endif %}</td>
             <td>{{ action.change_message }}</td>
         </tr>

Modified: 
django/branches/soc2009/i18n-improvements/django/contrib/admin/templatetags/admin_list.py
===================================================================
--- 
django/branches/soc2009/i18n-improvements/django/contrib/admin/templatetags/admin_list.py
   2009-06-08 13:35:39 UTC (rev 10955)
+++ 
django/branches/soc2009/i18n-improvements/django/contrib/admin/templatetags/admin_list.py
   2009-06-08 13:46:06 UTC (rev 10956)
@@ -7,7 +7,8 @@
 from django.utils.html import escape, conditional_escape
 from django.utils.text import capfirst
 from django.utils.safestring import mark_safe
-from django.utils.translation import get_date_formats, 
get_partial_date_formats, ugettext as _
+from django.utils.translation import ugettext as _
+from django.utils.formats import getformat
 from django.utils.encoding import smart_unicode, smart_str, force_unicode
 from django.template import Library
 import datetime
@@ -184,7 +185,9 @@
             # Dates and times are special: They're formatted in a certain way.
             elif isinstance(f, models.DateField) or isinstance(f, 
models.TimeField):
                 if field_val:
-                    (date_format, datetime_format, time_format) = 
get_date_formats()
+                    date_format = getformat('DATE_FORMAT')
+                    datetime_format = getformat('DATETIME_FORMAT')
+                    time_format = getformat('TIME_FORMAT')
                     if isinstance(f, models.DateTimeField):
                         result_repr = capfirst(dateformat.format(field_val, 
datetime_format))
                     elif isinstance(f, models.TimeField):
@@ -263,7 +266,8 @@
         year_lookup = cl.params.get(year_field)
         month_lookup = cl.params.get(month_field)
         day_lookup = cl.params.get(day_field)
-        year_month_format, month_day_format = get_partial_date_formats()
+        year_month_format = getformat('YEAR_MONTH_FORMAT')
+        month_day_format = getformat('MONTH_DAY_FORMAT')
 
         link = lambda d: mark_safe(cl.get_query_string(d, [field_generic]))
 

Modified: 
django/branches/soc2009/i18n-improvements/django/contrib/databrowse/datastructures.py
===================================================================
--- 
django/branches/soc2009/i18n-improvements/django/contrib/databrowse/datastructures.py
       2009-06-08 13:35:39 UTC (rev 10955)
+++ 
django/branches/soc2009/i18n-improvements/django/contrib/databrowse/datastructures.py
       2009-06-08 13:46:06 UTC (rev 10956)
@@ -6,7 +6,6 @@
 from django.db import models
 from django.utils import dateformat
 from django.utils.text import capfirst
-from django.utils.translation import get_date_formats
 from django.utils.encoding import smart_unicode, smart_str, iri_to_uri
 from django.utils.safestring import mark_safe
 from django.db.models.query import QuerySet
@@ -156,7 +155,9 @@
             objs = dict(self.field.choices).get(self.raw_value, EMPTY_VALUE)
         elif isinstance(self.field, models.DateField) or 
isinstance(self.field, models.TimeField):
             if self.raw_value:
-                date_format, datetime_format, time_format = get_date_formats()
+                date_format = getformat('DATE_FORMAT')
+                datetime_format = getformat('DATETIME_FORMAT')
+                time_format = getformat('TIME_FORMAT')
                 if isinstance(self.field, models.DateTimeField):
                     objs = capfirst(dateformat.format(self.raw_value, 
datetime_format))
                 elif isinstance(self.field, models.TimeField):

Added: django/branches/soc2009/i18n-improvements/django/utils/formats.py
===================================================================
--- django/branches/soc2009/i18n-improvements/django/utils/formats.py           
                (rev 0)
+++ django/branches/soc2009/i18n-improvements/django/utils/formats.py   
2009-06-08 13:46:06 UTC (rev 10956)
@@ -0,0 +1,40 @@
+from django.utils.importlib import import_module
+
+def getformat_null(format_type):
+    """
+    For a specific format type, returns the default format as
+    set on the settings.
+    format_type is the name of the format, for example 'DATE_FORMAT'
+    """
+    from django.conf import settings
+    return getattr(settings, format_type)
+
+def getformat_real(format_type):
+    """
+    For a specific format type, returns the format for the
+    current language (locale) defaulting to the format on settings.
+    format_type is the name of the format, for example 'DATE_FORMAT'
+    """
+    from django.utils.translation import get_language
+    import_formats = lambda s: import_module('.formats', 
'django.conf.locale.%s' % s)
+    tmp = import_formats('ca')
+    format = None
+    try:
+        module = import_formats(get_language())
+    except ImportError:
+        pass
+    else:
+        try:
+            format = getattr(module, format_type)
+        except AttributeError:
+            pass
+    return format or getformat_null(format_type)
+
+# getformat will just return the value on setings if
+# we don't use i18n in our project
+from django.conf import settings
+if settings.USE_I18N and settings.USE_FORMAT_I18N:
+    getformat = getformat_real
+else:
+    getformat = getformat_null
+

Modified: 
django/branches/soc2009/i18n-improvements/django/utils/translation/trans_null.py
===================================================================
--- 
django/branches/soc2009/i18n-improvements/django/utils/translation/trans_null.py
    2009-06-08 13:35:39 UTC (rev 10955)
+++ 
django/branches/soc2009/i18n-improvements/django/utils/translation/trans_null.py
    2009-06-08 13:46:06 UTC (rev 10956)
@@ -18,10 +18,10 @@
 deactivate = deactivate_all = lambda: None
 get_language = lambda: settings.LANGUAGE_CODE
 get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
-get_date_formats = lambda: (settings.DATE_FORMAT, settings.DATETIME_FORMAT, 
settings.TIME_FORMAT)
-get_partial_date_formats = lambda: (settings.YEAR_MONTH_FORMAT, 
settings.MONTH_DAY_FORMAT)
 check_for_language = lambda x: True
 
+# date formats shouldn't be used using gettext anymore. This
+# is kept for backward compatibility
 TECHNICAL_ID_MAP = {
     "DATE_WITH_TIME_FULL": settings.DATETIME_FORMAT,
     "DATE_FORMAT": settings.DATE_FORMAT,
@@ -51,3 +51,8 @@
 
 def get_language_from_request(request):
     return settings.LANGUAGE_CODE
+
+# get_date_formats and get_partial_date_formats aren't used anymore from django
+# itself, and are kept for backward compatibility.
+get_date_formats = lambda: (settings.DATE_FORMAT, settings.DATETIME_FORMAT, 
settings.TIME_FORMAT)
+get_partial_date_formats = lambda: (settings.YEAR_MONTH_FORMAT, 
settings.MONTH_DAY_FORMAT)

Modified: 
django/branches/soc2009/i18n-improvements/django/utils/translation/trans_real.py
===================================================================
--- 
django/branches/soc2009/i18n-improvements/django/utils/translation/trans_real.py
    2009-06-08 13:35:39 UTC (rev 10955)
+++ 
django/branches/soc2009/i18n-improvements/django/utils/translation/trans_real.py
    2009-06-08 13:46:06 UTC (rev 10956)
@@ -389,39 +389,6 @@
 
     return settings.LANGUAGE_CODE
 
-def get_date_formats():
-    """
-    Checks whether translation files provide a translation for some technical
-    message ID to store date and time formats. If it doesn't contain one, the
-    formats provided in the settings will be used.
-    """
-    from django.conf import settings
-    date_format = ugettext('DATE_FORMAT')
-    datetime_format = ugettext('DATETIME_FORMAT')
-    time_format = ugettext('TIME_FORMAT')
-    if date_format == 'DATE_FORMAT':
-        date_format = settings.DATE_FORMAT
-    if datetime_format == 'DATETIME_FORMAT':
-        datetime_format = settings.DATETIME_FORMAT
-    if time_format == 'TIME_FORMAT':
-        time_format = settings.TIME_FORMAT
-    return date_format, datetime_format, time_format
-
-def get_partial_date_formats():
-    """
-    Checks whether translation files provide a translation for some technical
-    message ID to store partial date formats. If it doesn't contain one, the
-    formats provided in the settings will be used.
-    """
-    from django.conf import settings
-    year_month_format = ugettext('YEAR_MONTH_FORMAT')
-    month_day_format = ugettext('MONTH_DAY_FORMAT')
-    if year_month_format == 'YEAR_MONTH_FORMAT':
-        year_month_format = settings.YEAR_MONTH_FORMAT
-    if month_day_format == 'MONTH_DAY_FORMAT':
-        month_day_format = settings.MONTH_DAY_FORMAT
-    return year_month_format, month_day_format
-
 dot_re = re.compile(r'\S')
 def blankout(src, char):
     """
@@ -537,3 +504,42 @@
         result.append((lang, priority))
     result.sort(lambda x, y: -cmp(x[1], y[1]))
     return result
+
+# get_date_formats and get_partial_date_formats aren't used anymore from django
+# itself, and are kept for backward compatibility.
+# Note that it's also important to keep format names maked for translation, so
+# for compatibility we still want to have formats on translation catalogs. That
+# makes template code like {{ my_date|date:_('DATE_FORMAT') }} go on working
+def get_date_formats():
+    """
+    Checks whether translation files provide a translation for some technical
+    message ID to store date and time formats. If it doesn't contain one, the
+    formats provided in the settings will be used.
+    """
+    from django.conf import settings
+    date_format = ugettext('DATE_FORMAT')
+    datetime_format = ugettext('DATETIME_FORMAT')
+    time_format = ugettext('TIME_FORMAT')
+    if date_format == 'DATE_FORMAT':
+        date_format = settings.DATE_FORMAT
+    if datetime_format == 'DATETIME_FORMAT':
+        datetime_format = settings.DATETIME_FORMAT
+    if time_format == 'TIME_FORMAT':
+        time_format = settings.TIME_FORMAT
+    return date_format, datetime_format, time_format
+
+def get_partial_date_formats():
+    """
+    Checks whether translation files provide a translation for some technical
+    message ID to store partial date formats. If it doesn't contain one, the
+    formats provided in the settings will be used.
+    """
+    from django.conf import settings
+    year_month_format = ugettext('YEAR_MONTH_FORMAT')
+    month_day_format = ugettext('MONTH_DAY_FORMAT')
+    if year_month_format == 'YEAR_MONTH_FORMAT':
+        year_month_format = settings.YEAR_MONTH_FORMAT
+    if month_day_format == 'MONTH_DAY_FORMAT':
+        month_day_format = settings.MONTH_DAY_FORMAT
+    return year_month_format, month_day_format
+

Modified: django/branches/soc2009/i18n-improvements/docs/ref/settings.txt
===================================================================
--- django/branches/soc2009/i18n-improvements/docs/ref/settings.txt     
2009-06-08 13:35:39 UTC (rev 10955)
+++ django/branches/soc2009/i18n-improvements/docs/ref/settings.txt     
2009-06-08 13:46:06 UTC (rev 10956)
@@ -303,6 +303,15 @@
 site.
 
 
+.. setting:: DECIMAL_SEPARATOR
+
+DECIMAL_SEPARATOR
+-----------------
+
+Default: ``'.'`` (Dot)
+
+The default decimal separator used when formatting decimal numbers.
+
 .. setting:: DEFAULT_CHARSET
 
 DEFAULT_CHARSET

Modified: 
django/branches/soc2009/i18n-improvements/tests/regressiontests/i18n/tests.py
===================================================================
--- 
django/branches/soc2009/i18n-improvements/tests/regressiontests/i18n/tests.py   
    2009-06-08 13:35:39 UTC (rev 10955)
+++ 
django/branches/soc2009/i18n-improvements/tests/regressiontests/i18n/tests.py   
    2009-06-08 13:46:06 UTC (rev 10956)
@@ -64,6 +64,15 @@
 'as'
 >>> print s
 Password
+
+>>> from django.utils.formats import getformat
+>>> activate('en')
+>>> getformat('DATE_FORMAT')
+'N j, Y'
+>>> activate('ca')
+>>> getformat('DATE_FORMAT')
+'j \de N \de Y'
+
 """
 
 __test__ = {


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to