
    cej                     p    d Z ddlZddlZddlmZ ddlmZ ddlmZ dgZej                  Z G d de	      Z
y)zTranslation function factory
    N)_lazy)_locale)_messageTranslatorFactoryc                       e Zd ZdZddZddZddZddZed        Z	ed        Z
ed	        Zd
 Zed        Zed        Zed        Zed        Zy)r   zCreate translator functionsNc                     || _         |4t        j                  |      }t        j                  j                  |      }|| _        y)a   Establish a set of translation functions for the domain.

        :param domain: Name of translation domain,
                       specifying a message catalog.
        :type domain: str
        :param localedir: Directory with translation catalogs.
        :type localedir: str
        N)domainr   get_locale_dir_variable_nameosenvironget	localedir)selfr	   r   variable_names       4/usr/lib/python3/dist-packages/oslo_i18n/_factory.py__init__zTranslatorFactory.__init__&   s:     #@@HM

}5I"    c                     | j                   t        j                  | j                  d      }|j                  fd}|S )a  Return a translation function ready for use with messages.

        The returned function takes a single value, the unicode string
        to be translated.  The return type varies depending on whether
        lazy translation is being done. When lazy translation is
        enabled, :class:`Message` objects are returned instead of
        regular :class:`unicode` strings.

        The domain argument can be specified to override the default
        from the factory, but the localedir from the factory is always
        used because we assume the log-level translation catalogs are
        installed in the same directory as the main application
        catalog.

        Tr   fallbackc                 b    t         j                  rt        j                  |       S  |       S )z,oslo_i18n.gettextutils translation function.)r	   r   USE_LAZYr   Message)msgr	   ms    r   fz3TranslatorFactory._make_translation_func.<locals>.fN   s&    ~~''F;;S6Mr   r	   gettexttranslationr   r   r	   tr   r   s    `  @r   _make_translation_funcz(TranslatorFactory._make_translation_func5   sF      >[[F*...)-/
 II	
 r   c                     | j                   t        j                  | j                  d      }|j                  fd}|S )a  Return a translation function ready for use with context messages.

        The returned function takes two values, the context of
        the unicode string, the unicode string to be translated.
        The returned type is the same as
        :method:`TranslatorFactory._make_translation_func`.

        The domain argument is the same as
        :method:`TranslatorFactory._make_translation_func`.

        Tr   c                     t         j                  r| |f}t        j                  |d      S | t        |} |      }t        |v r|S |S )z9oslo.i18n.gettextutils translation with context function.T)r	   has_contextual_form)r   r   r   r   CONTEXT_SEPARATOR)ctxr   msgidmsgctxsr	   r   s        r   r   z>TranslatorFactory._make_contextual_translation_func.<locals>.fj   sY    ~~c
''f<@B B "%&7=F&	A A%
Hr   r   r!   s    `  @r   !_make_contextual_translation_funcz3TranslatorFactory._make_contextual_translation_funcU   sF     >[[F*...)-/
 II	 r   c                     | j                   t        j                  | j                  d      }|j                  fd}|S )a  Return a plural translation function ready for use with messages.

        The returned function takes three values, the single form of
        the unicode string, the plural form of the unicode string,
        the count of items to be translated.
        The returned type is the same as
        :method:`TranslatorFactory._make_translation_func`.

        The domain argument is the same as
        :method:`TranslatorFactory._make_translation_func`.

        Tr   c                 r    t         j                  r| ||f}t        j                  |d      S  | ||      S )z3oslo.i18n.gettextutils plural translation function.T)r	   has_plural_formr   )	msgsingle	msgpluralmsgcountr)   r	   r   s       r   r   z:TranslatorFactory._make_plural_translation_func.<locals>.f   s?    ~~"Ix8''f8<> >Y	844r   )r	   r   r    r   ngettextr!   s    `  @r   _make_plural_translation_funcz/TranslatorFactory._make_plural_translation_funcy   sF     >[[F*...)-/
 JJ	5 r   c                 "    | j                         S )z!The default translation function.)r#   r   s    r   primaryzTranslatorFactory.primary   s     **,,r   c                 "    | j                         S )zThe contextual translation function.

        The returned function takes two values, the context of
        the unicode string, the unicode string to be translated.

        .. versionadded:: 2.1.0

        )r,   r6   s    r   contextual_formz!TranslatorFactory.contextual_form   s     5577r   c                 "    | j                         S )a  The plural translation function.

        The returned function takes three values, the single form of
        the unicode string, the plural form of the unicode string,
        the count of items to be translated.

        .. versionadded:: 2.1.0

        )r4   r6   s    r   plural_formzTranslatorFactory.plural_form   s     1133r   c                 D    | j                  | j                  dz   |z         S )Nz-log-)r#   r	   )r   levels     r   _make_log_translation_funcz,TranslatorFactory._make_log_translation_func   s!    **4;;+@5+HIIr   c                 $    | j                  d      S )z"Translate info-level log messages.infor>   r6   s    r   log_infozTranslatorFactory.log_info   s     ..v66r   c                 $    | j                  d      S )z%Translate warning-level log messages.warningrA   r6   s    r   log_warningzTranslatorFactory.log_warning   s     ..y99r   c                 $    | j                  d      S )z#Translate error-level log messages.errorrA   r6   s    r   	log_errorzTranslatorFactory.log_error   s     ..w77r   c                 $    | j                  d      S )z&Translate critical-level log messages.criticalrA   r6   s    r   log_criticalzTranslatorFactory.log_critical   s     ..z::r   )N)__name__
__module____qualname____doc__r   r#   r,   r4   propertyr7   r9   r;   r>   rB   rE   rH   rK    r   r   r   r   #   s    !#@"H> - - 	8 	8 
4 
4J 7 7 : : 8 8 ; ;r   )rO   r   r   	oslo_i18nr   r   r   __all__r'   objectr   rQ   r   r   <module>rU      sC      	    
 .. h; h;r   