Python gettext.bindtextdomain() Examples

The following are 30 code examples of gettext.bindtextdomain(). 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 gettext , or try the search function .
Example #1
Source File: app.py    From tuijam with MIT License 6 votes vote down vote up
def load_locale():
    import gettext
    from importlib.resources import path

    # Load pre-installed translation
    with path('tuijam', 'lang') as locale_path:
        locale = gettext.find('tuijam', locale_path)
        if locale is not None:
            gettext.bindtextdomain('tuijam', locale_path)
            gettext.textdomain('tuijam')

    # Then load user translation
    locale = gettext.find('tuijam', LOCALE_DIR)
    if locale is not None:
        gettext.bindtextdomain('tuijam', LOCALE_DIR)
        gettext.textdomain('tuijam') 
Example #2
Source File: test_gettext.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        # Set up the bindings
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        # For convenience
        self._ = gettext.gettext 
Example #3
Source File: test_gettext.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir) 
Example #4
Source File: test_gettext.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        # Set up the bindings
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        # For convenience
        self._ = gettext.gettext 
Example #5
Source File: translator.py    From uniconvertor with GNU Affero General Public License v3.0 5 votes vote down vote up
def set_locale(self, textdomain, msgs_path, locale='system'):
        msgs_path = msgs_path.decode('utf8') \
            if not (msgs_path, unicode) else msgs_path
        if locale == 'en' or not os.path.exists(msgs_path):
            return
        if locale and not locale == 'system':
            os.environ['LANGUAGE'] = locale
        gettext.bindtextdomain(textdomain, msgs_path)
        gettext.textdomain(textdomain)
        self.translate = gettext.gettext 
Example #6
Source File: i18n.py    From EasY_HaCk with Apache License 2.0 5 votes vote down vote up
def _initGettext():
    charset = initLocale()

    # Try to load gettext module
    if config.use_i18n:
        try:
            import gettext
            ok = True
        except ImportError:
            ok = False
    else:
        ok = False

    # gettext is not available or not needed: use dummy gettext functions
    if not ok:
        return (_dummy_gettext, _dummy_ngettext)

    # Gettext variables
    package = hachoir_core.PACKAGE
    locale_dir = path.join(path.dirname(__file__), "..", "locale")

    # Initialize gettext module
    gettext.bindtextdomain(package, locale_dir)
    gettext.textdomain(package)
    translate = gettext.gettext
    ngettext = gettext.ngettext

    # TODO: translate_unicode lambda function really sucks!
    # => find native function to do that
    unicode_gettext = lambda text: \
        unicode(translate(text), charset)
    unicode_ngettext = lambda singular, plural, count: \
        unicode(ngettext(singular, plural, count), charset)
    return (unicode_gettext, unicode_ngettext) 
Example #7
Source File: test_gettext.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir) 
Example #8
Source File: test_gettext.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        # Set up the bindings
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        # For convenience
        self._ = gettext.gettext 
Example #9
Source File: __init__.py    From AutoBouquetsMaker with GNU General Public License v3.0 5 votes vote down vote up
def localeInit():
	gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath)) 
Example #10
Source File: test_gettext.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir) 
Example #11
Source File: test_gettext.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        # Set up the bindings
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        # For convenience
        self._ = gettext.gettext 
Example #12
Source File: test_gettext.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir) 
Example #13
Source File: test_gettext.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        # Set up the bindings
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        # For convenience
        self._ = gettext.gettext 
Example #14
Source File: __init__.py    From HRTunerProxy with GNU General Public License v2.0 5 votes vote down vote up
def localeInit():
	if isDreamOS: # check if opendreambox image
		lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
		os_environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
	gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath)) 
Example #15
Source File: test_gettext.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir) 
Example #16
Source File: test_gettext.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        # Set up the bindings
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        # For convenience
        self._ = gettext.gettext 
Example #17
Source File: test_gettext.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir) 
Example #18
Source File: test_gettext.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        # Set up the bindings
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        # For convenience
        self._ = gettext.gettext 
Example #19
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 #20
Source File: tools.py    From syncthing-gtk with GNU General Public License v2.0 5 votes vote down vote up
def init_locale(localedir=None):
	"""
	Initializes gettext-related stuff
	"""
	global _localedir
	_localedir = localedir
	gettext.bindtextdomain(GETTEXT_DOMAIN, localedir)
	gettext.bind_textdomain_codeset(GETTEXT_DOMAIN, "utf-8")
	gettext.textdomain(GETTEXT_DOMAIN) 
Example #21
Source File: test_gettext.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir) 
Example #22
Source File: test_gettext.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        # Set up the bindings
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        # For convenience
        self._ = gettext.gettext 
Example #23
Source File: test_gettext.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir) 
Example #24
Source File: test_gettext.py    From oss-ftp with MIT License 5 votes vote down vote up
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        # Set up the bindings
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        # For convenience
        self._ = gettext.gettext 
