Python locale.textdomain() Examples

The following are 4 code examples of locale.textdomain(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module locale , or try the search function .
Example #1
Source File: i18n.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def setup_l10n(logger=None):
    """Setup RAFCON for localization

    Specify the directory, where the translation files (*.mo) can be found (rafcon/locale/) and set localization domain
    ("rafcon").

    :param logger: which logger to use for printing (either logging.log or distutils.log)
    """
    try:
        locale.setlocale(locale.LC_ALL, '')
    except locale.Error as e:
        logger and logger.warning("Cannot setup translations: {}".format(e))

    localedir = resource_filename('rafcon', 'locale')

    # Install gettext globally: Allows to use _("my string") without further imports
    gettext.install('rafcon', localedir)

    # Required for glade and the GtkBuilder
    locale.bindtextdomain('rafcon', localedir)
    locale.textdomain('rafcon') 
Example #2
Source File: alttoolbar_preferences.py    From alternative-toolbar with GNU General Public License v3.0 5 votes vote down vote up
def switch_locale(self, locale_type):
            """
            Change the locale
            """
            locale.setlocale(locale.LC_ALL, '')
            locale.bindtextdomain(locale_type, RB.locale_dir())
            locale.textdomain(locale_type)
            gettext.bindtextdomain(locale_type, RB.locale_dir())
            gettext.textdomain(locale_type)
            gettext.install(locale_type) 
Example #3
Source File: modules.py    From gpt with GNU General Public License v3.0 4 votes vote down vote up
def __init__(self):

        setproctitle.setproctitle("GPT")
        self.install_dir = os.getcwd()
        self.user_app_dir = os.path.join(os.path.expanduser("~"),
                                         ".config",
                                         "gpt",
                                         )
        # create hidden app folder in user"s home directory if it does
        # not exist
        if not os.path.isdir(self.user_app_dir):
            os.makedirs(self.user_app_dir)

        # initiate GTK+ application
        GLib.set_prgname("GPT")

        # set up logging
        os.chdir(self.user_app_dir)
        self.log = logging.getLogger("gpt")
        with open(os.path.join(self.install_dir, "logging.yaml")) as f:
            config = yaml.load(f)
            logging.config.dictConfig(config)

        self.loglevels = {"critical": 50,
                          "error": 40,
                          "warning": 30,
                          "info": 20,
                          "debug": 10,
                          }

        # log version info for debugging
        self.log.debug("Application version: {}".format(__version__))
        self.log.debug("GTK+ version: {}.{}.{}".format(Gtk.get_major_version(),
                                                          Gtk.get_minor_version(),
                                                          Gtk.get_micro_version(),
                                                          ))
        self.log.debug(_("Application executed from {}").format(self.install_dir))

        self.locales_dir = os.path.join(self.install_dir, "po", "locale")
        self.appname = "GPT"

        # setting up localization
        locale.bindtextdomain(self.appname, self.locales_dir)
        locale.textdomain(self.locales_dir)
        gettext.bindtextdomain(self.appname, self.locales_dir)
        gettext.textdomain(self.appname)

        # check for config file to set up working directory
        # create file in case it does not exist
        self.config = os.path.join(self.user_app_dir, "config.py")
        self.defaultwdir = os.path.join(os.path.expanduser("~"), "GP")

        if os.path.isfile(self.config):
            self.readconfig()
        else:
            self.stdir = self.defaultwdir
            self.chkdir(self.stdir)
            self.createconfig(self.stdir)
            self.kd_supp = True

        self.show_message(_("Working directory: {}").format(self.stdir)) 
Example #4
Source File: elibintl.py    From rednotebook with GNU General Public License v2.0 4 votes vote down vote up
def _install(domain, localedir, asglobal=False, libintl='intl'):
    '''
    :param domain: translation domain
    :param localedir: locale directory
    :param asglobal: if True, installs the function _() in Python’s builtin namespace. Default is False

    Private function doing all the work for the :func:`elib.intl.install` and
    :func:`elib.intl.install_module` functions.
    '''
    # prep locale system
    if asglobal:
        locale.setlocale(locale.LC_ALL, '')

        # on windows systems, set the LANGUAGE environment variable
        if sys.platform == 'win32' or sys.platform == 'nt':
            _putenv('LANGUAGE', _getscreenlanguage())

    # The locale module on Max OS X lacks bindtextdomain so we specifically
    # test on linux2 here. See commit 4ae8b26fd569382ab66a9e844daa0e01de409ceb
    if sys.platform == 'linux2':
        locale.bindtextdomain(domain, localedir)
        locale.bind_textdomain_codeset(domain, 'UTF-8')
        locale.textdomain(domain)

    # initialize Python's gettext interface
    gettext.bindtextdomain(domain, localedir)
    gettext.bind_textdomain_codeset(domain, 'UTF-8')

    if asglobal:
        gettext.textdomain(domain)

    # on windows systems, initialize libintl
    if libintl and (sys.platform == 'win32' or sys.platform == 'nt'):
        from ctypes import cdll
        libintl = cdll.LoadLibrary(libintl)
        libintl.bindtextdomain(domain, localedir)
        libintl.bind_textdomain_codeset(domain, 'UTF-8')

        if asglobal:
            libintl.textdomain(domain)

        del libintl