我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用gettext.bindtextdomain()。
def main(): mark_time("in main()") root_logger = logging.getLogger() root_logger.addHandler(logging.StreamHandler()) if '--debug' in sys.argv: root_logger.setLevel(logging.DEBUG) else: root_logger.setLevel(logging.INFO) # Tell GTK+ to use out translations locale.bindtextdomain('gtimelog', LOCALE_DIR) locale.textdomain('gtimelog') # Tell Python's gettext.gettext() to use our translations gettext.bindtextdomain('gtimelog', LOCALE_DIR) gettext.textdomain('gtimelog') # Make ^C terminate the process signal.signal(signal.SIGINT, signal.SIG_DFL) # Run the app app = Application() mark_time("app created") sys.exit(app.run(sys.argv))
def __init__(self): gettext.install('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), unicode=0, codeset="utf-8") gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE)) gettext.textdomain("enigma2") self.activeLanguage = 0 self.catalog = None self.lang = {} self.InitLang() self.callbacks = []
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
def test_bindtextdomain(self): self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir)
def init(): localedir = os.getenv("IBUS_LOCALEDIR") # Python's locale module doesn't provide all methods on some # operating systems like FreeBSD try: # for non-standard localedir locale.bindtextdomain(DOMAINNAME, localedir) locale.bind_textdomain_codeset(DOMAINNAME, "UTF-8") except AttributeError: pass gettext.bindtextdomain(DOMAINNAME, localedir) gettext.bind_textdomain_codeset(DOMAINNAME, "UTF-8")
def localeInit(): gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath))
def i18n(self, location): gettext.bindtextdomain('griffith', location) gettext.textdomain('griffith') gtk.glade.bindtextdomain('griffith', location) gtk.glade.textdomain('griffith') gettext.install('griffith', location, unicode=1)
def init_i18n(languages=None): # Ensure any resources we extract get cleaned up interpreter shutdown atexit.register(pkg_resources.cleanup_resources) # Figure out where the language catalogs are; this will extract them # if the package is frozen localedir = pkg_resources.resource_filename(__name__, 'locale') try: # Use the user's default locale instead of C locale.setlocale(locale.LC_ALL, '') except locale.Error as e: # If locale is not supported, use C which should at least provide # consistency. In this case, don't set a gettext domain to prevent # translation of strings locale.setlocale(locale.LC_ALL, 'C') else: # Set translation domain for GNU's gettext (needed by GTK's Builder) try: locale.bindtextdomain(__project__, localedir) locale.textdomain(__project__) except AttributeError: if sys.platform.startswith('win'): try: # We're on Windows; try and use intl.dll instead import ctypes libintl = ctypes.cdll.LoadLibrary('intl.dll') except OSError: # intl.dll isn't available; give up return else: libintl.bindtextdomain(__project__, localedir) libintl.textdomain(__project__) libintl.bind_textdomain_codeset(__project, 'UTF-8') else: # We're on something else (Mac OS X most likely); no idea what # to do here yet return # Finally, set translation domain for Python's built-in gettext _gettext.bindtextdomain(__project__, localedir) _gettext.textdomain(__project__)
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)
def localeInit(): 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! printDBG(PluginLanguageDomain + " set language to " + lang) gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath))
def localeInit(): lang = 'pl' #TO DO 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! print(PluginLanguageDomain + " set language to " + lang) gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath))
def __init__(self): gettext.install('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), unicode=0, codeset="utf-8") gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE)) gettext.textdomain("enigma2") self.activeLanguage = 0 self.catalog = None self.lang = {} self.langlist = [] # FIXME make list dynamically # name, iso-639 language, iso-3166 country. Please don't mix language&country! self.addLanguage("Deutsch", "de", "DE", "ISO-8859-15") self.addLanguage("English", "en", "EN", "ISO-8859-15") self.addLanguage("Italiano", "it", "IT", "ISO-8859-15") self.addLanguage("Türkçe", "tr", "TR", "ISO-8859-15") self.addLanguage("Français", "fr", "FR", "ISO-8859-15") self.addLanguage("Arabic", "ar", "AE", "ISO-8859-15") self.addLanguage("?????????", "bg", "BG", "ISO-8859-15") self.addLanguage("Català", "ca", "AD", "ISO-8859-15") self.addLanguage("?esky", "cs", "CZ", "ISO-8859-15") self.addLanguage("Dansk", "da", "DK", "ISO-8859-15") self.addLanguage("????????", "el", "GR", "ISO-8859-7") self.addLanguage("SChinese", "zh", "CN", "UTF-8") self.addLanguage("TChinese", "hk", "HK", "UTF-8") self.addLanguage("Español", "es", "ES", "ISO-8859-15") self.addLanguage("Eesti", "et", "EE", "ISO-8859-15") self.addLanguage("Persian", "fa", "IR", "ISO-8859-15") self.addLanguage("Suomi", "fi", "FI", "ISO-8859-15") self.addLanguage("Frysk", "fy", "NL", "ISO-8859-15") self.addLanguage("Hebrew", "he", "IL", "ISO-8859-15") self.addLanguage("Hrvatski", "hr", "HR", "ISO-8859-15") self.addLanguage("Magyar", "hu", "HU", "ISO-8859-15") self.addLanguage("Indonesian", "id", "ID", "ISO-8859-15") self.addLanguage("Íslenska", "is", "IS", "ISO-8859-15") self.addLanguage("Kurdish", "ku", "KU", "ISO-8859-15") self.addLanguage("Lietuvi?", "lt", "LT", "ISO-8859-15") self.addLanguage("Latviešu", "lv", "LV", "ISO-8859-15") self.addLanguage("Nederlands", "nl", "NL", "ISO-8859-15") self.addLanguage("Norsk Bokmål","nb", "NO", "ISO-8859-15") self.addLanguage("Norsk", "no", "NO", "ISO-8859-15") self.addLanguage("Polski", "pl", "PL", "ISO-8859-15") self.addLanguage("Português", "pt", "PT", "ISO-8859-15") self.addLanguage("Português do Brasil", "pt", "BR", "ISO-8859-15") self.addLanguage("Romanian", "ro", "RO", "ISO-8859-15") self.addLanguage("???????", "ru", "RU", "ISO-8859-15") self.addLanguage("Slovensky", "sk", "SK", "ISO-8859-15") self.addLanguage("Slovenš?ina", "sl", "SI", "ISO-8859-15") self.addLanguage("Srpski", "sr", "YU", "ISO-8859-15") self.addLanguage("Svenska", "sv", "SE", "ISO-8859-15") self.addLanguage("???????", "th", "TH", "ISO-8859-15") self.addLanguage("Ukrainian", "uk", "UA", "ISO-8859-15") self.callbacks = []
def load_options_definitions(self, force=False): """ Load vim option descriptions from a mpack file """ r = g.bindtextdomain('nvim', locale_dir) fields = ["full_name", "short_desc", "abbreviation", "scope"] # we embed the mpack file to deal with old nvim folders = [ self.nvim.eval('$VIMRUNTIME').strip(), os.path.join(os.path.dirname(os.path.abspath(__file__)), '../..') ] fname = None # TODO let the user be able to override default paths try: fname = self.nvim.vars['palette_descriptions_file'] logger.info("using configured g:palette_descriptions_file value") except Exception as e: logger.debug("Looking for descriptions files") # NvimDevLintToggle if fname is None: for folder in folders: fname = os.path.join(folder, 'data', 'options.mpack') logger.debug("Checking path '%s'" % fname) if os.path.isfile(fname): break # fname = '/home/teto/neovim2/build/runtime/data/options.mpack' # fname = os.path.join(filedir, "options.mpack"), logger.info("Loading descriptions from file %s" % fname) try: fd = open(fname, 'rb') res = msgpack.loads(fd.read()) except Exception as e: logger.error('Could not load definitions') self.nvim.command("echomsg 'Could not load definitions'") raise e df = pd.DataFrame([], columns=fields) for entry in res: temp = {k.decode(): v.decode() if isinstance(v, bytes) else v for k, v in entry.items()} # unpacker = msgpack.Unpacker(fd, use_list=False) # for unpacked in unpacker: # print(unpacked) df = df.append(temp, ignore_index=True) # df = pd.DataFrame(res, columns=fields) # df.from_records(res) # logger.debug(df["scope"].head()) df["scope"] = df["scope"].apply(lambda x: [e.decode() for e in x]) # print(df) return df # @neovim.function('PaletteGetMenu', sync=True) # def get_menus(self, args): # entries = self.retrieve_menus() # keys = list(entries.keys()) # res = self.nvim.call('PaletteFzf', keys)
def __init__(self): #get current directory self.install_dir = os.getcwd() #set up logging FORMAT = "%(asctime)s %(funcName)-14s %(lineno)d| %(levelname)-8s | %(message)s" logging.basicConfig(filename='gpt.log',level=logging.DEBUG,filemode='w',format=FORMAT,datefmt="%H:%M:%S") self.log = logging.getLogger(__name__) #Glade files/window configuration gladefile_list = [ "tlcalculator.glade", "gopro.glade", "appwindow.glade", "playerwindow.glade"] self.gladefile = [] for f in gladefile_list: self.gladefile.append(os.path.join(self.install_dir,"herostuff",f)) #css stylesheet self.stylesheet = os.path.join(self.install_dir,"herostuff","gtk.css") self.locales_dir = os.path.join(self.install_dir,'herostuff','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(os.path.expanduser('~'),".config","gpt.conf") self.defaultwdir = os.path.join(os.path.expanduser('~'),"GP") if os.path.isfile(self.config) is False: self.stdir = self.defaultwdir self.chkdir(self.stdir) self.createconfig(self.stdir) self.kd_supp = True else: self.readconfig() self.show_message(_("Working directory: %s") % self.stdir)
def main(): """ Start the Safe Eyes. """ system_locale = gettext.translation('safeeyes', localedir=Utility.LOCALE_PATH, languages=[Utility.system_locale(), 'en_US'], fallback=True) system_locale.install() # locale.bindtextdomain is required for Glade files # gettext.bindtextdomain(gettext.textdomain(), Utility.LOCALE_PATH) locale.bindtextdomain('safeeyes', Utility.LOCALE_PATH) parser = argparse.ArgumentParser(prog='safeeyes', description=_('description')) group = parser.add_mutually_exclusive_group() group.add_argument('-a', '--about', help=_('show the about dialog'), action='store_true') group.add_argument('-d', '--disable', help=_('disable the currently running safeeyes instance'), action='store_true') group.add_argument('-e', '--enable', help=_('enable the currently running safeeyes instance'), action='store_true') group.add_argument('-q', '--quit', help=_('quit the running safeeyes instance and exit'), action='store_true') group.add_argument('-s', '--settings', help=_('show the settings dialog'), action='store_true') group.add_argument('-t', '--take-break', help=_('Take a break now').lower(), action='store_true') parser.add_argument('--debug', help=_('start safeeyes in debug mode'), action='store_true') parser.add_argument('--version', action='version', version='%(prog)s ' + SAFE_EYES_VERSION) args = parser.parse_args() # Initialize the logging Utility.intialize_logging(args.debug) config = Config() if __running(): logging.info("Safe Eyes is already running") rpc_client = RPCClient(config.get('rpc_port')) if args.about: rpc_client.show_about() elif args.disable: rpc_client.disable_safeeyes() elif args.enable: rpc_client.enable_safeeyes() elif args.settings: rpc_client.show_settings() elif args.take_break: rpc_client.take_break() elif args.quit: rpc_client.quit() else: # Default behavior is opening settings rpc_client.show_settings() sys.exit(0) elif not args.quit: logging.info("Starting Safe Eyes") safeeyes = SafeEyes(system_locale, config) safeeyes.start() Timer(1.0, lambda: __evaluate_arguments(args, safeeyes)).start() Gtk.main()
def _install(domain, localedir, asglobal=False): ''' :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 sys.platform == 'win32' or sys.platform == 'nt': from ctypes import cdll libintl = cdll.intl libintl.bindtextdomain(domain, localedir) libintl.bind_textdomain_codeset(domain, 'UTF-8') if asglobal: libintl.textdomain(domain) del libintl
def __init__(self): gettext.install('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), unicode=0, codeset="utf-8") gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE)) gettext.textdomain("enigma2") self.activeLanguage = 0 self.catalog = None self.lang = {} self.langlist = [] # FIXME make list dynamically # name, iso-639 language, iso-3166 country. Please don't mix language&country! self.addLanguage("Arabic", "ar", "AE", "ISO-8859-15") self.addLanguage("?????????", "bg", "BG", "ISO-8859-15") self.addLanguage("Català", "ca", "AD", "ISO-8859-15") self.addLanguage("?esky", "cs", "CZ", "ISO-8859-15") self.addLanguage("Dansk", "da", "DK", "ISO-8859-15") self.addLanguage("Deutsch", "de", "DE", "ISO-8859-15") self.addLanguage("????????", "el", "GR", "ISO-8859-7") self.addLanguage("English", "en", "EN", "ISO-8859-15") self.addLanguage("Español", "es", "ES", "ISO-8859-15") self.addLanguage("Eesti", "et", "EE", "ISO-8859-15") self.addLanguage("?????", "fa", "IR", "UTF-8") self.addLanguage("Suomi", "fi", "FI", "ISO-8859-15") self.addLanguage("Français", "fr", "FR", "ISO-8859-15") self.addLanguage("Frysk", "fy", "NL", "ISO-8859-15") self.addLanguage("Hebrew", "he", "IL", "ISO-8859-15") self.addLanguage("TChinese", "hk", "HK", "UTF-8") self.addLanguage("Hrvatski", "hr", "HR", "ISO-8859-15") self.addLanguage("Magyar", "hu", "HU", "ISO-8859-15") self.addLanguage("Indonesian", "id", "ID", "ISO-8859-15") self.addLanguage("Íslenska", "is", "IS", "ISO-8859-15") self.addLanguage("Italiano", "it", "IT", "ISO-8859-15") self.addLanguage("Kurdish", "ku", "KU", "ISO-8859-15") self.addLanguage("Lietuvi?", "lt", "LT", "ISO-8859-15") self.addLanguage("Latviešu", "lv", "LV", "ISO-8859-15") self.addLanguage("Nederlands", "nl", "NL", "ISO-8859-15") self.addLanguage("Norsk Bokmål","nb", "NO", "ISO-8859-15") self.addLanguage("Norsk Nynorsk", "nn", "NO", "ISO-8859-15") self.addLanguage("Polski", "pl", "PL", "ISO-8859-15") self.addLanguage("Português", "pt", "PT", "ISO-8859-15") self.addLanguage("Português do Brasil","pt", "BR", "ISO-8859-15") self.addLanguage("Romanian", "ro", "RO", "ISO-8859-15") self.addLanguage("???????", "ru", "RU", "ISO-8859-15") self.addLanguage("Slovensky", "sk", "SK", "ISO-8859-15") self.addLanguage("Slovenš?ina", "sl", "SI", "ISO-8859-15") self.addLanguage("Srpski", "sr", "YU", "ISO-8859-15") self.addLanguage("Svenska", "sv", "SE", "ISO-8859-15") self.addLanguage("???????", "th", "TH", "ISO-8859-15") self.addLanguage("Türkçe", "tr", "TR", "ISO-8859-15") self.addLanguage("Ukrainian", "uk", "UA", "ISO-8859-15") self.addLanguage("SChinese", "zh", "CN", "UTF-8") self.callbacks = []