a
    V$cY                     @   s   d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlZd dlZd	ddZdd Zejde dS )
    )divisionabsolute_importwith_statementprint_functionunicode_literals)PY2
basestringbchrbordchropenpystrrangeroundstrtobytesunicodeNFc           	      C   s   |s | t jjjjvr td|  t jjjj|  }i }|rvt|d$}|tj	|dd W d    n1 sl0    Y  |j
 D ]\}}|r||kr|||< qt|d }tj||dd W d    n1 s0    Y  d S )Nz+Language %r does not have any translations.rzutf-8)encodingwT)ensure_ascii)renpygamescript
translatorstrings	Exceptionr   updatejsonloadtranslationsitemsdump)	languagedestinationmergeforcestresultfkv r,   renpy/translation\extract.pyextract_strings_core   s    2
r.   c                  C   s|   t jjdd} | jddd | jddd | jdd	d
d | jddd
d |  }|j}|dkrdd}t||j|j|j	 dS )z&
    The extract strings command.
    zExtracts translated strings.)descriptionr#   z0The language to extract translated strings from.)helpr$   z3The json file to store the translated strings into.z--mergezdIf given, the current contents of the file are preserved, and new contents are merged into the file.
store_true)r0   actionz--forcez8If given, noting happens if the language does not exist.NoneNF)
r   	argumentsArgumentParseradd_argument
parse_argsr#   r.   r$   r%   r&   )apargsr#   r,   r,   r-   extract_strings4   s    r:   )FF)
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r.   r:   r4   register_commandr,   r,   r,   r-   <module>   s   8
