diff options
| author | Georg Bauer <gb@hugo.westfalen.de> | 2005-12-04 12:06:16 +0000 |
|---|---|---|
| committer | Georg Bauer <gb@hugo.westfalen.de> | 2005-12-04 12:06:16 +0000 |
| commit | 5917fdcf2d07e54e7d83076b26e22bcadf65eb54 (patch) | |
| tree | b3232c933fbda8616b40dd96aec1a1f801c635dd /django/utils | |
| parent | 946bd1e370148efe6ae2da493f000373fa6a35a7 (diff) | |
added infrastructure code for later javascript translating (currently not active)
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1529 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/text.py | 19 | ||||
| -rw-r--r-- | django/utils/translation.py | 15 |
2 files changed, 34 insertions, 0 deletions
diff --git a/django/utils/text.py b/django/utils/text.py index 6ac8352ac6..8206095f42 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -1,5 +1,7 @@ import re +from django.conf.settings import DEFAULT_CHARSET + # Capitalizes the first letter of a string. capfirst = lambda x: x and x[0].upper() + x[1:] @@ -90,3 +92,20 @@ def compress_string(s): zfile.write(s) zfile.close() return zbuf.getvalue() + +ustring_re = re.compile(u"([\u0080-\uffff])") +def javascript_quote(s): + + def fix(match): + return r"\u%04x" % ord(match.group(1)) + + if type(s) == str: + s = s.decode(DEFAULT_ENCODING) + elif type(s) != unicode: + raise TypeError, s + s = s.replace('\\', '\\\\') + s = s.replace('\n', '\\n') + s = s.replace('\t', '\\t') + s = s.replace("'", "\\'") + return str(ustring_re.sub(fix, s)) + diff --git a/django/utils/translation.py b/django/utils/translation.py index a8a943e391..9c36850fb9 100644 --- a/django/utils/translation.py +++ b/django/utils/translation.py @@ -212,6 +212,21 @@ def get_language(): from django.conf.settings import LANGUAGE_CODE return LANGUAGE_CODE +def catalog(): + """ + This function returns the current active catalog for further processing. + This can be used if you need to modify the catalog or want to access the + whole message catalog instead of just translating one string. + """ + global _default, _active + t = _active.get(currentThread(), None) + if t is not None: + return t + if _default is None: + from django.conf import settings + _default = translation(settings.LANGUAGE_CODE) + return _default + def gettext(message): """ This function will be patched into the builtins module to provide the _ |
