a
    V$cd                     @   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 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unicodeNc                  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j	vrt
d| t|jddd}t| }W d   n1 s0    Y  |jri }| D ]\}}|||< q|}t jjjj	| }dt j_|j D ]\}}| p||k}	|	s2|js2q||vr@q||jvrPq|| }
t j|
}d|}|j| \}}t j||| t j||d  qdS )z$
    The merge strings command.
    z/Merges translated strings with the game script.)descriptionlanguagez,The language to merge translated strings to.)helpsourcez.The json file to take translated strings from.z	--reverse
store_truez(Reverses the languages in the json file.)actionr   z	--replacez"Replaces non-trivial translations.NoneNz+Language %r does not have any translations.rzutf-8)encodingFznew "{}"   )renpy	argumentsArgumentParseradd_argument
parse_argsr   gamescript
translatorstrings	Exceptionr   r   jsonloadsreadreverseitemsconfigclear_linestranslationsreplacetranslation_loctranslationquote_unicodeformat
scripteditinsert_line_beforeremove_line)apargsr   fdatanew_datakvsttrivialnewquotedcodefilename
linenumber rE   renpy/translation\merge.pymerge_strings   sF    ,


rG   )
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   r   r'   rG   r   register_commandrE   rE   rE   rF   <module>   s
   8<