CM3D2 Converter.translations.pgettext_functions

 1import bpy
 2
 3# Translation functions
 4_      = bpy.app.translations.pgettext
 5iface_ = bpy.app.translations.pgettext_iface
 6tip_   = bpy.app.translations.pgettext_tip
 7data_  = bpy.app.translations.pgettext_data
 8
 9
10def __format_with_translation_function(func):
11    # create a new format function using the specified function for translation
12    def _format(msgid: str, *args, msgctxt=None, **kwargs) -> str:
13        f_msg  = func(msgid=msgid, msgctxt=msgctxt)
14        f_args = [
15            func(msgid=arg, msgctxt=msgctxt) if type(arg) == str else arg 
16            for arg in args 
17        ]
18        f_kwargs = {
19            key: func(msgid=arg, msgctxt=msgctxt) if type(arg) == str else arg
20            for key, arg in kwargs.items() 
21        }
22        return f_msg.format(*f_args, **f_kwargs)
23
24    return _format
25
26
27# Format translation functions
28f_       = __format_with_translation_function( _      )
29f_iface_ = __format_with_translation_function( iface_ )
30f_tip_   = __format_with_translation_function( tip_   )
31f_data_  = __format_with_translation_function( data_  )
def iface_(unknown):

.. method:: pgettext_iface(msgid, msgctxt=None)

Try to translate the given msgid (with optional msgctxt), if labels' translation is enabled.

See pgettext() notes.

:arg msgid: The string to translate. :arg msgctxt: The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).

Returns

The translated string (or msgid if no translation was found).

def tip_(unknown):

.. method:: pgettext_tip(msgid, msgctxt=None)

Try to translate the given msgid (with optional msgctxt), if tooltips' translation is enabled.

See pgettext() notes.

:arg msgid: The string to translate. :arg msgctxt: The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).

Returns

The translated string (or msgid if no translation was found).

def data_(unknown):

.. method:: pgettext_data(msgid, msgctxt=None)

Try to translate the given msgid (with optional msgctxt), if new data name's translation is enabled.

See pgettext() notes.

:arg msgid: The string to translate. :arg msgctxt: The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).

Returns

The translated string (or msgid if no translation was found).

def f_(msgid: str, *args, msgctxt=None, **kwargs) -> str:
13    def _format(msgid: str, *args, msgctxt=None, **kwargs) -> str:
14        f_msg  = func(msgid=msgid, msgctxt=msgctxt)
15        f_args = [
16            func(msgid=arg, msgctxt=msgctxt) if type(arg) == str else arg 
17            for arg in args 
18        ]
19        f_kwargs = {
20            key: func(msgid=arg, msgctxt=msgctxt) if type(arg) == str else arg
21            for key, arg in kwargs.items() 
22        }
23        return f_msg.format(*f_args, **f_kwargs)
def f_iface_(msgid: str, *args, msgctxt=None, **kwargs) -> str:
13    def _format(msgid: str, *args, msgctxt=None, **kwargs) -> str:
14        f_msg  = func(msgid=msgid, msgctxt=msgctxt)
15        f_args = [
16            func(msgid=arg, msgctxt=msgctxt) if type(arg) == str else arg 
17            for arg in args 
18        ]
19        f_kwargs = {
20            key: func(msgid=arg, msgctxt=msgctxt) if type(arg) == str else arg
21            for key, arg in kwargs.items() 
22        }
23        return f_msg.format(*f_args, **f_kwargs)
def f_tip_(msgid: str, *args, msgctxt=None, **kwargs) -> str:
13    def _format(msgid: str, *args, msgctxt=None, **kwargs) -> str:
14        f_msg  = func(msgid=msgid, msgctxt=msgctxt)
15        f_args = [
16            func(msgid=arg, msgctxt=msgctxt) if type(arg) == str else arg 
17            for arg in args 
18        ]
19        f_kwargs = {
20            key: func(msgid=arg, msgctxt=msgctxt) if type(arg) == str else arg
21            for key, arg in kwargs.items() 
22        }
23        return f_msg.format(*f_args, **f_kwargs)
def f_data_(msgid: str, *args, msgctxt=None, **kwargs) -> str:
13    def _format(msgid: str, *args, msgctxt=None, **kwargs) -> str:
14        f_msg  = func(msgid=msgid, msgctxt=msgctxt)
15        f_args = [
16            func(msgid=arg, msgctxt=msgctxt) if type(arg) == str else arg 
17            for arg in args 
18        ]
19        f_kwargs = {
20            key: func(msgid=arg, msgctxt=msgctxt) if type(arg) == str else arg
21            for key, arg in kwargs.items() 
22        }
23        return f_msg.format(*f_args, **f_kwargs)