擅长:python、mysql、java
<pre><code>def add_localizer(event):
request = event.request
languages = ('en','us','es')
deflang = 'pt'
# CHECK current page
if 'page' in request.matchdict:
currentpage = DBSession.query(Pages).filter_by(url=request.matchdict['page']).first()
#SET pages languages
languages = currentpage.Languages.split(',')
deflang = currentpage.defLang
# - CHANGED
dln = default_locale_negotiator(request)
if not dln or dln not in languages:
#set the default language
request._LOCALE_ = deflang
localizer = get_localizer(request)
request.lang = localizer.locale_name
def auto_translate(string):
return localizer.translate(self.tsf(string))
request.localizer = localizer
request.translate = auto_translate
</code></pre>
<p>谢谢</p>