Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
PlacelessTranslationService.GettextMessageCatalog.GettextMessageCatalog Class Reference
Inheritance diagram for PlacelessTranslationService.GettextMessageCatalog.GettextMessageCatalog:
Inheritance graph
[legend]
Collaboration diagram for PlacelessTranslationService.GettextMessageCatalog.GettextMessageCatalog:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def filtered_manage_options
def reload
def queryMessage
def getLanguage
def getLanguageName
def getOtherLanguages
def getDomain
def getIdentifier
def getId
def getInfo
def isRTL
def Title
def get_size
def getModTime
def getObjectFSPath
def manage_afterAdd
def manage_beforeDelete
def manage_afterClone
def file_exists
def getEncoding
def getHeader
def displayInfo

Public Attributes

 id
 preferred_encodings
 name
 default_zope_data_encoding
 title

Static Public Attributes

string meta_type = 'Gettext Message Catalog'
string icon = 'misc_/PlacelessTranslationService/GettextMessageCatalog.png'
int isPrincipiaFolderish = 0
int isTopLevelPrincipiaApplicationObject = 0
tuple security = ClassSecurityInfo()
tuple manage_options
tuple index_html = ptFile('index_html', globals(), 'www', 'catalog_info')
tuple zmi_test = ptFile('zmi_test', globals(), 'www', 'catalog_test')

Private Member Functions

def _prepareTranslations
def _doPrepareTranslations
def _getMoFile
def _getPoFile
def _readFile
def _updateFromFS
def _getModTime

Private Attributes

 _pofile
 _mod_time
 _language
 _domain
 _v_tro
 _other_languages
 _is_rtl

Detailed Description

Message catalog that wraps a .po file in the filesystem and stores
the compiled po file in the zodb

Definition at line 165 of file GettextMessageCatalog.py.


Constructor & Destructor Documentation

def PlacelessTranslationService.GettextMessageCatalog.GettextMessageCatalog.__init__ (   self,
  id,
  pofile,
  language = None,
  domain = None 
)
Initialize the message catalog

Definition at line 179 of file GettextMessageCatalog.py.

00179 
00180     def __init__(self, id, pofile, language=None, domain=None):
00181         """Initialize the message catalog"""
00182         self._pofile   = make_relative_location(pofile)
00183         self.id        = id
00184         self._mod_time = self._getModTime()
00185         self._language = language
00186         self._domain   = domain
00187         self._prepareTranslations(0)


Member Function Documentation

Generate the translation object from a po file

Definition at line 199 of file GettextMessageCatalog.py.

00199 
00200     def _doPrepareTranslations(self):
00201         """Generate the translation object from a po file
00202         """
00203         self._updateFromFS()
00204         tro = None
00205         if getattr(self, '_v_tro', None) is None:
00206             self._v_tro = tro = translationRegistry.get(self.getId(), None)
00207         if tro is None:
00208             moFile = self._getMoFile()
00209             tro = GNUTranslations(moFile)
00210             if not self._language:
00211                 self._language = (tro._info.get('language-code', None) # new way
00212                                or tro._info.get('language', None)) # old way
00213             if not self._domain:
00214                 self._domain = tro._info.get('domain', None)
00215             if self._language is None or self._domain is None:
00216                 raise ValueError, 'potfile %s has no metadata, PTS needs a language and a message domain!' % os.path.join(*self._pofile)
00217             self._language = self._language.lower().replace('_', '-')
00218             self._other_languages = tro._info.get('x-is-fallback-for', '').split()
00219             self.preferred_encodings = tro._info.get('preferred-encodings', '').split()
00220             self.name = unicode(tro._info.get('language-name', ''), tro._charset)
00221             self.default_zope_data_encoding = tro._charset
00222 
00223             translationRegistry[self.getId()] = self._v_tro = tro
00224 
00225             # right to left support
00226             is_rtl = tro._info.get('x-is-rtl', 'no').strip().lower()
00227             if is_rtl in ('yes', 'y', 'true', '1'):
00228                 self._is_rtl = True
00229             elif is_rtl in ('no', 'n', 'false', '0'):
00230                 self._is_rtl = False
00231             else:
00232                 raise ValueError, 'Unsupported value for X-Is-RTL' % is_rtl
00233             rtlRegistry[self.getId()] = self.isRTL()
00234 
00235             if self.name:
00236                 self.title = '%s language (%s) for %s' % (self._language, self.name, self._domain)
00237             else:
00238                 self.title = '%s language for %s' % (self._language, self._domain)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 371 of file GettextMessageCatalog.py.

00371 
00372     def _getModTime(self):
00373         """
00374         """
00375         try:
00376             mtime = os.stat(self._getPoFile())[ST_MTIME]
00377         except (IOError, OSError):
00378             mtime = 0
00379         return mtime

Here is the call graph for this function:

Here is the caller graph for this function:

get compiled version of the po file as file object

Definition at line 323 of file GettextMessageCatalog.py.

