
\c           @  s[  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l m Z d  d l m Z d Z d   Z d   Z i  Z e a d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# e j$ j% d e#  d S(   i(   t   print_functionN(   t   quote_unicode(   t   elide_filenames   (?x)
\b__?\s*\(\s*[uU]?(
\"\"\"(?:\\.|\"{1,2}|[^\\"])*?\"\"\"
|'''(?:\\.|\'{1,2}|[^\\'])*?'''
|"(?:\\.|[^\\"])*"
|'(?:\\.|[^\\'])*'
)\s*\)
c         C  s   g  } x7 t  j j j j |  D] \ } } | j | | f  q Wd } x t  j j |   D] \ } } } xm t j	 t
 |  D]Y } | j d  } | d k	 r{ | j   } d | } t |  } | j | | f  q{ q{ WqY W| S(   s   
    Scans `filename`, a file containing Ren'Py script, for translatable
    strings.

    Generates a list of (line, string) tuples.
    i   t   uN(   t   renpyt   gamet   scriptt
   translatort   additional_stringst   appendt   parsert   list_logical_linest   ret   finditert	   STRING_REt   groupt   Nonet   stript   eval(   t   filenamet   rvt   linet   st	   _filenamet   linenot   textt   m(    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   scan_strings3   s    #"
c         C  sV  g  } |  t  j j k r | Sg  } d } t j |  d d  A } g  | j   j d d  j d  D] } | j   ^ qb } Wd  QXx t	 |  D] \ } } | s | d } n  t
 j d |  } | r | j d  }	 | r |	 j   }	 n  | j |	  q | r d	 d
 j |  }
 |
 j d  r2|
 j d  }
 n  g  } | j | |
 f  q q W| S(   Ni    t   rs   utf-8u   ﻿t    s   
i   s
   \s*## (.*)s   ## t    t   #s   # (   R   t   configt   translate_commentst   codecst   opent   readt   replacet   splitt   rstript	   enumerateR   t   matchR   R   R	   t   joint   endswith(   R   R   t   commentt   startt   ft   it   linest   lR   t   cR   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   scan_commentsP   s.    @c         C  s   |  t  k r t  |  St j j |   s{ t j j |   } y t j |  Wn n Xt j |  d d d } | j d  n t j |  d d d } t	 r | j d d j
 t j d    n  | j d  | t  |  <| S(	   Nt   at   encodings   utf-8u   ﻿u   # TOs   DO: Translation updated at {}
s   %Y-%m-%d %H:%Mu   
(   t   tl_file_cachet   ost   patht   existst   dirnamet   makedirst   ioR#   t   writet   todot   formatt   timet   strftime(   t   fnt   dnR.   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   open_tl_file   s     &
c          C  s/   x t  j   D] }  |  j   q Wt  j   d  S(   N(   R6   t   valuest   closet   clear(   R/   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   close_tl_files   s    c         C  s   t  j j t j j  } t  j j t j j  } |  j |  r] t  j j |  |  } t	 } nE |  j |  r t  j j |  |  } t
 } n t  j j |   } t
 } | | f S(   s   
    Shortens a file name. Returns the shortened filename, and a flag that says
    if the filename is in the common directory.
    (   R7   R8   t   normpathR   R    t	   commondirt   gamedirt
   startswitht   relpatht   Truet   Falset   basename(   R   RJ   RK   RB   t   common(    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   shorten_filename   s    		c         C  s  t  |   \ } } | r d  St j j t j j t j j | |  } | d d k r` | d  } n  | d k ru d  } n  t j	 j
 j } xL| j |  D]=\ } } | j | f | j k r q n  t | d  r | j | f | j k r q q n  t |  }	 | d  k rd } n  |	 j d j | j | j   |	 j d j | | j j d d	    |	 j d
  x, | j D]! }
 |	 j d |
 j   d  qkWx/ | j D]$ }
 |	 j d |
 j |  d  qW|	 j d
  q Wd  S(   NiR   R   t	   alternateR   u   # {}:{}
u   translate {} {}:
t   .t   _u   
u       # s   
u       (   RR   R7   R8   R*   R   R    RK   t   tl_directoryR   R   R   R   t   file_translatest
   identifiert   language_translatest   hasattrRS   RD   R=   R?   R   t
   linenumberR%   t   blockt   get_code(   R   t   languaget   filterRB   RQ   t   tl_filenameR   t   labelt   tR.   t   n(    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   write_translates   s4    '			("c         C  sJ   t  j j r |  j S|  j r  d S|  j } | d d k rF | d  } n  | S(   Ns
   common.rpyiR   (   R   R    t   translate_launchert   launcher_fileRQ   t   elided(   R   R   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   translation_filename   s    		c         C  s  |  d k r% t  j j j j d	 } n t  j j j j |  } t  j j j | | |  } t	 j
 t  } xv | D]n } t |  }	 |	 d	 k r ql n  | j | j k r ql n  |  d k r |	 d k r d }	 n  | |	 j |  ql Wx | j   D] \ }	 }
 t j j t  j j t  j j |  |	  }	 t |	  } | j d j |    | j d  x |
 D] } | | j  } | j d j t | j  | j   | j d j t | j    | j d j t |    | j d  qTWq Wd	 S(
   s%   
    Writes strings to the file.
    R   s
   common.rpys   common.rpymu   translate {} strings:
u   
u       # {}:{}
u       old "{}"
u       new "{}"
N(   R   R   R   R   t   stringsR   t   translationt   scanstringst   scant   collectionst   defaultdictt   listRh   R   t   translationsR	   t   itemsR7   R8   R*   R    RK   RV   RD   R=   R?   R   R   R   R   (   R^   R_   t   min_priorityt   max_priorityt   common_onlyt   stlRi   t   stringfilesR   t   tlfnt   slR.   R   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   write_strings   s2    	'%c         C  s   |  S(   N(    (   R   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   null_filter-  s    c         C  s   d S(   NR   (    (   R   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   empty_filter1  s    c           s.   d       f d   }  |  d d |  S(   s  
    :doc: text_utility

    Transforms `s`, while leaving text tags and interpolation the same.

    `function`
        A function that is called with strings corresponding to runs of
        text, and should return a second string that replaces that run
        of text.

    ::

        init python:
            def upper(s):
                return s.upper()

        $ upper = renpy.transform_text("{b}Not Upper{/b}")

    c   	      S  s  d } t  } d } d } x |  D] } | | k r | r@ d } n5 | | |  7} d } | d k rk t } n  | d 7} | | 7} q | | k r t  } | d 8} | d k  r | d 7} n  | | 7} q | r | | 7} q | | 7} q W| r | | |  7} n  | S(   Ni    R   i   (   RO   RN   (	   R   R-   t   endt   processt   specialst   firstR   t   bufR/   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   remove_specialJ  s4    		

c           s    |  d d    S(   Nt   {t   }(    (   R   (   t   functionR   (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   remove_bracesv  s    t   [t   ](    (   R   R   R   (    (   R   R   su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   generic_filter5  s    	,c           s   i    x] t  d d  D]L \ } } |   | <|   | <| j   } | j   } |   | <|   | <q Wd j   f d   |  D  S(   Nt   ABCDEFGHIJKLMt   NMOPQRSTUVWYZR   c         3  s!   |  ] }   j  | |  Vq d  S(   N(   t   get(   t   .0R/   (   t   ROT13(    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pys	   <genexpr>  s    (   t   zipt   lowerR*   (   R   R/   t   j(    (   R   su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   rot13_transform|  s    


c         C  s   t  |  t  S(   N(   R   R   (   R   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   rot13_filter  s    c           sR   d d d d d d d d d	 d
 d d d d g     f d   } t  j d | |   S(   Nt   sht   glt   cht   pht   trt   brt   frt   blt   grt   stRx   t   clt   plt   flc           s   |  j  d  } | d d
 k r, | d } n? | d    k rU | d | d  d } n | d	 | d d } | d j   r | j   } n  | S(   Ni    R4   t   eR/   t   oR   t   ayi   i   (   R4   R   R/   R   R   (   R   t   isuppert
   capitalize(   R   R/   R   (   t   lst(    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyR%     s    s   \w+(   R   t   sub(   R   R%   (    (   R   su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   piglatin_transform  s    0c         C  s   t  |  t  S(   N(   R   R   (   R   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   piglatin_filter  s    c          C  s   t  t j j  }  x t j j   D] \ } } | d k r@ q" n  | j d  rU q" n  t j	 j
 | |  } | j d  p | j d  s q" n  t j	 j |  } t j	 j |  s q" n  |  j |  q" W|  S(   sT   
    Returns a list of files that exist and should be scanned for translations.
    s   tl/s   .rpys   .rpymN(   Ro   R   R    t   translate_filest   loadert   listdirfilesR   RL   R7   R8   R*   R+   RI   R9   R	   (   t	   filenamesR:   R   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   translate_list_files  s    c         C  s  t  j j j } d } xT t   D]I } x@ | j | D]1 \ } } | j |  f | j k r3 | d 7} q3 q3 Wq Wd }	 t  j j j j |  }
 t  j	 j
 j | | |  } xN | D]F } t |  } | d k r q n  | j |
 j k r q n  |	 d 7}	 q Wt d j |  | |	   d S(   s@   
    Prints a count of missing translations for `language`.
    i    i   sE   {}: {} missing dialogue translations, {} missing string translations.N(   R   R   R   R   R   RW   RX   RY   Ri   Rj   Rk   Rl   Rh   R   R   Rp   t   printR?   (   R^   Rr   Rs   Rt   R   t   missing_translatesR   RU   Rb   t   missing_stringsRu   Ri   R   Rw   (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   count_missing  s(    	c       
   C  s  t  j j d d  }  |  j d d d |  j d d d d d	 d
 d |  j d d d d d d
 d |  j d d d d d d
 d |  j d d d d d d
 d |  j d d d d d d d d t |  j d d d d d d d d t |  j d d d d d d t d
 d |  j d  d d! d d" d t d
 d |  j d# d d$ d d% d t d
 d& |  j   } | j a t  j	 j
 r| j pd' } n | j pd( } | j rt | j | j | | j  t S| j rt } n* | j rt } n | j rt } n t } | j s7x' t   D] } t | | j |  qWn  t | j | | j | | j  t   t  j	 j
 r| j rt j j t  j	 j  d) d* d+  } t j j t  j	 j! d, | j d-  } t j j" |  rt j j" |  rt# j$ | |  qn  t S(.   sh   
    The translate command. When called from the command line, this generates
    the translations.
    t   descriptions"   Generates or updates translations.R^   t   helps*   The language to generate translations for.s   --rot13s*   Apply rot13 while generating translations.t   destt   rot13t   actiont
   store_trues
   --piglatins.   Apply pig latin while generating translations.t   piglatins   --emptys4   Produce empty strings while generating translations.t   emptys   --countsC   Instead of generating files, print a count of missing translations.t   counts   --min-prioritys/   Translate strings with more than this priority.Rr   t   defaulti    t   types   --max-priorityRs   s   --strings-onlys&   Only translate strings (not dialogue).t   strings_onlys   --common-onlys+   Only translate string from the common code.Rt   s	   --no-todos   Do not include the TODO flag.R>   t   store_falsei  i+  t   guiR   s
   script.rpyt   tls   script.rpym(%   R   t	   argumentst   ArgumentParsert   add_argumentt   intRO   RN   t
   parse_argsR>   R    Re   Rs   R   R   R^   Rr   Rt   R   R   R   R   R   R{   Rz   R   R   Rd   Ry   RH   R7   R8   R*   t
   renpy_baseRK   R9   t   shutilt   copy(   t   apt   argsRs   R_   R   t   srct   dst(    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   translate_command  sJ    %%%%%									!$%t	   translate(&   t
   __future__R    t   renpy.translationR   R   R7   R@   R<   R"   Rm   R   R   t   renpy.parserR   R   R   R3   R6   RN   R>   RD   RH   RR   Rd   Rh   Ry   Rz   R{   R   R   R   R   R   R   R   R   R   t   register_command(    (    (    su   C:\Users\romet\Desktop\TwistedScarlett Patreon Pack #13\FriendshipwithBenefits-0.1-pc\renpy\translation\generation.pyt   <module>   s@   		)				-		4			G						'	;