我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用locale.gettext()。
def __init__(self, appdir): self.appdir = appdir # print _("AppDir: %s" % [self.appdir]) newicondirs = [appdir] for icondir in core.xdg.IconTheme.icondirs: if icondir.startswith(core.xdg.IconTheme.basedir): icondir = self.appdir + icondir newicondirs.append(icondir) core.xdg.IconTheme.icondirs = newicondirs + core.xdg.IconTheme.icondirs # search AppDir, then system self.desktopfile = self._find_desktop_file_in_appdir() try: self.name = self.get_nice_name_from_desktop_file(self.desktopfile) except: self.name = "Unknown" try: self.executable = self.get_exec_path(self.get_exec_name_from_desktop_file(self.desktopfile)) except: self.executable = None try: self.icon = self.get_icon_path_by_icon_name(self.get_icon_name_from_desktop_file(self.desktopfile)) except: self.icon = None
def create_artists_label(album): label = ', '.join(album.get_albumartists()) if album.get_artists(): label = locale.gettext("{} feat. {}").format( label, ", ".join(album.get_artists()) ) return label
def create_track_title(track): title = track.get_title() if track.get_artists(): title = locale.gettext("{} feat. {}").format( title, ", ".join(track.get_artists()) ) return title
def update_status_bar(self, widget): self.statusbar.pop(self.context_id) lines = self.text_buffer.get_line_count() chars = self.text_buffer.get_char_count() words = self.text_buffer.get_text(self.text_buffer.get_start_iter(), self.text_buffer.get_end_iter(), False).split() word_count = 0 word_exceptions = ["#", "##", "###", "####", "#####", "######", "*", "**", "-", "+", "_", "/", "\\", "/", ":", ";", "@", "'", "~", "(", ")", "[", "]", "{", "}", "((", "))", "+-", "-+", "/=", ".", "|", "!", "!!", "!!!", "$", "", "%", "^", "&"] # Exclude these from word count for w in words: if w not in word_exceptions: if not re.match('^[0-9]{1,3}$', w): word_count += 1 self.status_message = "Lines: " + str(lines) + ", " + "Words: " + str(word_count) + ", Characters: " + str(chars) self.statusbar.push(self.context_id, self.status_message)
def parse_options(): """Support for command line options""" parser = optparse.OptionParser(version="%%prog %s" % get_version()) parser.add_option( "-v", "--verbose", action="count", dest="verbose", help=_("Show debug messages (-vv debugs remarkable_lib also)")) (options, args) = parser.parse_args() set_up_logging(options)
def get_file_items(self, window, files): # lightweight filter on file type and extension if not any(f.is_directory() or f.get_name().endswith(VIDEO_EXTENSIONS) for f in files): return # create subliminal menu subliminal_menuitem = Nautilus.MenuItem(name='SubliminalMenu::Subliminal', label='Subliminal') sub_menus = Nautilus.Menu() subliminal_menuitem.set_submenu(sub_menus) # create choose submenu on single file if len(files) == 1 and not files[0].is_directory(): choose_menuitem = Nautilus.MenuItem(name='SubliminalSubMenu::Choose', label=_('Choose subtitles')) choose_menuitem.connect('activate', self.choose_callback, files) sub_menus.append_item(choose_menuitem) # create download submenu download_menuitem = Nautilus.MenuItem(name='SubliminalSubMenu::Download', label=_('Download subtitles')) download_menuitem.connect('activate', self.download_callback, files) sub_menus.append_item(download_menuitem) # create configure submenu configure_menuitem = Nautilus.MenuItem(name='SubliminalSubMenu::Configure', label=_('Configure...')) configure_menuitem.connect('activate', self.config_callback) sub_menus.append_item(configure_menuitem) return subliminal_menuitem,
def parse_options(): """Support for command line options""" parser = optparse.OptionParser(version="%%prog %s" % get_version()) parser.add_option( "-v", "--verbose", action="count", dest="verbose", help=_("Show debug messages (-vv debugs pdf_compressor_lib also)")) (options, args) = parser.parse_args() set_up_logging(options)