Back to index

plone3  3.1.7
Functions | Variables
PlacelessTranslationService.load Namespace Reference

Functions

def _checkLanguage
def _updateMoFile
def _compile_locales_dir

Variables

 PTS_LANGUAGES = None
tuple langs = os.getenv('PTS_LANGUAGES')

Function Documentation

Definition at line 20 of file load.py.

00020 
00021 def _checkLanguage(lang):
00022     if PTS_LANGUAGES is None:
00023         return True
00024     else:
00025         return bool(lang in PTS_LANGUAGES)
00026 

Here is the caller graph for this function:

Compiles all po files in a locales directory (Zope3 format) to mo files.
Format:
    Products/MyProduct/locales/${lang}/LC_MESSAGES/${domain}.po
Where ${lang} and ${domain} are the language and the domain of the po
file (e.g. locales/de/LC_MESSAGES/plone.po)

Definition at line 74 of file load.py.

00074 
00075 def _compile_locales_dir(basepath):
00076     """
00077     Compiles all po files in a locales directory (Zope3 format) to mo files.
00078     Format:
00079         Products/MyProduct/locales/${lang}/LC_MESSAGES/${domain}.po
00080     Where ${lang} and ${domain} are the language and the domain of the po
00081     file (e.g. locales/de/LC_MESSAGES/plone.po)
00082     """
00083     basepath = str(os.path.normpath(basepath))
00084     if not isdir(basepath):
00085         return
00086 
00087     for lang in os.listdir(basepath):
00088         if not _checkLanguage(lang):
00089             continue
00090         langpath = join(basepath, lang)
00091         if not isdir(langpath):
00092             # it's not a directory
00093             continue
00094         msgpath = join(langpath, 'LC_MESSAGES')
00095         if not isdir(msgpath):
00096             # it doesn't contain a LC_MESSAGES directory
00097             continue
00098         names = fnmatch.filter(os.listdir(msgpath), '*.po')
00099         for name in names:
00100             domain = name[:-3]
00101             mofile = join(msgpath, name[:-2] + 'mo')
00102             result = _updateMoFile(name, msgpath, lang, domain, mofile)

Here is the call graph for this function:

Here is the caller graph for this function:

def PlacelessTranslationService.load._updateMoFile (   name,
  msgpath,
  lang,
  domain,
  mofile 
) [private]
Creates or updates a mo file in the locales folder. Returns True if a
new file was created.

Definition at line 27 of file load.py.

00027 
00028 def _updateMoFile(name, msgpath, lang, domain, mofile):
00029     """
00030     Creates or updates a mo file in the locales folder. Returns True if a
00031     new file was created.
00032     """
00033     pofile = join(msgpath, name)
00034     create = False
00035     update = False
00036 
00037     try:
00038         po_mtime = os.stat(pofile)[ST_MTIME]
00039     except (IOError, OSError):
00040         po_mtime = 0
00041 
00042     if os.path.exists(mofile):
00043         # Update mo file?
00044         try:
00045             mo_mtime = os.stat(mofile)[ST_MTIME]
00046         except (IOError, OSError):
00047             mo_mtime = 0
00048 
00049         if po_mtime > mo_mtime:
00050             # Update mo file
00051             update = True
00052         else:
00053             # Mo file is current
00054             return
00055     else:
00056         # Create mo file
00057         create = True
00058 
00059     if create or update:
00060         try:
00061             mo = Msgfmt(pofile, domain).getAsFile()
00062             fd = open(mofile, 'wb')
00063             fd.write(mo.read())
00064             fd.close()
00065 
00066         except (IOError, OSError, PoSyntaxError):
00067             log('Error while compiling %s' % pofile, logging.WARNING)
00068             return
00069 
00070         if create:
00071             return True
00072 
00073     return None

Here is the caller graph for this function:


Variable Documentation

Definition at line 15 of file load.py.

Definition at line 13 of file load.py.