Exemplo n.º 1
0
def deactivate():
    """
    Deinstalls the currently active translation object so that further _ calls
    will resolve against the default translation object, again.
    """
    global _active
    if currentThread() in _active:
        del _active[currentThread()]
Exemplo n.º 2
0
def deactivate():
    """
    Deinstalls the currently active translation object so that further _ calls
    will resolve against the default translation object, again.
    """
    global _active
    if currentThread() in _active:
        del _active[currentThread()]
Exemplo n.º 3
0
def get_script_prefix():
    """
    Returns the currently active script prefix. Useful for client code that
    wishes to construct their own URLs manually (although accessing the request
    instance is normally going to be a lot cleaner).
    """
    return _prefixes.get(currentThread(), '/')
Exemplo n.º 4
0
def deactivate_all():
    """
    Makes the active translation object a NullTranslations() instance. This is
    useful when we want delayed translations to appear as the original string
    for some reason.
    """
    _active[currentThread()] = gettext_module.NullTranslations()
Exemplo n.º 5
0
def set_script_prefix(prefix):
    """
    Sets the script prefix for the current thread.
    """
    if not prefix.endswith('/'):
        prefix += '/'
    _prefixes[currentThread()] = prefix
Exemplo n.º 6
0
def get_script_prefix():
    """
    Returns the currently active script prefix. Useful for client code that
    wishes to construct their own URLs manually (although accessing the request
    instance is normally going to be a lot cleaner).
    """
    return _prefixes.get(currentThread(), '/')
Exemplo n.º 7
0
def deactivate_all():
    """
    Makes the active translation object a NullTranslations() instance. This is
    useful when we want delayed translations to appear as the original string
    for some reason.
    """
    _active[currentThread()] = gettext_module.NullTranslations()
Exemplo n.º 8
0
def set_script_prefix(prefix):
    """
    Sets the script prefix for the current thread.
    """
    if not prefix.endswith('/'):
        prefix += '/'
    _prefixes[currentThread()] = prefix
Exemplo n.º 9
0
def get_urlconf(default=None):
    """
    Returns the root URLconf to use for the current thread if it has been
    changed from the default one.
    """
    thread = currentThread()
    if thread in _urlconfs:
        return _urlconfs[thread]
    return default
Exemplo n.º 10
0
def get_urlconf(default=None):
    """
    Returns the root URLconf to use for the current thread if it has been
    changed from the default one.
    """
    thread = currentThread()
    if thread in _urlconfs:
        return _urlconfs[thread]
    return default
Exemplo n.º 11
0
def do_ntranslate(singular, plural, number, translation_function):
    global _default, _active

    t = _active.get(currentThread(), None)
    if t is not None:
        return getattr(t, translation_function)(singular, plural, number)
    if _default is None:
        from google.appengine._internal.django.conf import settings
        _default = translation(settings.LANGUAGE_CODE)
    return getattr(_default, translation_function)(singular, plural, number)
Exemplo n.º 12
0
def do_ntranslate(singular, plural, number, translation_function):
    global _default, _active

    t = _active.get(currentThread(), None)
    if t is not None:
        return getattr(t, translation_function)(singular, plural, number)
    if _default is None:
        from google.appengine._internal.django.conf import settings
        _default = translation(settings.LANGUAGE_CODE)
    return getattr(_default, translation_function)(singular, plural, number)
Exemplo n.º 13
0
def get_language():
    """Returns the currently selected language."""
    t = _active.get(currentThread(), None)
    if t is not None:
        try:
            return to_language(t.language())
        except AttributeError:
            pass
    # If we don't have a real translation object, assume it's the default language.
    from google.appengine._internal.django.conf import settings
    return settings.LANGUAGE_CODE
Exemplo n.º 14
0
def get_language():
    """Returns the currently selected language."""
    t = _active.get(currentThread(), None)
    if t is not None:
        try:
            return to_language(t.language())
        except AttributeError:
            pass
    # If we don't have a real translation object, assume it's the default language.
    from google.appengine._internal.django.conf import settings
    return settings.LANGUAGE_CODE
Exemplo n.º 15
0
def activate(language):
    """
    Fetches the translation object for a given tuple of application name and
    language and installs it as the current translation object for the current
    thread.
    """
    if isinstance(language, str) and language == 'no':
        warnings.warn(
            "The use of the language code 'no' is deprecated. "
            "Please use the 'nb' translation instead.",
            PendingDeprecationWarning)
    _active[currentThread()] = translation(language)
Exemplo n.º 16
0
def set_urlconf(urlconf_name):
    """
    Sets the URLconf for the current thread (overriding the default one in
    settings). Set to None to revert back to the default.
    """
    thread = currentThread()
    if urlconf_name:
        _urlconfs[thread] = urlconf_name
    else:
        # faster than wrapping in a try/except
        if thread in _urlconfs:
            del _urlconfs[thread]
Exemplo n.º 17
0
def set_urlconf(urlconf_name):
    """
    Sets the URLconf for the current thread (overriding the default one in
    settings). Set to None to revert back to the default.
    """
    thread = currentThread()
    if urlconf_name:
        _urlconfs[thread] = urlconf_name
    else:
        # faster than wrapping in a try/except
        if thread in _urlconfs:
            del _urlconfs[thread]
Exemplo n.º 18
0
def activate(language):
    """
    Fetches the translation object for a given tuple of application name and
    language and installs it as the current translation object for the current
    thread.
    """
    if isinstance(language, str) and language == 'no':
        warnings.warn(
            "The use of the language code 'no' is deprecated. "
            "Please use the 'nb' translation instead.",
            PendingDeprecationWarning
        )
    _active[currentThread()] = translation(language)
Exemplo n.º 19
0
def catalog():
    """
    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 google.appengine._internal.django.conf import settings
        _default = translation(settings.LANGUAGE_CODE)
    return _default
Exemplo n.º 20
0
def catalog():
    """
    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 google.appengine._internal.django.conf import settings
        _default = translation(settings.LANGUAGE_CODE)
    return _default
Exemplo n.º 21
0
def do_translate(message, translation_function):
    """
    Translates 'message' using the given 'translation_function' name -- which
    will be either gettext or ugettext. It uses the current thread to find the
    translation object to use. If no current translation is activated, the
    message will be run through the default translation object.
    """
    eol_message = message.replace('\r\n', '\n').replace('\r', '\n')
    global _default, _active
    t = _active.get(currentThread(), None)
    if t is not None:
        result = getattr(t, translation_function)(eol_message)
    else:
        if _default is None:
            from google.appengine._internal.django.conf import settings
            _default = translation(settings.LANGUAGE_CODE)
        result = getattr(_default, translation_function)(eol_message)
    if isinstance(message, SafeData):
        return mark_safe(result)
    return result
Exemplo n.º 22
0
def do_translate(message, translation_function):
    """
    Translates 'message' using the given 'translation_function' name -- which
    will be either gettext or ugettext. It uses the current thread to find the
    translation object to use. If no current translation is activated, the
    message will be run through the default translation object.
    """
    eol_message = message.replace('\r\n', '\n').replace('\r', '\n')
    global _default, _active
    t = _active.get(currentThread(), None)
    if t is not None:
        result = getattr(t, translation_function)(eol_message)
    else:
        if _default is None:
            from google.appengine._internal.django.conf import settings
            _default = translation(settings.LANGUAGE_CODE)
        result = getattr(_default, translation_function)(eol_message)
    if isinstance(message, SafeData):
        return mark_safe(result)
    return result