|
0
|
1 |
# These are versions of the functions in django.utils.translation.trans_real |
|
|
2 |
# that don't actually do anything. This is purely for performance, so that |
|
|
3 |
# settings.USE_I18N = False can use this module rather than trans_real.py. |
|
|
4 |
|
|
29
|
5 |
import warnings |
|
0
|
6 |
from django.conf import settings |
|
|
7 |
from django.utils.encoding import force_unicode |
|
|
8 |
from django.utils.safestring import mark_safe, SafeData |
|
|
9 |
|
|
|
10 |
def ngettext(singular, plural, number): |
|
|
11 |
if number == 1: return singular |
|
|
12 |
return plural |
|
|
13 |
ngettext_lazy = ngettext |
|
|
14 |
|
|
|
15 |
def ungettext(singular, plural, number): |
|
|
16 |
return force_unicode(ngettext(singular, plural, number)) |
|
|
17 |
|
|
|
18 |
activate = lambda x: None |
|
|
19 |
deactivate = deactivate_all = lambda: None |
|
|
20 |
get_language = lambda: settings.LANGUAGE_CODE |
|
|
21 |
get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI |
|
|
22 |
check_for_language = lambda x: True |
|
|
23 |
|
|
29
|
24 |
# date formats shouldn't be used using gettext anymore. This |
|
|
25 |
# is kept for backward compatibility |
|
0
|
26 |
TECHNICAL_ID_MAP = { |
|
|
27 |
"DATE_WITH_TIME_FULL": settings.DATETIME_FORMAT, |
|
|
28 |
"DATE_FORMAT": settings.DATE_FORMAT, |
|
|
29 |
"DATETIME_FORMAT": settings.DATETIME_FORMAT, |
|
|
30 |
"TIME_FORMAT": settings.TIME_FORMAT, |
|
|
31 |
"YEAR_MONTH_FORMAT": settings.YEAR_MONTH_FORMAT, |
|
|
32 |
"MONTH_DAY_FORMAT": settings.MONTH_DAY_FORMAT, |
|
|
33 |
} |
|
|
34 |
|
|
|
35 |
def gettext(message): |
|
|
36 |
result = TECHNICAL_ID_MAP.get(message, message) |
|
|
37 |
if isinstance(message, SafeData): |
|
|
38 |
return mark_safe(result) |
|
|
39 |
return result |
|
|
40 |
|
|
|
41 |
def ugettext(message): |
|
|
42 |
return force_unicode(gettext(message)) |
|
|
43 |
|
|
|
44 |
gettext_noop = gettext_lazy = _ = gettext |
|
|
45 |
|
|
|
46 |
def to_locale(language): |
|
|
47 |
p = language.find('-') |
|
|
48 |
if p >= 0: |
|
|
49 |
return language[:p].lower()+'_'+language[p+1:].upper() |
|
|
50 |
else: |
|
|
51 |
return language.lower() |
|
|
52 |
|
|
|
53 |
def get_language_from_request(request): |
|
|
54 |
return settings.LANGUAGE_CODE |
|
29
|
55 |
|
|
|
56 |
# get_date_formats and get_partial_date_formats aren't used anymore by Django |
|
|
57 |
# but are kept for backward compatibility. |
|
|
58 |
def get_date_formats(): |
|
|
59 |
warnings.warn( |
|
|
60 |
'`django.utils.translation.get_date_formats` is deprecated. ' |
|
|
61 |
'Please update your code to use the new i18n aware formatting.', |
|
|
62 |
PendingDeprecationWarning |
|
|
63 |
) |
|
|
64 |
return settings.DATE_FORMAT, settings.DATETIME_FORMAT, settings.TIME_FORMAT |
|
|
65 |
|
|
|
66 |
def get_partial_date_formats(): |
|
|
67 |
warnings.warn( |
|
|
68 |
'`django.utils.translation.get_partial_date_formats` is deprecated. ' |
|
|
69 |
'Please update your code to use the new i18n aware formatting.', |
|
|
70 |
PendingDeprecationWarning |
|
|
71 |
) |
|
|
72 |
return settings.YEAR_MONTH_FORMAT, settings.MONTH_DAY_FORMAT |