I use settings in models/0.py
from gluon.storage import Storage
LANGS = Storage({
'ru': ['Русский', 'ru.png'],
'en': ['English', 'gb.png'],
'ge': ['German', 'ge.png'],
'tr': ['Türkçe', 'tr.png'],
})
settings = Storage(
develop = True,
migrate = True,
title = 'b..',
subtitle = 'Games ..s',
)
# if in request is change of lang
#
lang = request.vars.lang
if lang and lang != session.lang:
session.lang = lang
vars = request.vars
vars.pop('lang')
#print '0.py - lang -> %s' % session.lang
redirect(URL( args = request.args, vars = vars))
if session.lang and T.accepted_language != session.lang:
print '0.py - forsed T.[%s]' % session.lang
T.force(session.lang)
in models/menu.py
def lang_sel():
langs = []
for (n,l) in LANGS.iteritems():
if session.lang == n: continue
vars = request.vars.copy()
vars['lang'] = n
langs.append((
CAT(IMG(_src=URL('static', 'images/flags/' + l[1]),
_width=30, _alt=''),
' ',l[0]), False, URL(args=request.args, vars=vars))
)
return langs
response.menu_man = []
lang1 = session.lang or 'en'
lang = LANGS[lang1]
if not lang:
session.lang = None
else:
#print lang1, lang, lang_sel()
response.menu_man.append(
[CAT(IMG(_src=URL('static', 'images/flags/' + lang[1]), _width=30,
_alt=''), ' ', lang[0]),
False, None, lang_sel()])
in views/layout.html
<div class="{{='nav-collapse' if is_mobile else 'nav pull-right'}}">
{{if response.menu_man:}}
{{=MENU(response.menu_man, _class='mobile-menu nav' if is_mobile
else 'nav
pull-right',mobile=is_mobile,li_class='dropdown',ul_class='dropdown-menu')}}
{{pass}}
</div>
<div class="{{='nav-collapse' if is_mobile else 'nav'}}">
{{if response.menu:}}
{{=MENU(response.menu, _class='mobile-menu nav' if is_mobile else
'nav',mobile=is_mobile,li_class='dropdown',ul_class='dropdown-menu')}}
{{pass}}
</div><!--/.nav-collapse -->
example here
http://lite.cash/bets/default/index
среда, 6 марта 2013 г., 9:15:11 UTC+3 пользователь TestFirstName
TestLastName написал:
>
> where to set up localization in web2py
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.