00323 
00324     def _getMoFile(self):
00325         """get compiled version of the po file as file object
00326         """
00327         useCache = True
00328         if useCache:
00329             hit, mof = cachedPoFile(self)
00330             return mof
00331         else:
00332             mo = Msgfmt(self._readFile(), self.getId())
00333             return mo.getAsFile()

get absolute path of the po file as string

Definition at line 334 of file GettextMessageCatalog.py.

00334 
00335     def _getPoFile(self):
00336         """get absolute path of the po file as string
00337         """
00338         prefix, pofile = self._pofile
00339         if prefix == 'ZOPE_HOME':
00340             return os.path.join(ZOPE_HOME, pofile)
00341         elif prefix == 'INSTANCE_HOME':
00342             return os.path.join(INSTANCE_HOME, pofile)
00343         elif prefix == 'CLIENT_HOME':
00344             return os.path.join(CLIENT_HOME, pofile)
00345         else:
00346             return os.path.normpath(pofile)

Here is the caller graph for this function:

Try to generate the translation object
   if fails remove us from registry

Definition at line 188 of file GettextMessageCatalog.py.

00188 
00189     def _prepareTranslations(self, catch=1):
00190         """Try to generate the translation object
00191            if fails remove us from registry
00192         """
00193         try: self._doPrepareTranslations()
00194         except:
00195             if self.getId() in translationRegistry.keys():
00196                 del translationRegistry[self.getId()]
00197             if not catch: raise
00198             else: pass

Here is the caller graph for this function:

Read the data from the filesystem.

Definition at line 347 of file GettextMessageCatalog.py.

00347 
00348     def _readFile(self, reparse=False):
00349         """Read the data from the filesystem.
00350 
00351         """
00352         file = open(self._getPoFile(), 'rb')
00353         data = []
00354         try:
00355             # XXX need more checks here
00356             data = file.readlines()
00357         finally:
00358             file.close()
00359         return data

Here is the call graph for this function:

Here is the caller graph for this function:

Refresh our contents from the filesystem

if the file is newer and we are running in debug mode.

Definition at line 360 of file GettextMessageCatalog.py.

00360 
00361     def _updateFromFS(self):
00362         """Refresh our contents from the filesystem
00363 
00364         if the file is newer and we are running in debug mode.
00365         """
00366         if Globals.DevelopmentMode:
00367             mtime = self._getModTime()
00368             if mtime != self._mod_time:
00369                 self._mod_time = mtime
00370                 self.reload()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 433 of file GettextMessageCatalog.py.

00433 
00434     def displayInfo(self):
00435         self._prepareTranslations()
00436         try: info = self._v_tro._info
00437         except:
00438             # broken catalog probably
00439             info={}
00440         keys = info.keys()
00441         keys.sort()
00442         return [{'name': k, 'value': info[k]} for k in keys] + [
00443             {'name': 'full path', 'value': os.path.join(*self._pofile)},
00444             {'name': 'last modification', 'value': self.getModTime().ISO()}
00445             ]
00446 
00447 InitializeClass(GettextMessageCatalog)
00448 

Here is the call graph for this function:

Definition at line 411 of file GettextMessageCatalog.py.

00411 
00412     def file_exists(self):
00413         try:
00414             file = open(self._getPoFile(), 'rb')
00415         except:
00416             return False
00417         return True

Here is the call graph for this function:

Definition at line 239 of file GettextMessageCatalog.py.

00239 
00240     def filtered_manage_options(self, REQUEST=None):
00241         return self.manage_options

Get the size of the underlying file.

Definition at line 380 of file GettextMessageCatalog.py.

00380 
00381     def get_size(self):
00382         """Get the size of the underlying file."""
00383         return os.path.getsize(self._getPoFile())

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 293 of file GettextMessageCatalog.py.

00293 
00294     def getDomain(self):
00295         """
00296         """
00297         return self._domain

Definition at line 419 of file GettextMessageCatalog.py.

00419 
00420     def getEncoding(self):
00421         try:
00422             content_type = self.getHeader('content-type')
00423             enc = content_type.split(';')[1].strip()
00424             enc = enc.split('=')[1]
00425         except: enc='utf-8'
00426         return enc

Here is the call graph for this function:

Definition at line 427 of file GettextMessageCatalog.py.

00427 
00428     def getHeader(self, header):
00429         self._prepareTranslations()
00430         info = self._v_tro._info
00431         return info.get(header)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 303 of file GettextMessageCatalog.py.

00303 
00304     def getId(self):
00305         """
00306         """
00307         return self.id

Definition at line 298 of file GettextMessageCatalog.py.

00298 
00299     def getIdentifier(self):
00300         """
00301         """
00302         return self.id

Definition at line 308 of file GettextMessageCatalog.py.

00308 
00309     def getInfo(self, name):
00310         """
00311         """
00312         self._prepareTranslations()
00313         return self._v_tro._info.get(name, None)
    

Here is the call graph for this function:

