
    08i:                     B    d dl Z d dlmZ ddlmZmZ  G d de      ZdZy)    N)ElementTree   )UserUserExceptionc                   v     e Zd ZdZ fdZd Zd Zed        Ze	d        Z
ed        Zd Zd	 Zd
 Zd Z xZS )TranslationFilez! Encapsulate a translation file. c           
         t        |   di | t        j                  j	                  |      rJ| j                  dj                  |             	 t        j                  |      j                         | _
        nt        j                  t              | _
        || _        || _        || _        i | _        i | _        i | _        g }| j                  D ]  }|j,                  dk7  r|j/                  |       d}g }	|D ]?  }
|
j,                  dk(  r|
j0                  }|
j,                  dk(  s/|	j/                  |
       A |so|	| j(                  |<   |	D ]e  }|j3                  d	      }||j0                  s#|j3                  d
      }||j0                  sC|j0                  | j*                  |j0                  <   g  |D ]  }| j                  j5                  |        d| _        d| _        d| _        d| _        d| _        d| _         d| _!        g | _"        y# t        $ r*}t        dj                  |dt        |                  d}~ww xY w)z" Initialise the translation file. zReading {0}...z
{}: {}: {}zinvalid translation fileNcontext namemessagesourcetranslationr    )#super__init__ospathisfileprogressformatr   parsegetroot_root	Exceptionr   str
fromstring	_EMPTY_TS_ts_file_no_obsolete_no_summary_updated_contexts	_contexts_translationstagappendtextfindremove_nr_new_nr_new_duplicates"_nr_new_using_existing_translation_nr_existing_nr_kept_obsolete_nr_discarded_obsolete_nr_discarded_untranslated_new_message_els)selfts_fileno_obsolete
no_summarykwargsecontext_els
context_elr   message_elsel
message_el	source_eltranslation_el	__class__s                 h/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/PyQt6/lupdate/translation_file.pyr   zTranslationFile.__init__   sA    	"6"77>>'"MM*11':;E(..w7??A
 %//	:DJ'%!#   ** 	MJ~~*z*DK  +66V#77DVVy(&&r*	+ '2t$"- 	MJ * 9I (	 %/__]%CN%-^5H5H 9G9L9LD&&y~~6	M%	M> & 	*JJJj)	* "#23/!"&'#*+' !#E  E#$++G :CFDE EEs   (H 	I%IIc           	         | j                  dj                  | j                  |j                               |j                  D ]  }	 | j
                  |j                     }| j                  |j                        }|j                  D ]  }| j                  ||      }|$|j                  |       | j                  ||       n| j                  ||      }|q| j                  |      }|j                  |       | j                  dj                  | j                  |j                                      | xj"                  dz  c_        n| j                  dj                  | j                  |j                                      |j%                  d      D ]C  }|j'                  d      dk(  s|j(                  r|j*                  d= 2|j-                  dd	       E || j.                  v r| xj0                  dz  c_        n| xj2                  dz  c_        |j5                  d
| j7                  |               y# t        $ r g }Y w xY w)z7 Update the translation file from a SourceFile object. zUpdating {0} from {1}...NzAdded new message '{0}'r   zUpdated message '{0}'r   typevanished
unfinishedr   )r   r   r   filenamecontextsr#   r   KeyError_get_updated_message_elsmessages_find_messager)   _add_message_el_make_message_elr&   prettyr   r*   findallgetr'   attribsetr1   r+   r-   insert_make_location_el)r2   r   r
   r:   updated_message_elsr   r<   r>   s           r@   updatezTranslationFile.updatej   s    	*11$--)	*  5	FG!"nnW\\:
 #'"?"?"M"++ +F!//E
)&&z2((5HI "&!3!3G,".J %!%!6!6w!?J'..z:MM5<<$(KK$?AB LLA%LMM3::$(KK$?AB +5*<*<]*K I)--f5C-22$2$9$9&$A . 2 26< HI "T%:%:://14/))Q.)!!!T%;%;G%DEW+F5	F  ! !s   H99IIc                    | j                   j                         D ]>  \  }}d}|D ]0  }| j                  |j                  d      j                        }|j                  d      }||j                  r| j
                  r6| j                  dj                  |             | xj                  dz  c_        |j                  dd       || j                  |      }| j                  ||       | j                  dj                  |             | xj                  dz  c_        | j                  d	j                  |             | xj                  dz  c_        3 A t        | j                  j!                               D ]}  }t#        j$                  d
      }t#        j$                  d      }||_        |j'                  |       |j)                  | j                  |          | j*                  j'                  |        | j                  dj                  | j,                               | j*                  D ]  }	t#        j.                  |	d        t1        | j,                  ddd      5 }
|
j3                  d       |
j3                  d       t#        j"                  | j*                        j3                  |
d       |
j3                  d       ddd       | j4                  s| j7                          yy# 1 sw Y   'xY w)z4 Write the translation file back to the filesystem. Nr   r   z Discarded obsolete message '{0}'r   rB   rC   zKept obsolete message '{0}'z$Discarded untranslated message '{0}'r
   r   zWriting {0}...    )spacewzutf-8
)encodingnewlinez'<?xml version="1.0" encoding="utf-8"?>
z<!DOCTYPE TS>
unicode)r[   )r#   itemsrM   r(   r'   r    r   r   r/   rQ   rH   rK   r.   r0   sortedr"   keysr   Elementr&   extendr   r   indentopenwriter!   _summary)r2   r   r:   rT   r<   r   r>   r9   name_elr;   fs              r@   re   zTranslationFile.write   s   
 "&!5!5!7 	9D+"&) 9