Example #25
Source File: test_gettext.py    From BinderFilter with MIT License 5 votes vote down vote up
def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir) 
Example #26
Source File: test_gettext.py    From BinderFilter with MIT License 5 votes vote down vote up
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        # Set up the bindings
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        # For convenience
        self._ = gettext.gettext 
Example #27
Source File: i18n.py    From ITWSV with MIT License 5 votes vote down vote up
def _initGettext():
    charset = initLocale()

    # Try to load gettext module
    if config.use_i18n:
        try:
            import gettext
            ok = True
        except ImportError:
            ok = False
    else:
        ok = False

    # gettext is not available or not needed: use dummy gettext functions
    if not ok:
        return (_dummy_gettext, _dummy_ngettext)

    # Gettext variables
    package = hachoir_core.PACKAGE
    locale_dir = path.join(path.dirname(__file__), "..", "locale")

    # Initialize gettext module
    gettext.bindtextdomain(package, locale_dir)
    gettext.textdomain(package)
    translate = gettext.gettext
    ngettext = gettext.ngettext

    # TODO: translate_unicode lambda function really sucks!
    # => find native function to do that
    unicode_gettext = lambda text: \
        unicode(translate(text), charset)
    unicode_ngettext = lambda singular, plural, count: \
        unicode(ngettext(singular, plural, count), charset)
    return (unicode_gettext, unicode_ngettext) 
Example #28
Source File: i18n.py    From Yuki-Chan-The-Auto-Pentest with MIT License 5 votes vote down vote up
def _initGettext():
    charset = initLocale()

    # Try to load gettext module
    if config.use_i18n:
        try:
            import gettext
            ok = True
        except ImportError:
            ok = False
    else:
        ok = False

    # gettext is not available or not needed: use dummy gettext functions
    if not ok:
        return (_dummy_gettext, _dummy_ngettext)

    # Gettext variables
    package = hachoir_core.PACKAGE
    locale_dir = path.join(path.dirname(__file__), "..", "locale")

    # Initialize gettext module
    gettext.bindtextdomain(package, locale_dir)
    gettext.textdomain(package)
    translate = gettext.gettext
    ngettext = gettext.ngettext

    # TODO: translate_unicode lambda function really sucks!
    # => find native function to do that
    unicode_gettext = lambda text: \
        unicode(translate(text), charset)
    unicode_ngettext = lambda singular, plural, count: \
        unicode(ngettext(singular, plural, count), charset)
    return (unicode_gettext, unicode_ngettext) 
Example #29
Source File: test_gettext.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir) 
Example #30
Source File: i18n.py    From innstereo with GNU General Public License v2.0 4 votes vote down vote up
def __init__(self):
        # The translation files will be under
        # @locale_dir@/@LANGUAGE@/LC_MESSAGES/@app_name@.mo
        self.app_name = "innstereo"
        app_dir = abspath(os.path.dirname(__file__))

        # Locale are stored in innstereo/locale
        # .mo files will then be located in innstereo/locale/LANGUAGECODE/LC_MESSAGES/
        locale_dir = abspath(join(app_dir, "locale"))

        if sys.platform == "win32":
            # Set $LANG on MS Windows for gettext
            if os.getenv('LANG') is None:
                lang, enc = locale.getdefaultlocale() #lang is POSIX e.g. de_DE
                os.environ['LANG'] = lang
                languages = [lang]

            # Set LOCALE_DIR for MS Windows
            import ctypes
            LIB_INTL = abspath(join(app_dir, "../gnome/libintl-8.dll"))
            libintl = ctypes.cdll.LoadLibrary(LIB_INTL)
            lc = locale.setlocale(locale.LC_ALL, "")
            locale_dir_g = abspath(join(app_dir, "locale"))
            libintl.bindtextdomain(self.app_name, locale_dir_g)
            libintl.bind_textdomain_codeset(self.app_name, "UTF-8")
        else:
            kwargs = {}
            if sys.version < '3':
                kwargs['unicode'] = 1
            gettext.install(True, localedir=None, **kwargs)

            gettext.find(self.app_name, locale_dir)
            locale.bindtextdomain(self.app_name, locale_dir)

        # Now we need to choose the language. We will provide a list, and gettext
        # will use the first translation available in the list
        default_languages = os.environ.get('LANG', '').split(':')
        default_languages += ['en_US']

        lc, encoding = locale.getdefaultlocale()
        if lc:
            languages = [lc]

        # Concat all languages (env + default locale),
        # and here we have the languages and location of the translations
        languages += default_languages

        gettext.bindtextdomain (self.app_name, locale_dir)
        gettext.textdomain (self.app_name)

        self._language = gettext.translation(self.app_name, locale_dir,
                                             languages=languages, fallback=True)