mò
MìGc           @   sá   d  k  Z  d  k Z d  k Z d k l Z d k l Z d k l Z d k l	 Z	 d k
 l Z d k
 l Z d  Z e e i d ƒ ƒ o= e i d ƒ Z e i ƒ  i d d	 ƒ i ƒ  Z e e ƒ Z n d
 „  Z d „  Z d „  Z d  S(   N(   s   isdir(   s   join(   s   ST_MTIME(   s   log(   s   Msgfmt(   s   PoSyntaxErrort   PTS_LANGUAGESt   ,t    c         C   s)   t  d  j o t Sn t |  t  j ƒ Sd  S(   N(   R    t   Nonet   Truet   boolt   lang(   R   (    (    tO   /home2/kennisonb/webapps/zope/Zope/Products/PlacelessTranslationService/load.pyt   _checkLanguage   s    c         C   sf  t  | |  ƒ } t } t } y t i | ƒ t	 } Wn t t f j
 o d } n Xt i i | ƒ oX y t i | ƒ t	 } Wn t t f j
 o d } n X| | j o
 t } qÅ d Sn t } | p | o yE t | | ƒ i ƒ  }
 t | d ƒ }	 |	 i |
 i ƒ  ƒ |	 i ƒ  Wn4 t t t f j
 o t d | t i ƒ d Sn X| o t Sqbn d S(   si   
    Creates or updates a mo file in the locales folder. Returns True if a
    new file was created.
    i    Nt   wbs   Error while compiling %s(    t   joint   msgpatht   namet   pofilet   Falset   createt   updatet   ost   statt   ST_MTIMEt   po_mtimet   IOErrort   OSErrort   patht   existst   mofilet   mo_mtimeR   t   Msgfmtt   domaint	   getAsFilet   mot   opent   fdt   writet   readt   closet   PoSyntaxErrort   logt   loggingt   WARNINGR   (   R   R   R   R   R   R   R   R   R   R    R   R   (    (    R   t   _updateMoFile   s:     
	c   	      C   s
  t  t i i |  ƒ ƒ }  t |  ƒ p d Sn xÖ t i |  ƒ D]Å } t | ƒ p q= n t	 |  | ƒ } t | ƒ p q= n t	 | d ƒ } t | ƒ p q= n t i t i | ƒ d ƒ } xG | D]? } | d  } t	 | | d  d ƒ } t | | | | | ƒ } q¿ Wq= Wd S(   s  
    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)
    Nt   LC_MESSAGESs   *.poiýÿÿÿiþÿÿÿR   (   t   strR   R   t   normpatht   basepatht   isdirt   listdirR   R   R
   t   langpathR   t   fnmatcht   filtert   namesR   R   R   R(   t   result(	   R,   R   R   R   R3   R/   R   R   R2   (    (    R   t   _compile_locales_dirJ   s(       
(   R0   R&   R   t   os.pathR-   R
   R   R   t*   Products.PlacelessTranslationService.utilsR%   t+   Products.PlacelessTranslationService.msgfmtR   R$   R   R    R   t   getenvt   langst   stript   replacet   splitt   tupleR   R(   R4   (   R-   R   R&   R%   R   R(   R   R$   R0   R
   R    R   R9   R4   (    (    R   t   ?   s    					/