Ñò
RüLc           @   sé   d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z d  d k l Z d e	 f d „  ƒ  YZ
 e d j oZ d Z e
 d e ƒ Z d	 e i ƒ  GHd
 e i ƒ  GHe i GHe i GHe i GHe i ƒ  GHn d S(   iÿÿÿÿN(   t   gettext(   t   ElementTreet
   LocaleInfoc           B   sz   e  Z d  Z d d g Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 e
 e
 d	 „ Z d
 „  Z d „  Z d „  Z RS(   s<    class with handy functions to parse the locale information s   /etc/default/locales   /etc/environmentc         C   su  | |  _  t i i | d | ƒ } h  |  _ h  |  _ h  |  _ t d d ƒ } | i d ƒ } xj | D]b } | i	 d } d | i	 j o | i	 d } n | i	 d } | |  i j o | |  i | <qa qa Wt
 d ƒ |  i d	 <t
 d
 ƒ |  i d <t d d ƒ } | i d ƒ } xI | D]A } | i	 d } | i	 d } | |  i j o | |  i | <qqWt d d ƒ } | i d ƒ } xw | D]o } d | i	 j o | i	 d }	 n | i	 d }	 d | i	 j o | i	 d } n | i	 d } |	 |  i | <q|Wx t | ƒ D]q }
 |
 i ƒ  } | i d ƒ p | d j o qün | i d ƒ } | d i d ƒ } d | d |  i | d <qüWd  S(   Nt   datat   files$   /usr/share/xml/iso-codes/iso_639.xmlt   iso_639_entryt   namet   iso_639_1_codet   iso_639_2T_codes   Chinese (simplified)s   zh-hanss   Chinese (traditional)s   zh-hants&   /usr/share/xml/iso-codes/iso_639_3.xmlt   iso_639_3_entryt   ids%   /usr/share/xml/iso-codes/iso_3166.xmlt   iso_3166_entryt   common_namet   alpha_2_codet   alpha_3_codet   #t    t   ;i   t   :s   %si    (   t   _datadirt   ost   patht   joint   _langt   _countryt   _languagelistR   t   getiteratort   attribt   _t   opent   stript
   startswitht   split(   t   selft   languagelist_filet   datadirt   LANGUAGELISTt   ett   itt   elmt   langt   codet   descrt   linet   tmpt   wt	   localeenv(    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt   __init__   sX    				    c         C   s    | |  i  j o |  i  | Sd S(   s$    map language code to language name R   (   R   (   R!   R)   (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyR(   X   s    c         C   s    | |  i  j o |  i  | Sd S(   s!    map country code to country nameR   (   R   (   R!   R)   (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt   country^   s    c         C   sÖ   g  } t  i d d g d t  i ƒ} x« t i | i ƒ  d d ƒ D] } | i ƒ  } | i d ƒ p' | d j p | d j p | d	 j o qA n t i	 |  i
 | ƒ } | d
 } | | j o | i | ƒ qA qA W| S(   sR    return a list of locales available on the system
            (running locale -a) t   locales   -at   stdouti    s   
R   R   t   Ct   POSIXt   LOCALE(   t
   subprocesst   Popent   PIPEt   stringR    t   communicateR   R   t   macrost   LangpackMacrosR   t   append(   R!   t   localest   pR+   R,   t   macrR1   (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt   generated_localesd   s     7
c         C   sg   | |  i  j oO t i d |  i  | ƒ } | |  i  | j o t i d |  i  | ƒ } n | S| Sd S(   s   return translated languaget   iso_639t	   iso_639_3N(   R   R    t   dgettext(   R!   R(   t	   lang_name(    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt   translate_languageu   s    c         C   s6   | |  i  j o t i d |  i  | ƒ } | S| Sd S(   sš   
        return translated language and country of the given
        locale into the given locale, e.g. 
        (Deutsch, Deutschland) for de_DE
        t   iso_3166N(   R   R    RD   (   R!   R0   t   country_name(    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt   translate_country   s    c   
         sŽ  d } t  i |  i | ƒ ‰  | t j o< d } d t i j o t i d } n ˆ  d t i d <n |  i ˆ  d ƒ } | } t ˆ  d ƒ d j o” |  i	 ˆ  d ƒ } t
 ‡  f d †  |  i ƒ  ƒ } | t j o t | ƒ d j p | t j o2 |  i ˆ  d ƒ }	 |	 o d	 | | f } q$q(n t ˆ  d
 ƒ d j o d | ˆ  d
 f } n | t j o& | o | t i d <qŠt i d =n | S(   s4    get a locale code and output a human readable name R   t   LANGUAGER5   t   LCODEt   CCODEi    c            s   |  i  ˆ  d  ƒ S(   RK   (   R   (   t   k(   R@   (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt   <lambda>©   s    i   s   %s (%s)t   VARIANTs   %s - %sN(   R;   R<   R   t   Truet   NoneR   t   environRF   t   lenRI   t   filterRA   t   FalseR0   (
   R!   R1   t   nativet   allCountriest	   returnValt   current_languageRE   RH   t   lt	   mycountry(    (   R@   s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt	   translateš   s.    -c         C   se   t  i |  i | ƒ } | d } | d } | |  i j o |  i | S| | j o | Sd | | f S(   s—    input is a language code, output a string that can be put in
            the LANGUAGE enviroment variable.
            E.g: en_DK -> en_DK:en
        RK   R5   s   %s:%s(   R;   R<   R   R   (   R!   R)   R@   t   langcodeR1   (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt   makeEnvStringÉ   s    

c   	      C   s  d } d } g  } t  i i d ƒ } t  i i | ƒ o… x‚ t | ƒ D]p } t i d | ƒ } | o | i d ƒ i d ƒ } n t i d | ƒ } | o | i d ƒ i d ƒ } qD qD Wn t	 | ƒ d j op t  i i d ƒ } t  i i | ƒ oG xD t | ƒ D]2 } t i d	 | ƒ } | o | i d ƒ } qqWq?n t	 | ƒ d j o! d
 t  i
 j o t  i
 d
 } n t	 | ƒ d j o_ t	 | ƒ d j oH d t  i
 j o% t  i
 d | j o t  i
 d } qá|  i | ƒ } qån | i | ƒ | i | ƒ | S(   sê  
        Reads '~/.profile' if present and '~/.dmrc' otherwise or if '~/.profile' doesn't set
        any values.
        Scans for LANG and LANGUAGE variable settings and returns a list [LANG, LANGUAGE].
        In case of '~/.dmrc', we only have the locale as a value, not the full LANGUAGE
        variable compatible string. Therefor we need to generate one from the provided locale.
        Likewise, if LANGUAGE is not defined, generate a string from the provided LANG value.
        R   s
   ~/.profiles   export LANG=(.*)$i   t   "s   export LANGUAGE=(.*)$i    s   ~/.dmrcs   Language=(.*)$t   LANGRJ   (   R   R   t
   expandusert   existsR   t   ret   matcht   groupR   RS   RR   R^   R=   (	   R!   R(   t   languaget   resultt   fnameR+   t
   match_langt   match_languageRd   (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt   getUserDefaultLanguageÙ   s>    	 $ #$c         C   s™  d } d } g  } x#|  i  D]} t i i | ƒ oÿ t i | t i ƒ oé xÊ t | ƒ D]¼ } | i d ƒ o | i d d ƒ } n t	 i
 d | ƒ } | o | i d ƒ i d ƒ } n | i d ƒ o | i d d ƒ } n t	 i
 d | ƒ } | o | i d ƒ i d ƒ } qX qX Wt | ƒ d j o Pq4q q Wt | ƒ d j o
 d	 } n t | ƒ d j o |  i | ƒ } n | i | ƒ | i | ƒ | S(
   s³   
        Reads '/etc/default/locale' if present, and if not '/etc/environment'.
        Scans for LANG and LANGUAGE variable settings and returns a list [LANG, LANGUAGE].
        R   R`   R_   s
   LANG=(.*)$i   RJ   s   LANGUAGE=(.*)$i    s   en_US.UTF-8(   t   environmentsR   R   Rb   t   accesst   R_OKR   R   t   replaceRc   Rd   Re   R   RS   R^   R=   (   R!   R(   Rf   Rg   Rh   R+   Ri   Rj   (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt   getSystemDefaultLanguage  s8    
   
(   t   __name__t
   __module__t   __doc__Rl   R/   R(   R0   RA   RF   RI   RU   R\   R^   Rk   Rp   (    (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyR      s   	E				
	/		(t   __main__s   /usr/share/language-selector/t   languagelists)   default system locale and languages: '%s's'   default user locale and languages: '%s'(   R9   Rc   R6   R    R   R;   R   t   xml.etree.ElementTreeR   t   objectR   Rq   R#   t   liRp   Rk   R   R   R   RA   (    (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/LocaleInfo.pyt   <module>   s$   ÿ 