Z__X%>%C%CD!+!?!-.2E2E(( B I I(.!01 33q83&**6:>.6262O2O$(3*/ ,,Z9LM = D DV LN..!3.MMBII$*,- 33q8359	9@ 4116689 		*D$,,Y7J!))&1GGLg&d44T:;JJj)		* 	&--dmm<= ** 	1Br0	1 $--wE 	GG>?GG%&##DJJ/55a)5LGGDM		 MMO  	 	s   +A$K55K>c                 t    | j                  d      D ]  }| j                  |        |j                  |        y)z> Add a message element to a list of updated message elements. locationN)rN   r)   r&   )r<   rT   location_els      r@   rK   zTranslationFile._add_message_el   s<    
 &--j9 	+Kk*	+ 	"":.    c                    |D ]  }d}d}d}g }|D ]  }|j                   dk(  r|j                  }|j                   dk(  r|j                  };|j                   dk(  r|j                  }W|j                   j                  d      ss|j                  |j                   dd |j                  g        ||j                  k7  r||j
                  k7  r|| j                  |      k7  r||j                  j                  k7  r|c S  y)z7 Return the message element for a message from a list. r   r   commentextracommentextra-   N)	r%   r'   
startswithr&   r   rn   _get_message_extra_commentsembedded_commentsextras)	clsr   r:   r<   r   rn   extra_commentru   r;   s	            r@   rJ   zTranslationFile._find_message   s    & 	JFGMF ! 966X%WWFVVy( ggGVV~-$&GGMVV&&x0MM266!":rww"789 ''//) ? ? HH22999=	@ rl   c                 L    dj                  | j                  j                        S )zA Return a message's extra comments as they appear in a .ts file.  )joinrt   extra_comments)r   s    r@   rs   z+TranslationFile._get_message_extra_comments  s     xx11@@AArl   c                 h    	 | j                   |   }|S # t        $ r g }|| j                   |<   Y |S w xY w)z< Return the list of updated message elements for a context. )r"   rG   )r2   r   rT   s      r@   rH   z(TranslationFile._get_updated_message_els  sM    	?"&"8"8">
 #"	  	?"$+>D""4(""		?s    11c                 2   t        j                  dt        j                  j	                  |j
                  t        j                  j                  t        j                  j                  | j                                    t        |j                              S )z Return a 'location' element. rj   )start)rE   line)r   ra   r   r   relpathrE   dirnameabspathr   r   line_nr)r2   r   s     r@   rS   z!TranslationFile._make_location_el*  sd     "":)9)9 ggoobggoodmm.LM ) O)+ 	+rl   c                    i }|j                   j                  r|j                   j                  |d<   |j                  rd|d<   t        j                  d|      }t        j                  d      }|j
                  |_        |j                  |       |j                  r7t        j                  d      }|j                  |_        |j                  |       |j                   j                  r<t        j                  d      }| j                  |      |_        |j                  |       t        j                  dd	
      }| j                  j                  |j
                        }|rU||_        | j                  dj                  | j                  |j
                                     | xj                   dz  c_        |j                  r$|j                  t        j                  d             |j                  |       |j                   j"                  D ]5  \  }	}
t        j                  d|	z         }|
|_        |j                  |       7 | j$                  j                  |       |S )z Return a 'message' element. idyesnumerusr   r   rn   ro   r   rD   )rB   z%Reused existing translation for '{0}'r   numerusformrp   )rt   
message_idr   r   ra   r   r'   r&   rn   r{   rs   r$   rO   r   r   rM   r,   ru   r1   )r2   r   attrsr<   r=   
comment_elextracomment_elr>   r   fieldvaluer;   s               r@   rL   z TranslationFile._make_message_el2  s    $$//!33>>E$K??$E) ((E:
''1	 	)$??$,,Y7J%ooJOj)$$33)11.AO#'#C#CG#LO o.$,,]!#
 ((,,W^^<"-NMM;BB KK79: 33q83??!!+"5"5!## $ 	.)#55<< 	"LE5$$X%56BBGb!	"
 	$$Z0rl   c                 P    g  fd} j                   rZ j                  r- |dj                   j                    j                               n! |dj                   j                                 j                  r! |dj                   j                                j                  r! |dj                   j                                j
                  r! |dj                   j
                                j                  r! |dj                   j                                j                  r! |dj                   j                               s+j                  d	j                   j                  
             t        t        j                  j                               y)z- Display the summary of changes to the user. c                     s+j                  dj                  j                               j                  d| z          y )NzSummary of changes to {ts}:tsrW   )r&   r   r   )r   r2   summary_liness    r@   summaryz)TranslationFile._summary.<locals>.summaryp  s@     !$$5<<<NP   $/rl   z0{0} new messages were added (and {1} duplicates)z{0} new messages were addedz){0} messages reused existing translationsz {0} existing messages were foundz{0} obsolete messages were keptz${0} obsolete messages were discardedz({0} untranslated messages were discardedz{ts} was unchangedr   N)r*   r+   r   r,   r-   r.   r/   r0   r&   r   printr   lineseprz   )r2   r   r   s   ` @r@   rf   zTranslationFile._summaryj  sl    	0 <<&&JQQd&=&=? @ 5<<T\\JK22?FF;;= > 6==%%' ( !!5<<**, - &&:AA//1 2 **>EE335 6   !5!<!<!<!NObjjoom,-rl   )__name__
__module____qualname____doc__r   rU   re   staticmethodrK   classmethodrJ   rs   rH   rS   rL   rf   __classcell__)r?   s   @r@   r   r      sn    +L#\<F|>@ / / # #J B B
	#+6p-.rl   r   z<TS version="2.1">
</TS>
)r   	xml.etreer   userr   r   r   r   r   rl   r@   <module>r      s&   & 
 ! %~.d ~.F	rl   