Added I18n JSON methods
authorThierry Florac <tflorac@ulthar.net>
Tue, 03 Jun 2014 23:32:27 +0200
changeset 30 3c2c5114bc5f
parent 29 d4270d6b448a
child 31 103c1f925a8b
Added I18n JSON methods
src/ztfy/myams/json/__init__.py
src/ztfy/myams/json/configure.zcml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ztfy/myams/json/__init__.py	Tue Jun 03 23:32:27 2014 +0200
@@ -0,0 +1,25 @@
+#
+# Copyright (c) 2012 Thierry Florac <tflorac AT onf.fr>
+# All Rights Reserved.
+#
+
+
+# import standard packages
+
+# import Zope3 interfaces
+from z3c.language.session.interfaces import ILanguageSession
+
+# import local interfaces
+
+# import Zope3 packages
+
+# import local packages
+from z3c.jsonrpc.publisher import MethodPublisher
+
+
+class I18nMethodsPublisher(MethodPublisher):
+    """I18n methods publisher"""
+
+    def setUserLanguage(self, lang):
+        if lang:
+            ILanguageSession(self.request).setLanguage(lang)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ztfy/myams/json/configure.zcml	Tue Jun 03 23:32:27 2014 +0200
@@ -0,0 +1,16 @@
+<configure
+	xmlns="http://namespaces.zope.org/z3c"
+	xmlns:zcml="http://namespaces.zope.org/zcml"
+	i18n_domain="ztfy.myams">
+
+	<configure zcml:condition="installed ztfy.i18n">
+
+		<jsonrpc
+			for="*"
+			class=".I18nMethodsPublisher"
+			methods="setUserLanguage"
+			permission="zope.View" />
+
+	</configure>
+
+</configure>