2006-07-04 11:58:45 +08:00
|
|
|
# These are versions of the functions in django.utils.translation.trans_real
|
|
|
|
# that don't actually do anything. This is purely for performance, so that
|
|
|
|
# settings.USE_I18N = False can use this module rather than trans_real.py.
|
|
|
|
|
2009-12-23 01:58:49 +08:00
|
|
|
import warnings
|
2006-07-04 11:58:45 +08:00
|
|
|
from django.conf import settings
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
from django.utils.encoding import force_unicode
|
2007-11-17 20:11:54 +08:00
|
|
|
from django.utils.safestring import mark_safe, SafeData
|
2006-07-04 11:58:45 +08:00
|
|
|
|
|
|
|
def ngettext(singular, plural, number):
|
|
|
|
if number == 1: return singular
|
|
|
|
return plural
|
|
|
|
ngettext_lazy = ngettext
|
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
def ungettext(singular, plural, number):
|
|
|
|
return force_unicode(ngettext(singular, plural, number))
|
|
|
|
|
2010-11-04 18:48:27 +08:00
|
|
|
def pgettext(context, message):
|
|
|
|
return ugettext(message)
|
|
|
|
|
|
|
|
def npgettext(context, singular, plural, number):
|
|
|
|
return ungettext(singular, plural, number)
|
|
|
|
|
2006-07-04 11:58:45 +08:00
|
|
|
activate = lambda x: None
|
2007-10-22 01:14:25 +08:00
|
|
|
deactivate = deactivate_all = lambda: None
|
2006-07-08 21:58:33 +08:00
|
|
|
get_language = lambda: settings.LANGUAGE_CODE
|
2006-07-11 22:08:42 +08:00
|
|
|
get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
|
2006-07-14 10:55:42 +08:00
|
|
|
check_for_language = lambda x: True
|
|
|
|
|
2009-12-23 01:58:49 +08:00
|
|
|
# date formats shouldn't be used using gettext anymore. This
|
|
|
|
# is kept for backward compatibility
|
2007-04-05 11:22:49 +08:00
|
|
|
TECHNICAL_ID_MAP = {
|
|
|
|
"DATE_WITH_TIME_FULL": settings.DATETIME_FORMAT,
|
|
|
|
"DATE_FORMAT": settings.DATE_FORMAT,
|
|
|
|
"DATETIME_FORMAT": settings.DATETIME_FORMAT,
|
|
|
|
"TIME_FORMAT": settings.TIME_FORMAT,
|
|
|
|
"YEAR_MONTH_FORMAT": settings.YEAR_MONTH_FORMAT,
|
|
|
|
"MONTH_DAY_FORMAT": settings.MONTH_DAY_FORMAT,
|
|
|
|
}
|
|
|
|
|
|
|
|
def gettext(message):
|
2007-11-17 20:11:54 +08:00
|
|
|
result = TECHNICAL_ID_MAP.get(message, message)
|
|
|
|
if isinstance(message, SafeData):
|
|
|
|
return mark_safe(result)
|
|
|
|
return result
|
2007-04-05 11:22:49 +08:00
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
def ugettext(message):
|
|
|
|
return force_unicode(gettext(message))
|
|
|
|
|
2007-04-05 11:25:30 +08:00
|
|
|
gettext_noop = gettext_lazy = _ = gettext
|
2007-04-05 11:22:49 +08:00
|
|
|
|
2006-07-14 10:55:42 +08:00
|
|
|
def to_locale(language):
|
|
|
|
p = language.find('-')
|
|
|
|
if p >= 0:
|
|
|
|
return language[:p].lower()+'_'+language[p+1:].upper()
|
|
|
|
else:
|
|
|
|
return language.lower()
|
2006-07-28 00:38:32 +08:00
|
|
|
|
|
|
|
def get_language_from_request(request):
|
|
|
|
return settings.LANGUAGE_CODE
|
2009-12-23 01:58:49 +08:00
|
|
|
|
|
|
|
# get_date_formats and get_partial_date_formats aren't used anymore by Django
|
|
|
|
# but are kept for backward compatibility.
|
|
|
|
def get_date_formats():
|
|
|
|
warnings.warn(
|
|
|
|
'`django.utils.translation.get_date_formats` is deprecated. '
|
|
|
|
'Please update your code to use the new i18n aware formatting.',
|
2010-10-11 20:20:07 +08:00
|
|
|
DeprecationWarning
|
2009-12-23 01:58:49 +08:00
|
|
|
)
|
|
|
|
return settings.DATE_FORMAT, settings.DATETIME_FORMAT, settings.TIME_FORMAT
|
|
|
|
|
|
|
|
def get_partial_date_formats():
|
|
|
|
warnings.warn(
|
|
|
|
'`django.utils.translation.get_partial_date_formats` is deprecated. '
|
|
|
|
'Please update your code to use the new i18n aware formatting.',
|
2010-10-11 20:20:07 +08:00
|
|
|
DeprecationWarning
|
2009-12-23 01:58:49 +08:00
|
|
|
)
|
|
|
|
return settings.YEAR_MONTH_FORMAT, settings.MONTH_DAY_FORMAT
|