
    3fi=                     J    d dl mZmZmZ d dlmZmZ d dlmZ  G d de      Z	y)    )AnyOptionalSequence)BaseDocumentTransformerDocument)get_client_infoc                       e Zd ZdZddddddededee   dee   d	ee   d
dfdZdddddee   dee   dee   dede	d
ee   fdZ
y)GoogleTranslateTransformera?  Translate text documents using Google Cloud Translation.

    Inherits from
    [`BaseDocumentTransformer`][langchain_core.documents.BaseDocumentTransformer].

    Transforms documents by translating their content using Google Cloud Translation API
    with support for custom models and glossaries.

    !!! note "Installation"

        Requires additional dependencies:

        ```bash
        pip install langchain-google-community[translate]
        ```

    See [Translation API documentation](https://cloud.google.com/translate/docs) for
    detailed information.
    globalN)locationmodel_idglossary_idapi_endpoint
project_idr   r   r   r   returnc                   	 ddl m} ddlm} || _        || _        || _        || _        |j                  t        d      |r	 ||      nd      | _        | j                  j                  ||      | _        |r| j                   d	| nd| _        |r#| j                  j                  |||      | _        yd| _        y# t        $ r}t	        d      |d}~ww xY w)
a  Initialize Google Cloud Translation transformer.

        Args:
            project_id: Google Cloud Project ID.
            location: Translation service location.
            model_id: Custom translation model ID.
            glossary_id: Glossary ID for specialized translations.
            api_endpoint: Regional API endpoint.

        Raises:
            ImportError: If `google-cloud-translate` package is not installed.
        r   )ClientOptions	translateCould not import google-cloud-translate python package. Please, install translate dependency group: `pip install langchain-google-community[translate]`Nr   )r   )client_infoclient_optionsz/models/)google.api_core.client_optionsr   google.cloudr   ImportErrorr   r   r   r   TranslationServiceClientr   _clientcommon_location_path_parent_path_model_pathglossary_path_glossary_path)	selfr   r   r   r   r   r   r   excs	            b/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_google_community/translate.py__init__z#GoogleTranslateTransformer.__init__   s    *	D. %  & 99'4<H<8d : 
 !LL==j(S 9At  !(4d 	
  LL&&z8[I 	  	/  	F 		s   B> >	CCCz
text/plain)source_language_codetarget_language_code	mime_type	documentsr'   r(   r)   kwargsc                T   |d}t        |      	 ddlm} | j                  j                  |j                  |D 	cg c]  }	|	j                   c}	| j                  | j                  |j                  | j                        |||            }
|
j                  xs |
j                  }t        ||      D 	cg c]A  \  }	}t        |j                   i |	j"                  |j$                  |j&                  d	
      C c}}	S # t        $ r}t        d      |d}~ww xY wc c}	w c c}}	w )a8  Translate text documents using Google Translate.

        Args:
            documents: Sequence of [`Document`][langchain_core.documents.Document]
                objects to translate.
            source_language_code: ISO 639 language code of the input document.
                If not provided, language will be auto-detected.
            target_language_code: ISO 639 language code of the output document.
                Required for translation. For supported languages, see
                [Language Support](https://cloud.google.com/translate/docs/languages).
            mime_type: Media type of input text. Options: `'text/plain'`,
                `'text/html'`. Default: `'text/plain'`.
            **kwargs: Additional keyword arguments.

        Returns:
            Translated documents with updated metadata including `model`,
            `detected_language_code`, and original metadata fields.

        Raises:
            ValueError: If `target_language_code` is not provided.
            ImportError: If `google-cloud-translate` package is not installed.
        NzZtarget_language_code is required for translation. Please provide an ISO 639 language code.r   r   r   )glossary)contentsparentmodelglossary_configr'   r(   r)   )request)r0   detected_language_code)page_contentmetadata)
ValueErrorr   r   r   r   translate_textTranslateTextRequestr4   r   r    TranslateTextGlossaryConfigr"   glossary_translationstranslationszipr   translated_textr5   r0   r3   )r#   r*   r'   r(   r)   r+   msgr   r$   docresponser;   translations                r%   transform_documentsz.GoogleTranslateTransformer.transform_documentsR   sP   >  ';  S/!	. <<..226?@s#**@((&& ) E E!00 !F ! &:%9# 3 
 / 
  55N9N9N %(	<$@

 ![ (88ll(...9.P.P

 
	
1  	F 		 A

s#   D D8AD$	DDD)__name__
__module____qualname____doc__strr   r&   r   r   r   rB        r%   r
   r
      s    0 !"&%)&*3
3
 	3

 3-3
 c]3
 sm3
 
3
r /3.2%J
H%J
 'sm	J

 'smJ
 J
 J
 
(	J
rI   r
   N)
typingr   r   r   langchain_core.documentsr   r   !langchain_google_community._utilsr   r
   rH   rI   r%   <module>rM      s     * * F =T
!8 T
rI   