コード例 #1
0
    def decorated_view(request, *args, **kwargs):
        user = request.user

        if user.is_anonymous:
            return reject_request(request)

        if user.has_perms(['wagtailadmin.access_admin']):
            preferred_language = None
            if hasattr(user, 'wagtail_userprofile'):
                preferred_language = user.wagtail_userprofile.get_preferred_language(
                )
                l18n.set_language(preferred_language)
                time_zone = user.wagtail_userprofile.get_current_time_zone()
                activate_tz(time_zone)
            if preferred_language:
                with override(preferred_language):
                    return view_func(request, *args, **kwargs)
            else:
                return view_func(request, *args, **kwargs)

        if not request.is_ajax():
            messages.error(request,
                           _('You do not have permission to access the admin'))

        return reject_request(request)
コード例 #2
0
ファイル: tztool.py プロジェクト: CZ-NIC/foris
def gencountries():
    tzdata = maketzdata()

    countries = {}
    l18n.set_language("en")
    for luci_tz, country, city, zoneinfo in tzdata:
        countries[country] = l18n.territories[country]
    pickle.dump(countries, file("foris/utils/countries.pickle2", "wb"), protocol=2)
コード例 #3
0
def gencountries():
    tzdata = maketzdata()

    countries = {}
    l18n.set_language("en")
    for luci_tz, country, city, zoneinfo in tzdata:
        countries[country] = unicode(l18n.territories[country])
    pickle.dump(countries,
                file("foris/utils/countries.pickle2", "wb"),
                protocol=2)
コード例 #4
0
ファイル: tztool.py プロジェクト: CZ-NIC/foris
def maketzdata():
    l18n.set_language("en")  # base language is English

    tzdata = []

    for luci_tz, zoneinfo in luci_TZ:
        country = l18n.utils.get_country_code_from_tz(luci_tz.replace(" ", "_"))
        city = l18n.tz_cities[luci_tz.replace(" ", "_")]
        tzdata.append((luci_tz, country, city, zoneinfo))
    return tzdata
コード例 #5
0
    def decorated_view(request, *args, **kwargs):

        user = request.user

        if user.is_anonymous:
            return reject_request(request)

        if user.has_perms(['wagtailadmin.access_admin']):
            try:
                preferred_language = None
                if hasattr(user, 'wagtail_userprofile'):
                    preferred_language = user.wagtail_userprofile.get_preferred_language(
                    )
                    l18n.set_language(preferred_language)
                    time_zone = user.wagtail_userprofile.get_current_time_zone(
                    )
                    activate_tz(time_zone)
                with LogContext(user=user):
                    if preferred_language:
                        with override(preferred_language):
                            response = view_func(request, *args, **kwargs)

                        if hasattr(response, "render"):
                            # If the response has a render() method, Django treats it
                            # like a TemplateResponse, so we should do the same
                            # In this case, we need to guarantee that when the TemplateResponse
                            # is rendered, it is done within the override context manager
                            # or the user preferred_language will not be used
                            # (this could be replaced with simply rendering the TemplateResponse
                            # for simplicity but this does remove some of its middleware modification
                            # potential)
                            render = response.render

                            def overridden_render(response):
                                with override(preferred_language):
                                    return render()

                            response.render = types.MethodType(
                                overridden_render, response)
                            # decorate the response render method with the override context manager
                        return response
                    else:
                        return view_func(request, *args, **kwargs)

            except PermissionDenied:
                if request.headers.get('x-requested-with') == 'XMLHttpRequest':
                    raise

                return permission_denied(request)

        if not request.headers.get('x-requested-with') == 'XMLHttpRequest':
            messages.error(request,
                           _('You do not have permission to access the admin'))

        return reject_request(request)
コード例 #6
0
def maketzdata():
    l18n.set_language("en")  # base language is English

    tzdata = []

    for luci_tz, zoneinfo in luci_TZ:
        country = l18n.utils.get_country_code_from_tz(luci_tz.replace(
            " ", "_"))
        city = unicode(l18n.tz_cities[luci_tz.replace(" ", "_")])
        tzdata.append((luci_tz, country, city, zoneinfo))
    return tzdata
