本文整理汇总了Python中quodlibet.ngettext函数的典型用法代码示例。如果您正苦于以下问题:Python ngettext函数的具体用法?Python ngettext怎么用?Python ngettext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ngettext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _album
def _album(self, songs, box):
text = []
discs = {}
for song in songs:
try:
discs[song("~#disc")] = int(
song["tracknumber"].split("/")[1])
except (AttributeError, ValueError, IndexError, KeyError):
discs[song("~#disc")] = max([
song("~#track", discs.get(song("~#disc"), 0))])
tracks = sum(discs.values())
discs = len(discs)
length = sum([song.get("~#length", 0) for song in songs])
if tracks == 0 or tracks < len(songs):
tracks = len(songs)
parts = []
if discs > 1:
parts.append(
ngettext("%d disc", "%d discs", discs) % discs)
parts.append(
ngettext("%d track", "%d tracks", tracks) % tracks)
if tracks != len(songs):
parts.append(ngettext("%d selected", "%d selected",
len(songs)) % len(songs))
text.append(", ".join(parts))
text.append(util.format_time_preferred(length))
if "location" in song:
text.append(util.escape(song["location"]))
if "organization" in song or "labelid" in song:
t = util.escape(song.comma("~organization~labelid"))
text.append(t)
if "producer" in song:
text.append(_("Produced by %s") % (
util.escape(song.comma("producer"))))
w = Label("")
w.set_ellipsize(Pango.EllipsizeMode.END)
w.set_markup("\n".join(text))
hb = Gtk.HBox(spacing=12)
cover = CoverImage()
cover.set_property('no-show-all', True)
hb.pack_start(cover, False, True, 0)
def show_cover(cover, success):
if success:
cover.show()
cover.disconnect(signal_id)
signal_id = cover.connect('cover-visible', show_cover)
cover.set_song(song)
hb.pack_start(w, True, True, 0)
box.pack_start(hb, False, False, 0)
示例2: _album
def _album(self, songs, box):
albums, noalbum = _sort_albums(songs)
def format(args):
date, song, album = args
markup = "<big><i>%s</i></big>" % util.escape(album)
return "%s (%s)" % (markup, date[:4]) if date else markup
get_cover = app.cover_manager.get_cover
covers = [(a, get_cover(s), s) for d, s, a in albums]
albums = [format(a) for a in albums]
if noalbum:
albums.append(ngettext("%d song with no album",
"%d songs with no album", noalbum) % noalbum)
l = Label(markup="\n".join(albums), ellipsize=True)
box.pack_start(Frame(_("Selected Discography"), l), False, False, 0)
covers = [ac for ac in covers if bool(ac[1])]
t = Gtk.Table(n_rows=4, n_columns=(len(covers) // 4) + 1)
t.set_col_spacings(12)
t.set_row_spacings(12)
added = set()
for i, (album, cover, song) in enumerate(covers):
if cover.name in added:
continue
cov = ReactiveCoverImage(song=song, tooltip=album)
c = i % 4
r = i // 4
t.attach(cov, c, c + 1, r, r + 1,
xoptions=Gtk.AttachOptions.EXPAND, yoptions=0)
added.add(cover.name)
box.pack_start(t, True, True, 0)
示例3: plugin_songs
def plugin_songs(self, songs):
desc = ngettext("%d song", "%d songs", len(songs)) % len(songs)
win = ConsoleWindow(create_console(songs), title=desc)
win.set_icon_name(self.PLUGIN_ICON)
win.set_title(_("{plugin_name} for {songs} ({app})").format(
plugin_name=self.PLUGIN_NAME, songs=desc, app=app.name))
win.show_all()
示例4: _album
def _album(self, songs, box):
text = []
discs = {}
for song in songs:
try:
discs[song("~#disc")] = int(
song["tracknumber"].split("/")[1])
except (AttributeError, ValueError, IndexError, KeyError):
discs[song("~#disc")] = max([
song("~#track", discs.get(song("~#disc"), 0))])
tracks = sum(discs.values())
discs = len(discs)
length = sum([song.get("~#length", 0) for song in songs])
if tracks == 0 or tracks < len(songs):
tracks = len(songs)
parts = []
if discs > 1:
parts.append(
ngettext("%d disc", "%d discs", discs) % discs)
parts.append(
ngettext("%d track", "%d tracks", tracks) % tracks)
if tracks != len(songs):
parts.append(ngettext("%d selected", "%d selected",
len(songs)) % len(songs))
text.append(", ".join(parts))
text.append("(%s)" % util.format_time_preferred(length))
if "location" in song:
text.append(util.escape(song["location"]))
if "organization" in song or "labelid" in song:
t = util.escape(song.comma("~organization~labelid"))
text.append(t)
if "producer" in song:
text.append(_("Produced by %s") % (
util.escape(song.comma("producer"))))
w = Label(markup="\n".join(text), ellipsize=True)
hb = Gtk.HBox(spacing=12)
hb.pack_start(w, True, True, 0)
hb.pack_start(ReactiveCoverImage(song=song), False, True, 0)
box.pack_start(hb, False, False, 0)
示例5: confirm_multi_album_invoke
def confirm_multi_album_invoke(parent, plugin_name, count):
"""Dialog to confirm invoking a plugin with X albums in case X is high"""
title = ngettext("Run the plugin \"%(name)s\" on %(count)d album?",
"Run the plugin \"%(name)s\" on %(count)d albums?",
count) % {"name": plugin_name, "count": count}
description = ""
ok_text = _("_Run Plugin")
prompt = ConfirmationPrompt(parent, title, description, ok_text).run()
return prompt == ConfirmationPrompt.RESPONSE_INVOKE
示例6: __update_count
def __update_count(self, model, path, lab):
if len(model) == 0:
text = ""
else:
time = sum([row[0].get("~#length", 0) for row in model])
text = ngettext("%(count)d song (%(time)s)",
"%(count)d songs (%(time)s)",
len(model)) % {
"count": len(model), "time": format_time_preferred(time)}
lab.set_text(text)
示例7: suggested_name_for
def suggested_name_for(cls, songs):
if len(songs) == 1:
title = songs[0].comma("title")
else:
title = ngettext(
"%(title)s and %(count)d more",
"%(title)s and %(count)d more",
len(songs) - 1) % (
{'title': songs[0].comma("title"),
'count': len(songs) - 1})
return title
示例8: confirm_multi_playlist_invoke
def confirm_multi_playlist_invoke(parent, plugin_name, count):
"""Dialog to confirm invoking a plugin with X playlists
in case X is high
"""
params = {"name": plugin_name, "count": format_int_locale(count)}
title = ngettext("Run the plugin \"%(name)s\" on %(count)s playlist?",
"Run the plugin \"%(name)s\" on %(count)s playlists?",
count) % params
description = ""
ok_text = _("_Run Plugin")
prompt = ConfirmationPrompt(parent, title, description, ok_text).run()
return prompt == ConfirmationPrompt.RESPONSE_INVOKE
示例9: __init__
def __init__(self, parent, plugin_name, count):
title = ngettext("Run the plugin \"%(name)s\" on %(count)d album?",
"Run the plugin \"%(name)s\" on %(count)d albums?",
count) % {'name': plugin_name, 'count': count}
super(ConfirmMultiAlbumInvoke, self).__init__(
get_top_parent(parent),
title, "",
buttons=Gtk.ButtonsType.NONE)
self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
self.add_icon_button(_("_Run Plugin"), Icons.SYSTEM_RUN,
self.RESPONSE_INVOKE)
self.set_default_response(Gtk.ResponseType.CANCEL)
示例10: __init__
def __init__(self, parent, playlist, songs):
desc = ngettext("What do you want to do with that %d song?",
"What do you want to do with those %d songs?",
len(songs)) % len(songs)
title = _("Confirm action for playlist \"%s\"") % playlist.name
super(ConfirmMultipleSongsAction, self).__init__(
Gtk.MessageType.QUESTION, parent, title, desc,
Gtk.ButtonsType.NONE)
self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
self.add_icon_button(_("_Add"), Icons.LIST_ADD, self.ADD)
self.add_icon_button(_("_Remove"), Icons.LIST_REMOVE, self.REMOVE)
示例11: confirm_song_removal_invoke
def confirm_song_removal_invoke(parent, songs):
songs = set(songs)
if not songs:
return True
count = len(songs)
song = next(iter(songs))
title = (ngettext("Remove track: \"%%(title)s\" from library?",
"Remove %(count)d tracks from library?",
count) % {'count': count}) % {
'title': song('title') or song('~basename')}
return ConfirmationPrompt.RESPONSE_INVOKE == ConfirmationPrompt(
parent, title, "", _("Remove from Library")).run()
示例12: __init__
def __init__(self, parent, playlist, count):
title = ngettext("Are you sure you want to remove %d duplicate song?",
"Are you sure you want to remove %d duplicate songs?",
count) % count
description = (_("The duplicate songs will be removed "
"from the playlist '%s'.") % playlist.name)
super(ConfirmRemoveDuplicatesDialog, self).__init__(
Gtk.MessageType.WARNING, parent, title, description,
Gtk.ButtonsType.NONE)
self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
self.add_icon_button(_("_Remove"), Icons.LIST_REMOVE,
Gtk.ResponseType.YES)
示例13: __on_changed
def __on_changed(self, widget, songs):
if songs:
if len(songs) == 1:
title = songs[0].comma("title")
else:
title = ngettext(
"%(title)s and %(count)d more",
"%(title)s and %(count)d more",
len(songs) - 1) % {'title': songs[0].comma("title"),
'count': len(songs) - 1}
self.set_title("%s - %s" % (title, _("Properties")))
else:
self.set_title(_("Properties"))
self.set_pending(None)
示例14: format_time_long
def format_time_long(time, limit=2):
"""Turn a time value in seconds into x hours, x minutes, etc.
`limit` limits the count of units used, so the result will be <= time.
0 means no limit.
"""
from quodlibet import ngettext
if time < 1:
return _("No time information")
cutoffs = [
(60, lambda n: ngettext("%d second", "%d seconds", n)),
(60, lambda n: ngettext("%d minute", "%d minutes", n)),
(24, lambda n: ngettext("%d hour", "%d hours", n)),
(365, lambda n: ngettext("%d day", "%d days", n)),
(None, lambda n: ngettext("%d year", "%d years", n)),
]
time_str = []
for divisor, gettext_partial in cutoffs:
if time < 1:
break
if divisor is None:
time, unit = 0, time
else:
time, unit = divmod(time, divisor)
if unit:
time_str.append(gettext_partial(unit) % unit)
time_str.reverse()
if limit:
time_str = time_str[:limit]
return ", ".join(time_str)
示例15: __init__
def __init__(self, parent, plugin_name, count):
params = {"name": plugin_name, "count": format_int_locale(count)}
title = ngettext("Run the plugin \"%(name)s\" on %(count)s playlist?",
"Run the plugin \"%(name)s\" on %(count)s playlists?",
count) % params
super(ConfirmMultiPlaylistInvoke, self).__init__(
get_top_parent(parent),
title, "",
buttons=Gtk.ButtonsType.NONE)
self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
self.add_icon_button(
_("_Run Plugin"), Icons.SYSTEM_RUN, self.RESPONSE_INVOKE)
self.set_default_response(Gtk.ResponseType.CANCEL)