Added I18nManager base mixin class
authorThierry Florac <thierry.florac@onf.fr>
Thu, 08 Oct 2015 09:25:29 +0200
changeset 16 9c58c8a2796b
parent 15 2f14e76d44f7
child 17 fa883acc1f55
Added I18nManager base mixin class
src/pyams_i18n/content.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_i18n/content.py	Thu Oct 08 09:25:29 2015 +0200
@@ -0,0 +1,39 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_i18n.interfaces import II18nManager, INegotiator
+
+# import packages
+from pyams_utils.registry import query_utility
+from zope.interface import implementer
+from zope.schema.fieldproperty import FieldProperty
+
+
+@implementer(II18nManager)
+class I18nManagerMixin(object):
+    """I18n manager class mixin"""
+
+    languages = FieldProperty(II18nManager['languages'])
+
+    def get_languages(self):
+        langs = []
+        negotiator = query_utility(INegotiator)
+        if negotiator is not None:
+            langs.append(negotiator.server_language)
+        langs.extend(sorted(filter(lambda x: x not in langs, self.languages or ())))
+        return langs