コード例 #7
0
ファイル: decorators.py プロジェクト: bbusenius/wagtail
    def decorated_view(request, *args, **kwargs):
        user = request.user

        if user.is_anonymous:
            return reject_request(request)

        if user.has_perms(['wagtailadmin.access_admin']):
            if hasattr(user, 'wagtail_userprofile'):
                language = user.wagtail_userprofile.get_preferred_language()
                l18n.set_language(language)
                activate_lang(language)
                time_zone = user.wagtail_userprofile.get_current_time_zone()
                activate_tz(time_zone)
            return view_func(request, *args, **kwargs)

        if not request.is_ajax():
            messages.error(request, _('You do not have permission to access the admin'))

        return reject_request(request)
コード例 #8
0
def makelocale(lang, plural_forms=None):
    plural_forms = plural_forms or "nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;"
    import polib
    po = polib.POFile()

    tzdata = maketzdata()

    countries = set()
    regions = set()
    cities = set()

    l18n.set_language("en")
    for luci_tz, country, city, zoneinfo in tzdata:
        regions.add(luci_tz.split("/")[0])
        countries.add(unicode(l18n.territories[country]))
        cities.add(city)

    po.metadata = {
        'Project-Id-Version': "Foris TZ info translations",
        'POT-Creation-Date': "2016-04-28 15:04+0200",
        'PO-Revision-Date': "2016-04-28 13:55+0200",
        'Last-Translator': "Automatically generated <*****@*****.**>",
        'Language': lang,
        'MIME-Version': "1.0",
        'Content-Type': "text/plain; charset=UTF-8",
        'Content-Transfer-Encoding': "8bit",
        'Plural-Forms': plural_forms,
    }

    # Activate translation for the requested language
    l18n.set_language(lang)
    translations = {}
    for part in (regions, cities, countries):
        for x in part:
            translations[x] = unicode(l18n.translation.L18NLazyString(x))

    for msgid, msgstr in translations.iteritems():
        po.append(polib.POEntry(msgid=msgid, msgstr=msgstr))

    po.save("foris/locale/%s/LC_MESSAGES/tzinfo.po" % lang)
コード例 #9
0
ファイル: tztool.py プロジェクト: CZ-NIC/foris
def makelocale(lang, plural_forms=None):
    plural_forms = plural_forms or "nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;"
    import polib
    po = polib.POFile()

    tzdata = maketzdata()

    countries = set()
    regions = set()
    cities = set()

    l18n.set_language("en")
    for luci_tz, country, city, zoneinfo in tzdata:
        regions.add(luci_tz.split("/")[0])
        countries.add(l18n.territories[country])
        cities.add(city)

    po.metadata = {
        'Project-Id-Version': "Foris TZ info translations",
        'POT-Creation-Date': "2016-04-28 15:04+0200",
        'PO-Revision-Date': "2016-04-28 13:55+0200",
        'Last-Translator': "Automatically generated <*****@*****.**>",
        'Language': lang,
        'MIME-Version': "1.0",
        'Content-Type': "text/plain; charset=UTF-8",
        'Content-Transfer-Encoding': "8bit",
        'Plural-Forms': plural_forms,
    }

    # Activate translation for the requested language
    l18n.set_language(lang)
    translations = {}
    for part in (regions, cities, countries):
        for x in part:
            translations[x] = l18n.translation.L18NLazyString(x)

    for msgid, msgstr in translations.items():
        po.append(polib.POEntry(msgid=msgid, msgstr=msgstr))

    po.save("foris/locale/%s/LC_MESSAGES/tzinfo.po" % lang)
コード例 #10
0
ファイル: _base.py プロジェクト: olopost/l18n
 def tearDownClass(cls):
     l18n.set_language(None)
コード例 #11
0
ファイル: _base.py プロジェクト: olopost/l18n
 def setUpClass(cls):
     l18n.set_language(cls.language)