ryshcate / ryshcate / locale.py

# -*- coding: utf-8 -*-
"""
ryshcate.locale
===============
Tools for localizing languages and dates/times.

:copyright: 2010 Matthew "LeafStorm" Frazier
:license:   MIT/X11, see LICENSE for details
"""
from flask import session
from flaskext.babel import (Babel, format_date, format_time, format_datetime,
                            gettext, _)
from pytz import common_timezones
from speaklater import make_lazy_string

TRANSLATED_LANGUAGES = [
    ('en', u'English')
]


def lazy_gettext(string, **variables):
    """
    Like :func:`gettext` but the string returned is lazy which means
    it will be translated when it is used as an actual string.

    Example::

        hello = lazy_gettext(u'Hello World')

        @app.route('/')
        def index():
            return unicode(hello)
    """
    return make_lazy_string(gettext, string, **variables)

__ = lazy_gettext


def get_user_locale():
    return session.get('locale')


def get_user_timezone():
    return session.get('timezone')


def setup_babel(app):
    babel_inst = Babel(app)
    babel_inst.localeselector(get_user_locale)
    babel_inst.timezoneselector(get_user_timezone)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.