Préférences linguistiques enregistrées dans les données utilisateur et utilisées...
authorBenoît Pin <pin@cri.ensmp.fr>
Wed, 17 Sep 2014 13:05:01 +0000 (15:05 +0200)
committerBenoît Pin <pin@cri.ensmp.fr>
Wed, 17 Sep 2014 13:05:01 +0000 (15:05 +0200)
overrides.zcml
skins/custom_generic/personalize_form.pt
userlanguages.py [new file with mode: 0644]

index bf37e72..3c01665 100644 (file)
              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>
index 6836348..149f1dc 100755 (executable)
                   <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 (file)
index 0000000..8103d15
--- /dev/null
@@ -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()