Philipp Hörist pushed to branch master at gajim / gajim

Commits:

3 changed files:

Changes:

  • gajim/gtk/util.py
    ... ... @@ -13,6 +13,7 @@
    13 13
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    14 14
     
    
    15 15
     from typing import Tuple
    
    16
    +from typing import Any
    
    16 17
     
    
    17 18
     import os
    
    18 19
     import sys
    
    ... ... @@ -35,9 +36,19 @@ log = logging.getLogger('gajim.gtk.util')
    35 36
     
    
    36 37
     
    
    37 38
     class Builder:
    
    38
    -    def __init__(self, filename: str, widget: str = None) -> None:
    
    39
    +    def __init__(self,
    
    40
    +                 filename: str,
    
    41
    +                 widget: str = None,
    
    42
    +                 domain: str = None,
    
    43
    +                 gettext_: Any = None) -> None:
    
    39 44
             self._builder = Gtk.Builder()
    
    40
    -        self._builder.set_translation_domain(i18n.DOMAIN)
    
    45
    +
    
    46
    +        if domain is None:
    
    47
    +            domain = i18n.DOMAIN
    
    48
    +        self._builder.set_translation_domain(domain)
    
    49
    +
    
    50
    +        if gettext_ is None:
    
    51
    +            gettext_ = _
    
    41 52
     
    
    42 53
             file_path = os.path.join(configpaths.get('GUI'), filename)
    
    43 54
     
    
    ... ... @@ -46,7 +57,8 @@ class Builder:
    46 57
                 tree = ET.parse(file_path)
    
    47 58
                 for node in tree.iter():
    
    48 59
                     if 'translatable' in node.attrib and node.text is not None:
    
    49
    -                    node.text = _(node.text)
    
    60
    +                    node.text = gettext_(node.text)
    
    61
    +
    
    50 62
                 xml_text = ET.tostring(tree.getroot(),
    
    51 63
                                        encoding='unicode',
    
    52 64
                                        method='xml')
    

  • gajim/plugins/helpers.py
    ... ... @@ -26,6 +26,9 @@ __all__ = ['log', 'log_calls', 'Singleton']
    26 26
     import logging
    
    27 27
     import functools
    
    28 28
     
    
    29
    +from gajim.plugins import plugins_i18n
    
    30
    +from gajim.gtk.util import Builder
    
    31
    +
    
    29 32
     log = logging.getLogger('gajim.plugin_system')
    
    30 33
     '''
    
    31 34
     Logger for code related to plug-in system.
    
    ... ... @@ -130,3 +133,10 @@ class Singleton(type):
    130 133
                     #'classname' : cls.__name__})
    
    131 134
     
    
    132 135
             return cls.instance
    
    136
    +
    
    137
    +
    
    138
    +def get_builder(file_name: str, widget: str = None) -> Builder:
    
    139
    +    return Builder(file_name,
    
    140
    +                   widget,
    
    141
    +                   domain=plugins_i18n.DOMAIN,
    
    142
    +                   gettext_=plugins_i18n._)

  • gajim/plugins/pluginmanager.py
    ... ... @@ -694,11 +694,7 @@ class PluginManager(metaclass=Singleton):
    694 694
     
    
    695 695
                         plugins_found.append(module_attr)
    
    696 696
                     except TypeError:
    
    697
    -                    # set plugin localization
    
    698
    -                    try:
    
    699
    -                        module_attr._ = plugins_i18n._
    
    700
    -                    except AttributeError:
    
    701
    -                        pass
    
    697
    +                    pass
    
    702 698
                     except configparser.NoOptionError:
    
    703 699
                         # all fields are required
    
    704 700
                         log.debug(