Hello,
I copied the code from admin\views\layout.html to myapp\views\default\user.html and made 2 small changes to only allow 'en' and 'pt' and to the path.
{{if hasattr(T,'get_possible_languages_info'):}}
<select name="adminlanguage" onchange="var date = new Date();cookieDate=date.setTime(date.getTime()+(100*24*60*60*1000));document.cookie='adminLanguage='+this.options[this.selectedIndex].id+'; expires='+cookieDate+'; path='/user/login?_next=/';window.location.reload()">
{{for langinfo in sorted([(code,info[1]) for code, info in iteritems(T.get_possible_languages_info()) if code != 'default' and code in ['pt', 'en']]):}}
<option {{=T.accepted_language==langinfo[0] and 'selected' or ''}} {{='id='+langinfo[0]}} >{{=langinfo[1]}}</option>
{{pass}}
</select>
{{pass}}
The page does not refresh and does not change language. The selection sticks.
If I change the path to /, like it is in the admin\views\layout.html, the page refreshes but the selection always returns to 'en' and the page is always in 'en'.
I tried this code (modified) in db.py from another article in the forum:
if 'adminlanguage' in request.cookies and request.cookies['adminlanguage'] is not None:
print('in cookie')
T.force(request.cookies['adminlanguage'].value)
else:
print('force en')
T.force('en')
but I always get 'force en' in the console.
Nothing worked.
Thanks,
JM