Exemplo n.º 1
0
def sa_gettext(key, locale=None, domain=None):
    """
    SQLAlchemy-based version of gettext. Messages are stored in
    database instead.
    """

    locale = get_locale(locale)

    messages = get_sa_catalog(domain).get(locale)
    if not messages:
        messages = get_sa_catalog(domain).get(locale[:2], {})

    return unicode(messages.get(key, key))
Exemplo n.º 2
0
def sa_gettext(key, locale=None, domain=None):
    """
    SQLAlchemy-based version of gettext. Messages are stored in
    database instead.
    """

    locale = get_locale(locale)

    messages = get_sa_catalog(domain).get(locale)
    if not messages:
        messages = get_sa_catalog(domain).get(locale[:2], {})

    return unicode(messages.get(key, key))
Exemplo n.º 3
0
def tg_ngettext(key1, key2, num, locale=None, domain=None):
    """Get the gettext value for key.

    Added to builtins as '_'. Returns Unicode string.

    @param key: text to be translated
    @param locale: locale code to be used.
        If locale is None, gets the value provided by get_locale.

    """
    if locale is None:
        locale = get_locale()
    if not is_locale_supported(locale):
        locale = locale[:2]

    try:
        return get_catalog(locale, domain).ngettext(key1, key2, num)
    except KeyError:
        return key1
    except IOError:
        return key1