1
##############################################################################
3
# Copyright (c) 2003 Zope Corporation and Contributors.
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.
13
##############################################################################
14
"""Placeful internationalization of content objects.
18
__docformat__ = 'restructuredtext'
20
from zope.interface import Interface
21
from zope.i18n.interfaces import ITranslationDomain, IMessageCatalog
22
from zope.app.container.interfaces import IContainer
25
class IWriteTranslationDomain(Interface):
26
"""This interface describes the methods that are necessary for an editable
27
Translation Domain to work.
29
For a translation domain to be editable its 'messages' have to support
30
the following information: id, string, domain, language, date
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)
37
def getMessage(msgid, langauge):
38
"""Get the full message of a particular language."""
40
def getMessageIds(filter='%'):
41
"""Get all the message ids of this domain."""
44
"""Get all the messages of this domain."""
46
def getAllLanguages():
47
"""Find all the languages that are available"""
49
def getAvailableLanguages():
50
"""Find all the languages that are available."""
52
def addMessage(msgid, msg, language, mod_time=None):
53
"""Add a message to the translation domain.
55
If `mod_time` is ``None``, then the current time should be inserted.
58
def updateMessage(msgid, msg, language, mod_time=None):
59
"""Update a message in the translation domain.
61
If `mod_time` is ``None``, then the current time should be inserted.
64
def deleteMessage(domain, msgid, language):
65
"""Delete a messahe in the translation domain."""
67
def addLanguage(language):
68
"""Add Language to Translation Domain"""
70
def deleteLanguage(language):
71
"""Delete a Domain from the Translation Domain."""
74
class ISyncTranslationDomain(Interface):
75
"""This interface allows translation domains to be synchronized. The
76
following four synchronization states can exist:
78
0 - uptodate: The two messages are in sync.
79
Default Action: Do nothing.
81
1 - new: The message exists on the foreign TS, but is locally unknown.
82
Default Action: Add the message to the local catalog.
84
2 - older: The local version of the message is older than the one on
86
Default Action: Update the local message.
88
3 - newer: The local version is newer than the foreign version.
89
Default Action: Do nothing.
91
4 - deleted: The message does not exist in the foreign TS.
92
Default Action: Delete local version of message.
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:
100
foreign_mod_date, local_mod_date
103
def synchronize(messages_mapping):
104
"""Update the local message catalogs based on the foreign data.
108
class ILocalTranslationDomain(ITranslationDomain,
109
IWriteTranslationDomain,
110
ISyncTranslationDomain,
112
"""This is the common and full-features translation domain. Almost all
113
translation domain implementations will use this interface.
115
An exception to this is the `GlobalMessageCatalog` as it will be read-only.
119
class ILocalMessageCatalog(IMessageCatalog):
120
"""If this interfaces is implemented by a message catalog, then we will be
121
able to update our messages.
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.
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`.
133
An exception is raised if the message id is not found.
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."""
140
def deleteMessage(msgid):
141
"""Delete a message from the catalog."""
144
"""Get a list of all the message ids."""
147
"""Get a list of all the messages."""