Definition at line 278 of file GettextMessageCatalog.py.

00278 
00279     def getLanguage(self):
00280         """
00281         """
00282         return self._language

Definition at line 283 of file GettextMessageCatalog.py.

00283 
00284     def getLanguageName(self):
00285         """
00286         """
00287         return self.name or self._language

Return the last_modified date of the file we represent.

Returns a DateTime instance.

Definition at line 384 of file GettextMessageCatalog.py.

00384 
00385     def getModTime(self):
00386         """Return the last_modified date of the file we represent.
00387 
00388         Returns a DateTime instance.
00389         """
00390         self._updateFromFS()
00391         return DateTime(self._mod_time)

Here is the call graph for this function:

Here is the caller graph for this function:

Return the path of the file we represent

Definition at line 392 of file GettextMessageCatalog.py.

00392 
00393     def getObjectFSPath(self):
00394         """Return the path of the file we represent"""
00395         return self._getPoFile()

Here is the call graph for this function:

Definition at line 288 of file GettextMessageCatalog.py.

00288 
00289     def getOtherLanguages(self):
00290         """
00291         """
00292         return self._other_languages

Definition at line 314 of file GettextMessageCatalog.py.

00314 
00315     def isRTL(self):
00316         """
00317         """
00318         return self._is_rtl

Definition at line 398 of file GettextMessageCatalog.py.

00398 
    def manage_afterAdd(self, item, container): pass

Definition at line 400 of file GettextMessageCatalog.py.

00400 
00401     def manage_afterClone(self, item): pass

Definition at line 399 of file GettextMessageCatalog.py.

00399 
    def manage_beforeDelete(self, item, container): pass
Queries the catalog for a message

If the message wasn't found the default value or the id is returned.

Definition at line 266 of file GettextMessageCatalog.py.

00266 
00267     def queryMessage(self, id, default=None):
00268         """Queries the catalog for a message
00269 
00270         If the message wasn't found the default value or the id is returned.
00271         """
00272         try:
00273             return getMessage(translationRegistry[self.getId()],id,default)
00274         except KeyError:
00275             if default is None:
00276                 default = id
00277             return default

Forcibly re-read the file

Definition at line 242 of file GettextMessageCatalog.py.

00242 
00243     def reload(self, REQUEST=None):
00244         """Forcibly re-read the file
00245         """
00246         if self.getId() in translationRegistry.keys():
00247             del translationRegistry[self.getId()]
00248         if hasattr(self, '_v_tro'):
00249             del self._v_tro
00250         name = self.getId()
00251         pts = aq_parent(self)
00252         pofile=self._getPoFile()
00253         try:
00254             self._prepareTranslations(0)
00255             log('reloading %s: %s' % (name, self.title), severity=logging.DEBUG)
00256         except:
00257             pts._delObject(name)
00258             exc=sys.exc_info()
00259             log('Message Catalog has errors', logging.WARNING, name, exc)
00260             pts.addCatalog(BrokenMessageCatalog(name, pofile, exc))
00261         self = pts._getOb(name)
00262         if hasattr(REQUEST, 'RESPONSE'):
00263             if not REQUEST.form.has_key('noredir'):
00264                 REQUEST.RESPONSE.redirect(self.absolute_url())

Here is the caller graph for this function:

Definition at line 320 of file GettextMessageCatalog.py.

00320 
00321     def Title(self):
00322         return self.title

Here is the caller graph for this function:


Member Data Documentation

Definition at line 185 of file GettextMessageCatalog.py.

Definition at line 227 of file GettextMessageCatalog.py.

Definition at line 184 of file GettextMessageCatalog.py.

Definition at line 183 of file GettextMessageCatalog.py.

Definition at line 217 of file GettextMessageCatalog.py.

Definition at line 181 of file GettextMessageCatalog.py.

Definition at line 205 of file GettextMessageCatalog.py.

Definition at line 220 of file GettextMessageCatalog.py.

string PlacelessTranslationService.GettextMessageCatalog.GettextMessageCatalog.icon = 'misc_/PlacelessTranslationService/GettextMessageCatalog.png' [static]

Definition at line 171 of file GettextMessageCatalog.py.

Definition at line 182 of file GettextMessageCatalog.py.

Definition at line 407 of file GettextMessageCatalog.py.

Definition at line 173 of file GettextMessageCatalog.py.

Definition at line 174 of file GettextMessageCatalog.py.

Initial value:
(
        {'label':'Info', 'action':''},
        {'label':'Test', 'action':'zmi_test'},
        )

Definition at line 402 of file GettextMessageCatalog.py.

Definition at line 170 of file GettextMessageCatalog.py.

Definition at line 219 of file GettextMessageCatalog.py.

Definition at line 218 of file GettextMessageCatalog.py.

Definition at line 176 of file GettextMessageCatalog.py.

Definition at line 235 of file GettextMessageCatalog.py.

Definition at line 408 of file GettextMessageCatalog.py.


The documentation for this class was generated from the following file: