我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用gettext.textdomain()。
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_textdomain(self): self.assertEqual(gettext.textdomain(), 'gettext')
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 __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 __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 _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 = []