Ë
    ™•Új½	  ã                   óÈ   — U d Z ddlZddlmZ ddlZddlmZ  ej                  d«      ZdZ	i Z
eeeef   ef   ed<   dee   d	ed
ee   fd„Zdee   d
eeeee   f      fd„Zy)u²  
translate_service.py â€” French â†’ English / Spanish for product names (brief sheet 3: "French input only, the
back-office translates by itself, the EN / ES fields stay editable").

A machine translation can get a commercial name wrong, so the result only FILLS the fields: the admin sees them and
can correct them before saving. If no service answers the product is still saved and shown in French: `translate`
returns None, never raises.

Provider: MyMemory (api.mymemory.translated.net), free and with no key to manage â€” plenty for a handful of product names
(about 5,000 characters a day per server address). Only the product text leaves the server: no pupil, family or order data.
é    N)ÚOptional)Úconfigzmeeconic.translate)ÚenÚesÚ_cacheÚtextsÚlangÚreturnc                 ót  — g }| D ]°  }t        j                  dt        j                  |d|› �dœ¬«      }|j	                  «        |j                  «       }|d   d   }|j                  d«      dvsd	|j                  «       v r$t        d
|j                  d«      xs |d d › �«      ‚|j                  |«       Œ² |S )Nz'https://api.mymemory.translated.net/getzfr|)ÚqÚlangpair)ÚtimeoutÚparamsÚresponseDataÚtranslatedTextÚresponseStatus)éÈ   Ú200zMYMEMORY WARNINGz
MyMemory: ÚresponseDetailsé<   )	ÚhttpxÚgetr   ÚTRANSLATE_TIMEOUT_SECSÚraise_for_statusÚjsonÚupperÚ
ValueErrorÚappend)r   r	   ÚoutÚtextÚrÚdataÚ
translateds          ú5/var/www/photos/backend/services/translate_service.pyÚ	_mymemoryr%      sÆ   € Ø
€CØò 	ˆÜ�I‰IÐ?Ì×IfÑIfØ#'°s¸4¸&°\ÑBôDˆà	×ÑÔØ�v‰v‹xˆØ˜.Ñ)Ð*:Ñ;ˆ
à�8‰8Ð$Ó%¨\Ñ9Ð=OÐS]×ScÑScÓSeÑ=eÜ˜z¨$¯(©(Ð3DÓ*EÒ*XÈÐTWÐUWÈÐ)YÐZÓ[Ð[Ø�
‰
�:Õð	ð €Jó    c                 ó  — | D �cg c]%  }dj                  |xs dj                  «       «      ‘Œ' } }t        | D �ch c]  }|sŒ|’Œ	 c}«      }|s%t        D ��ci c]  }|| D �cg c]  }d‘Œ c}“Œ c}}S 	 t        D ]n  }|D �cg c]  }||ft        vsŒ|‘Œ }}|sŒ t        |t        ||«      «      D ]6  \  }}dj                  t        |«      j                  «       «      t        ||f<   Œ8 Œp t        D ��ci c]   }|| D �cg c]  }|rt        ||f   nd‘Œ c}“Œ" c}}S c c}w c c}w c c}w c c}}w c c}w c c}w c c}}w # t        $ r3}t        j                  dt        |«      j                  «       Y d}~yd}~ww xY w)zd{"en": [...], "es": [...]} in the order of `texts` (empty texts stay empty), or None if unavailable.ú Ú z5Translation unavailable (%s): products stay in FrenchN)ÚjoinÚsplitÚsortedÚTARGETSr   Úzipr%   ÚstrÚ	ExceptionÚlogÚwarningÚtypeÚ__name__)	r   ÚtÚtodor	   Ú_ÚmissingÚsrcÚdstÚexcs	            r$   Ú	translater<   (   s_  € à27Ö8¨QˆS�X‰X�q’w˜B—o‘oÓ'Õ(Ð8€EÐ8Ü˜eÖ)˜¢q’1Ò)Ó*€DÙÜ6=×>¨d� 5Ö)˜a’rÒ)Ñ)Ó>Ð>ð	Üò 	EˆDØ"&ÖB˜Q¨1¨d¨)¼6Ò*A’qÐBˆGÐBÚÜ # G¬Y°wÀÓ-EÓ Fò E‘H�C˜Ø*-¯(©(´3°s³8·>±>Ó3CÓ*D”F˜C ˜;Ò'ñEð	Eô
 SZ×ZÈ$�¸uÖE¸!©A”v˜q $˜iÒ(°2Ñ5ÒEÑEÓZÐZùò 9ùÚ)ùâ)ùÓ>ùò Cùò FùÓZøÜò Ü�‰ÐKÌTÐRUËY×M_ÑM_Ô`Üûðúsƒ   …*DºD#ÁD#Á
D-Á"	D(Á+D-Á5E ÂD3ÂD3ÂE ÂAE Ã5
D=Ã?D8ÄD=ÄE Ä(D-Ä3E Ä8D=Ä=E Å	E?Å)E:Å:E?)Ú__doc__ÚloggingÚtypingr   r   Úcorer   Ú	getLoggerr1   r-   r   ÚdictÚtupler/   Ú__annotations__Úlistr%   r<   © r&   r$   ú<module>rG      s—   ðò
ó Ý ã å à€g×ÑÐ,Ó-€à
€Ø%'€ˆˆU�3˜�8‰_˜cÐ!Ñ"Ó 'ð�T˜#‘Yð  cð ¨d°3©ió ð�T˜#‘Yð  8¨D°°d¸3±i°Ñ,@Ñ#Aô r&   