Back to index

plone3  3.1.7
languages.py
Go to the documentation of this file.
00001 # -*- coding: UTF-8 -*-
00002 
00003 from plone.app.i18n.locales.interfaces import IContentLanguages
00004 from plone.app.i18n.locales.interfaces import IMetadataLanguages
00005 from plone.app.i18n.locales.interfaces import IModifiableLanguageAvailability
00006 
00007 from plone.i18n.locales.languages import ContentLanguageAvailability
00008 from plone.i18n.locales.languages import MetadataLanguageAvailability
00009 from plone.i18n.locales.languages import LanguageAvailability
00010 
00011 from zope.interface import implements
00012 
00013 from OFS.SimpleItem import SimpleItem
00014 
00015 class Languages(SimpleItem, LanguageAvailability):
00016     """ A base implementation for persistent utilities implementing
00017     IModifiableLanguageAvailability.
00018 
00019     Let's make sure that this implementation actually fulfills the API.
00020 
00021       >>> from zope.interface.verify import verifyClass
00022       >>> verifyClass(IModifiableLanguageAvailability, Languages)
00023       True
00024     """
00025     implements(IModifiableLanguageAvailability)
00026 
00027     def __init__(self):
00028         self.languages = ['en']
00029         self.combined = []
00030 
00031     def getAvailableLanguages(self, combined=False):
00032         """Returns a sequence of language tags for available languages.
00033         """
00034         if combined:
00035             languages = list(self.languages)
00036             languages.extend(self.combined)
00037             return languages
00038         else:
00039             return list(self.languages)
00040 
00041     def setAvailableLanguages(self, languages, combined=False):
00042         """Sets a list of available language tags.
00043         """
00044         languages = list(languages)
00045         if combined:
00046             self.combined = languages
00047         else:
00048             self.languages = languages
00049 
00050 
00051 class ContentLanguages(Languages, ContentLanguageAvailability):
00052     """A local utility storing a list of available content languages.
00053 
00054     Let's make sure that this implementation actually fulfills the API.
00055 
00056       >>> from zope.interface.verify import verifyClass
00057       >>> verifyClass(IContentLanguages, ContentLanguages)
00058       True
00059     """
00060     implements(IContentLanguages)
00061 
00062     id  = 'plone_app_content_languages'
00063     title = 'Manages available content languages'
00064     meta_type = 'Plone App I18N Content Languages'
00065 
00066 
00067 class MetadataLanguages(Languages, MetadataLanguageAvailability):
00068     """A local utility storing a list of available metadata languages.
00069 
00070     Let's make sure that this implementation actually fulfills the API.
00071 
00072       >>> from zope.interface.verify import verifyClass
00073       >>> verifyClass(IMetadataLanguages, MetadataLanguages)
00074       True
00075     """
00076     implements(IMetadataLanguages)
00077 
00078     id  = 'plone_app_metadata_languages'
00079     title = 'Manages available metadata languages'
00080     meta_type = 'Plone App I18N Metadata Languages'