~hardware-certification/zope3/certify-staging-2.5

« back to all changes in this revision

Viewing changes to src/zope/app/i18n/.svn/text-base/interfaces.py.svn-base

  • Committer: Marc Tardif
  • Date: 2008-04-26 19:03:34 UTC
  • Revision ID: cr3@lime-20080426190334-u16xo4llz56vliqf
Initial import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2003 Zope Corporation and Contributors.
 
4
# All Rights Reserved.
 
5
#
 
6
# This software is subject to the provisions of the Zope Public License,
 
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
 
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 
11
# FOR A PARTICULAR PURPOSE.
 
12
#
 
13
##############################################################################
 
14
"""Placeful internationalization of content objects.
 
15
 
 
16
$Id$
 
17
"""
 
18
__docformat__ = 'restructuredtext'
 
19
 
 
20
from zope.interface import Interface
 
21
from zope.i18n.interfaces import ITranslationDomain, IMessageCatalog
 
22
from zope.app.container.interfaces import IContainer
 
23
 
 
24
 
 
25
class IWriteTranslationDomain(Interface):
 
26
    """This interface describes the methods that are necessary for an editable
 
27
    Translation Domain to work.
 
28
 
 
29
    For a translation domain to be editable its 'messages' have to support
 
30
    the following information: id, string, domain, language, date
 
31
 
 
32
    Most of the information will be natural, since they are required by the
 
33
    translation domain, but especially the date is not a necessary info
 
34
    (in fact, it is meta data)
 
35
    """
 
36
 
 
37
    def getMessage(msgid, langauge):
 
38
        """Get the full message of a particular language."""
 
39
 
 
40
    def getMessageIds(filter='%'):
 
41
        """Get all the message ids of this domain."""
 
42
 
 
43
    def getMessages():
 
44
        """Get all the messages of this domain."""
 
45
 
 
46
    def getAllLanguages():
 
47
        """Find all the languages that are available"""
 
48
 
 
49
    def getAvailableLanguages():
 
50
        """Find all the languages that are available."""
 
51
 
 
52
    def addMessage(msgid, msg, language, mod_time=None):
 
53
        """Add a message to the translation domain.
 
54
 
 
55
        If `mod_time` is ``None``, then the current time should be inserted.
 
56
        """
 
57
 
 
58
    def updateMessage(msgid, msg, language, mod_time=None):
 
59
        """Update a message in the translation domain.
 
60
 
 
61
        If `mod_time` is ``None``, then the current time should be inserted.
 
62
        """
 
63
 
 
64
    def deleteMessage(domain, msgid, language):
 
65
        """Delete a messahe in the translation domain."""
 
66
 
 
67
    def addLanguage(language):
 
68
        """Add Language to Translation Domain"""
 
69
 
 
70
    def deleteLanguage(language):
 
71
        """Delete a Domain from the Translation Domain."""
 
72
 
 
73
 
 
74
class ISyncTranslationDomain(Interface):
 
75
    """This interface allows translation domains to be synchronized. The
 
76
    following four synchronization states can exist:
 
77
 
 
78
    0 - uptodate: The two messages are in sync.
 
79
             Default Action: Do nothing.
 
80
 
 
81
    1 - new: The message exists on the foreign TS, but is locally unknown.
 
82
             Default Action: Add the message to the local catalog.
 
83
 
 
84
    2 - older: The local version of the message is older than the one on
 
85
             the server.
 
86
             Default Action: Update the local message.
 
87
 
 
88
    3 - newer: The local version is newer than the foreign version.
 
89
             Default Action: Do nothing.
 
90
 
 
91
    4 - deleted: The message does not exist in the foreign TS.
 
92
             Default Action: Delete local version of message.
 
93
    """
 
94
 
 
95
    def getMessagesMapping(languages, foreign_messages):
 
96
        """Creates a mapping of the passed foreign messages and the local ones.
 
97
        Returns a status report in a dictionary with keys of the form
 
98
        (msgid, domain, language) and values being a tuple of:
 
99
 
 
100
        foreign_mod_date, local_mod_date
 
101
        """
 
102
 
 
103
    def synchronize(messages_mapping):
 
104
        """Update the local message catalogs based on the foreign data.
 
105
        """
 
106
 
 
107
 
 
108
class ILocalTranslationDomain(ITranslationDomain,
 
109
                              IWriteTranslationDomain,
 
110
                              ISyncTranslationDomain,
 
111
                              IContainer):
 
112
    """This is the common and full-features translation domain. Almost all
 
113
    translation domain implementations will use this interface.
 
114
 
 
115
    An exception to this is the `GlobalMessageCatalog` as it will be read-only.
 
116
    """
 
117
 
 
118
 
 
119
class ILocalMessageCatalog(IMessageCatalog):
 
120
    """If this interfaces is implemented by a message catalog, then we will be
 
121
    able to update our messages.
 
122
 
 
123
    Note that not all methods here require write access, but they should
 
124
    not be required for an `IReadMessageCatalog` and are used for editing
 
125
    only. Therefore this is the more suitable interface to put them.
 
126
    """
 
127
 
 
128
    def getFullMessage(msgid):
 
129
        """Get the message data and meta data as a nice dictionary. More
 
130
        advanced implementation might choose to return an object with
 
131
        the data, but the object should then implement `IEnumerableMapping`.
 
132
 
 
133
        An exception is raised if the message id is not found.
 
134
        """
 
135
 
 
136
    def setMessage(msgid, message, mod_time=None):
 
137
        """Set a message to the catalog. If `mod_time` is ``None`` use the
 
138
        current time instead as modification time."""
 
139
 
 
140
    def deleteMessage(msgid):
 
141
        """Delete a message from the catalog."""
 
142
 
 
143
    def getMessageIds():
 
144
        """Get a list of all the message ids."""
 
145
 
 
146
    def getMessages():
 
147
        """Get a list of all the messages."""
 
148