当前位置: 首页>>代码示例>>Python>>正文


Python config.LANGUAGES类代码示例

本文整理汇总了Python中config.LANGUAGES的典型用法代码示例。如果您正苦于以下问题:Python LANGUAGES类的具体用法?Python LANGUAGES怎么用?Python LANGUAGES使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LANGUAGES类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_locale

def get_locale():
	if (g.user is not None) and (not g.user.is_anonymous()):
		if g.user.lang_id is not None:
			app.logger.info(g.user.lang.short_name)
			return g.user.lang.short_name
		else:
			accept_lang = request.accept_languages.best_match(LANGUAGES.keys())
			if accept_lang is None or (accept_lang == ''):
				accept_lang = 'en'			
			g.user.lang = Language.query.filter_by(short_name = accept_lang).first()
			db.session.add(g.user)
			db.session.commit()
			return g.user.lang.short_name
	else:
		return request.accept_languages.best_match(LANGUAGES.keys())
开发者ID:ManGregory,项目名称:microblog,代码行数:15,代码来源:views.py

示例2: get_locale

def get_locale():
    print "hi"
    # for testing, hard code the language to show
    # return 'fr'
    print request.accept_languages
    # in production use the below to change language based on http 'accept-languages' header:
    return request.accept_languages.best_match(LANGUAGES.keys())
开发者ID:dan-may,项目名称:translation,代码行数:7,代码来源:views.py

示例3: get_locale

def get_locale():
    if request.args.get('lang'):
        g.lang = request.args.get('lang')
    if g.get('lang'):
        return g.lang
    g.lang = request.accept_languages.best_match(LANGUAGES.keys())
    return g.lang
开发者ID:Showfom,项目名称:iwho.is,代码行数:7,代码来源:views.py

示例4: get_locale

def get_locale():
    # if language forced
    if 'LANGUAGE'in app.config:
        if app.config['LANGUAGE'] in LANGUAGES.keys():
	    return app.config['LANGUAGE']
	else:
            print 'Language not found in Config - LANGUAGES'
    # else if a user is logged in, use the locale from the user settings
    user = getattr(g, 'user', None)
    
    if user is not None:
	print user.locale
        return user.locale
    # otherwise try to guess the language from the user accept
    # header the browser transmits.  We support de/fr/en in this
    # example.  The best match wins.
    return request.accept_languages.best_match(LANGUAGES.keys()) # 'it'
开发者ID:mattbt,项目名称:fsn-p3-itemcatalog,代码行数:17,代码来源:translations.py

示例5: get_locale

def get_locale():
    # if a user is logged in, use the locale from the user settings
    # user = getattr(g, 'user', None)
    # if user is not None:
    #     return user.locale
    # otherwise try to guess the language from the user accept
    # header the browser transmits.  We support de/fr/en in this
    # example.  The best match wins.
    return request.accept_languages.best_match(LANGUAGES.keys())
开发者ID:fdumpling,项目名称:canjs-flask-example,代码行数:9,代码来源:views.py

示例6: before

def before():
    g.languages = LANGUAGES
    g.locale = request.cookies.get('locale')
    if g.locale is None:
        g.locale = request.accept_languages.best_match(LANGUAGES.keys())

        @after_this_request
        def remember_language(response):
            response.set_cookie('locale', g.locale)
            return response

    g.search_form = SearchForm()
    if current_user and current_user.is_authenticated:
        current_user.see_you()
        g.roles = [role.role_name for role in current_user.roles]
开发者ID:dregor,项目名称:flask,代码行数:15,代码来源:views.py

示例7: get_locale

def get_locale():
    supported_languages = LANGUAGES.keys()
    language_arg = request.args.get('l')
    if language_arg is not None:
        if language_arg in supported_languages:
            @after_this_request
            def remember_language(response):
                response.set_cookie('language', language_arg)

            return language_arg
    else:
        language_cookie = request.cookies.get('language')
        if language_cookie in supported_languages:
            return language_cookie

    return request.accept_languages.best_match(supported_languages)
开发者ID:ijabz,项目名称:critiquebrainz,代码行数:16,代码来源:babel.py

示例8: get_locale

def get_locale():
    """
    the function targeted by this selector above will be called before each request, to give us a chance to choose the
    language when producing its response.
    For now we will do something simple, we will just read the Accept-Lanugages header sent by the browser in the HTTP
    request and find the best-matching language from the list we support. This is simple, 'best_match' method does it
    for us.

    Accept-Languages header in most browsers is config'd by default with language selected at OS level, but all give
    users chance to select others. Users can provide a list of languages, each with a weight. Looks like:
    Accept-Language: da, en-gb;q=0.8, en;q=0.7
    Danish default weight=1 is preferred, followed by GB-English, finally with generic english.

    To translate text, use gettext(string to translate) within Python code, or {{ _('string')}} inside HTML
    :return:
    """
    #return 'es'
    return request.accept_languages.best_match(LANGUAGES.keys())  # temp set to spanish for testing
开发者ID:Toruitas,项目名称:Python,代码行数:18,代码来源:views.py

示例9: get_locale

def get_locale():
    headers = request.headers.get('User-Agent')
    app.logger.info('Header info: ' + headers)
    return request.accept_languages.best_match(LANGUAGES.keys()) or 'en'
开发者ID:Pballer,项目名称:prayer,代码行数:4,代码来源:views.py

示例10:

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys

if sys.platform == 'win32':
    pybabel = r"C:\Python27\Scripts\pybabel.exe"
else:
    pybabel = "pybabel"

from config import LANGUAGES
os.system(pybabel + ' extract -F babel.cfg -k lazy_gettext -k T -o messages.pot ..\\')

for lang in LANGUAGES.keys():
    os.system('%s init -i messages.pot -d . -l "%s"' % (pybabel, lang.replace("-","_")))

os.system("pause")
os.unlink('messages.pot')

开发者ID:13917547121,项目名称:me,代码行数:29,代码来源:pybabel_init.py

示例11: get_locale

def get_locale():
    if current_user and current_user.is_authenticated():
        return current_user.lang
    return request.accept_languages.best_match(LANGUAGES.keys())
开发者ID:Tibodef,项目名称:PythonBlog,代码行数:4,代码来源:views.py

示例12: get_locale

def get_locale():
    try:
        return request.cookies["selected_lang"]
    except:
        return request.accept_languages.best_match(LANGUAGES.keys())
开发者ID:SaptakS,项目名称:open-event-orga-server,代码行数:5,代码来源:variables.py

示例13: get_locale

def get_locale():
    # if a user is logged in, use the locale from the user settings
    if current_user and current_user.locale is not None and \
            not current_user.is_anonymous():
        return current_user.locale
    return request.accept_languages.best_match(LANGUAGES.keys())
开发者ID:10280588,项目名称:viaduct,代码行数:6,代码来源:__init__.py

示例14: get_locale

def get_locale():
    """Return the best matched language supported."""
    return request.accept_languages.best_match(LANGUAGES.keys())
开发者ID:carriercomm,项目名称:kilink,代码行数:3,代码来源:kilink.py

示例15: locale

 def locale(self):
   if self.request.get('lang'):
     return self.request.get('lang')
   else:
     return LANGUAGES.get(self.request.headers.get('X-AppEngine-Country')) or 'en'
开发者ID:sasxa,项目名称:mapload,代码行数:5,代码来源:__init__.py


注:本文中的config.LANGUAGES类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。