
    Pi                    b    d dl mZ d dlZd dlZd dlmZ  G d d          Z G d d          ZdS )    )annotationsN)Anyc                  L    e Zd ZdZddZddZddZdd	Zd
 Zd Z	d Z
ddZdS )I18nDataz
    A class that wraps a translation key with metadata.

    This object will be serialized and sent to the frontend, where the actual
    translation will happen using the frontend's i18n system.
    keystrc                "    || _         d| _        dS )z
        Initialize a I18nData object.

        Args:
            key: The translation key to be translated in the frontend.
        translation_metadataN)r   _typeselfr   s     _/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/gradio/i18n.py__init__zI18nData.__init__   s     +


    returndict[str, Any]c                     | j         | j        dS )z
        Convert the I18nData object to a dictionary for serialization.
        This allows the frontend to recognize it as a translatable object.
        )__type__r   )r   r   r   s    r   to_dictzI18nData.to_dict   s    
 !Jtx888r   c                ^    ddl }d|                    |                                            S )z
        String representation of the I18nData object.
        Used when the object is converted to a string.
        This returns a special format that can be recognized by the frontend
        as needing translation.
        r   N__i18n__)jsondumpsr   )r   r   s     r   __str__zI18nData.__str__!   s/     	6$**T\\^^44666r   c                *    |                                  S )zF
        Representation of the I18nData object for debugging.
        )r   r   s    r   __repr__zI18nData.__repr__,   s     ||~~r   c                @    t          |           t          |          z   S )z=
        Handle string concatenation (self + other).
        r   r   others     r   __add__zI18nData.__add__2   s     4yy3u::%%r   c                @    t          |          t          |           z   S )z=
        Handle string concatenation (other + self).
        r   r    s     r   __radd__zI18nData.__radd__8   s     5zzCII%%r   c                     |                     d          r3|                    d          rt           j        j         d|            fd}|S )z
        Handle attribute access for I18nData.
        This makes it possible to use I18nData objects in contexts
        that expect strings with methods.
        __z has no attribute c                     S N )_args_kwargsr   s     r   methodz$I18nData.__getattr__.<locals>.methodG   s    Kr   )
startswithendswithAttributeError	__class____name__)r   namer,   s   `  r   __getattr__zI18nData.__getattr__>   so     ??4   	WT]]4%8%8 	W DN$;!U!Ut!U!UVVV	 	 	 	 	 r   c                *    |                                  S )z
        Convert the I18nData object to a JSON-serializable dictionary.
        This is used by the default Python JSON serializer.
        )r   r   s    r   tojsonzI18nData.tojsonL   s    
 ||~~r   N)r   r   )r   r   )r   r   )r1   
__module____qualname____doc__r   r   r   r   r"   r$   r3   r5   r)   r   r   r   r      s         , , , ,9 9 9 9	7 	7 	7 	7   & & && & &       r   r   c                  b    e Zd ZdZ ej        d          ZddZdd
ZddZ	e
dd            ZdS )I18na  
    Handles internationalization (i18n) for Gradio applications.

    Stores translation dictionaries and provides a method to retrieve translation keys.
    The translation lookup happens on the frontend based on the browser's locale
    and the provided translation dictionaries.
    z ^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$translationsdict[str, str]c                    i | _         |                                D ]B\  }}|                     |          st          j        d| dt
                     || j         |<   CdS )a  
        Initializes the I18n class.

        Args:
            **translations: Each keyword argument should be a locale code (e.g., "en", "fr") with a
                          dictionary value, which maps translation keys to translated strings.
                          Example: gr.I18n(en={"greeting": "Hello"}, es={"greeting": "Hola"})

                          These translations can be passed to the frontend for use there.
        zInvalid locale code: 'z'. Locale codes should follow BCP 47 format (e.g., 'en', 'en-US'). This locale will still be included, but may not work correctly.N)r;   items_is_valid_localewarningswarnUserWarning)r   r;   localetranslation_dicts       r   r   zI18n.__init__`   s     (4(:(:(<(< 	9 	9$F$((00 WV W W W  
 )9Df%%	9 	9r   rC   r   r   boolc                P    t          | j                            |                    S r(   )rE   _LOCALE_PATTERNmatch)r   rC   s     r   r?   zI18n._is_valid_localev   s!    D(..v66777r   r   r   c                     t          |          S )a  
        Returns a I18nData object containing the translation key.

        This metadata object will be serialized and sent to the frontend,
        where it will be translated by the frontend's i18n system.

        Args:
            key: The key to identify the translation string (e.g., "submit_button").

        Returns:
            A I18nData object containing the translation key.
        )r   r   s     r   __call__zI18n.__call__y   s     }}r   dict[str, dict[str, str]]c                    | j         S )z
        Returns the dictionary of translations provided during initialization.
        These can be passed to the frontend for use in its translation system.
        )r;   r   s    r   translations_dictzI18n.translations_dict   s       r   N)r;   r<   )rC   r   r   rE   )r   r   r   r   )r   rK   )r1   r6   r7   r8   recompilerG   r   r?   rJ   propertyrM   r)   r   r   r:   r:   T   s          !bj!DEEO9 9 9 9,8 8 8 8    ! ! ! X! ! !r   r:   )
__future__r   rN   r@   typingr   r   r:   r)   r   r   <module>rS      s    " " " " " " 				       I I I I I I I IX:! :! :! :! :! :! :! :! :! :!r   