From: Benoît Pin <pin@cri.ensmp.fr> Date: Wed, 17 Sep 2014 13:05:01 +0000 (+0200) Subject: Préférences linguistiques enregistrées dans les données utilisateur et utilisées... X-Git-Url: https://scm.cri.ensmp.fr/git/Plinn.git/commitdiff_plain/c15d698f84d77c34393d33dbe492d44694619010 Préférences linguistiques enregistrées dans les données utilisateur et utilisées en priorité (par rapport au préférences du navigateur). --- diff --git a/overrides.zcml b/overrides.zcml index bf37e72..3c01665 100644 --- a/overrides.zcml +++ b/overrides.zcml @@ -15,4 +15,10 @@ Products.CMFCore.interfaces.ICatalogTool" provides="Products.CMFCore.interfaces.IIndexableObject" factory=".catalog_adapters.PlinnIndexableObjectWrapper" /> + <adapter + for="zope.publisher.interfaces.http.IHTTPRequest" + provides="zope.i18n.interfaces.IUserPreferredLanguages" + factory=".userlanguages.AuthenticatedUserLanguages" + /> + </configure> diff --git a/skins/custom_generic/personalize_form.pt b/skins/custom_generic/personalize_form.pt index 6836348..149f1dc 100755 --- a/skins/custom_generic/personalize_form.pt +++ b/skins/custom_generic/personalize_form.pt @@ -41,6 +41,16 @@ <input type="text" name="email" value="" tal:attributes="value python:member.getProperty('email', None)" /> </td> </tr> + <tr> + <th i18n:translate="">Preferred languages</th> + <td> + <input type="text" name="preferred_languages:tokens" + tal:attributes="value python:' '.join(member.getProperty('preferred_languages', []))"/> + <dl class="FieldHelp"> + <dd i18n:translate="">Please enter language codes separated by spaces.</dd> + </dl> + </td> + </tr> <tr> <td><br /></td> <td> diff --git a/userlanguages.py b/userlanguages.py new file mode 100644 index 0000000..8103d15 --- /dev/null +++ b/userlanguages.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +from zope.publisher.browser import BrowserLanguages +from Products.CMFCore.utils import getUtilityByInterfaceName + +class AuthenticatedUserLanguages(BrowserLanguages): + + def getPreferredLanguages(self) : + mtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IMembershipTool') + if mtool.isAnonymousUser() : + return super(AuthenticatedUserLanguages, self).getPreferredLanguages() + else : + m = mtool.getAuthenticatedMember() + userLangs = m.getProperty('preferred_languages', []) + return userLangs or super(AuthenticatedUserLanguages, self).getPreferredLanguages()