本文整理汇总了Python中i18n._属性的典型用法代码示例。如果您正苦于以下问题:Python i18n._属性的具体用法?Python i18n._怎么用?Python i18n._使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类i18n
的用法示例。
在下文中一共展示了i18n._属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge_changes
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def merge_changes(self, changectx, repo_file, text, user, parent):
"""Commits and merges conflicting changes in the repository."""
tip_node = changectx.node()
# FIXME: The following line fails sometimes :/
filectx = changectx[repo_file].filectx(parent)
parent_node = filectx.changectx().node()
self.repo.dirstate.setparents(parent_node)
node = self._commit([repo_file], text, user)
partial = lambda filename: repo_file == filename
try:
mercurial.merge.update(self.repo, tip_node, True, True, partial)
msg = _(u'merge of edit conflict')
except mercurial.util.Abort:
msg = _(u'failed merge of edit conflict')
self.repo.dirstate.setparents(tip_node, node)
# Mercurial 1.1 and later need updating the merge state
try:
mercurial.merge.mergestate(self.repo).mark(repo_file, "r")
except (AttributeError, KeyError):
pass
return msg
示例2: artists_text
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def artists_text(entry, inline):
if len(entry['artists']) > 0:
artists = _('<b>Artists:</b>\n')
for artist in entry['artists']:
roles = []
for role in artist['effectiveRoles'].split(', '):
if role == 'Default':
roles.append(artist['categories'][:2])
else:
roles.append(role[:2])
artists += _('[<code>{roles}</code>] '
'{artist_name}').format(roles=','.join(roles), artist_name=artist['name'])
if not inline:
try:
artists += ' /ar_{}'.format(artist['artist']['id'])
except KeyError:
pass
artists += '\n'
return artists
return _('No artists found\n')
示例3: pv
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def pv(bot, update, groups, lang):
data = voca_db.song(groups[0], lang=lang, fields='MainPicture, Names, Lyrics, Artists, PVs')
inline = bool(update.callback_query.inline_message_id)
# TODO: Deal with several of the same service. Ex: 17523 has two YT
for pv_info in data['pVs']:
if pv_info['service'] == groups[1]:
text = ''
if inline:
text = content_parser(data, info=True, inline=True, bot_name=bot.username)
text += '\n\n' + Emoji.MOVIE_CAMERA
text += _('<b>{service} PV for {song} by {artist}</b>\n'
'PV Title:\n{name}\n{url}').format(song=data['name'],
artist=data['artistString'],
service=pv_info['service'],
name=pv_info['name'],
url=pv_info['url'])
edit_message_text(bot, update, send_if_possible=True,
text=text,
reply_markup=song_keyboard(data, inline=True) if inline else None,
parse_mode=ParseMode.HTML)
update.callback_query.answer()
return
示例4: edit_message_text
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def edit_message_text(bot, update, *args, send_if_possible=False, text='', **kwargs):
if update.callback_query.message:
pieces = split(text, MAX_MESSAGE_LENGTH - 1, seps=('\n\n', '\n', ' '))
if len(pieces) > 1:
bot.answer_callback_query(callback_query_id=update.callback_query.id,
text=_('Message too long to send. Attempting to send in pieces.'),
show_alert=True)
for piece in pieces:
if send_if_possible:
bot.send_message(chat_id=update.callback_query.message.chat.id, *args, text=piece, **kwargs)
else:
bot.edit_message_text(chat_id=update.callback_query.message.chat.id,
message_id=update.callback_query.message.message_id,
text=piece,
*args, **kwargs)
# If several pieces we want to send the next piece... probably
send_if_possible = True
elif update.callback_query.inline_message_id:
if len(text) > 4095:
bot.answer_callback_query(callback_query_id=update.callback_query.id,
text=_('Message too long for inline mode! Please use non-inline mode '
'by sending a message directly to {bot_name}.').format(bot_name=bot.name),
show_alert=True)
else:
bot.edit_message_text(inline_message_id=update.callback_query.inline_message_id, *args, text=text, **kwargs)
示例5: on_delete_learned_data_clicked
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def on_delete_learned_data_clicked(self, dummy_widget):
'''
The button requesting to delete all data learned from
user input or text files has been clicked.
'''
SETUP_UI.delete_learned_data_button.set_sensitive(False)
confirm_question = Gtk.Dialog(
title=_('Are you sure?'),
parent=SETUP_UI.builder.get_object('main_dialog'),
buttons=(
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
box = confirm_question.get_content_area()
box.add(Gtk.Label(
_('Do you really want to delete all language \n'
+ 'data learned from typing or reading files?')))
confirm_question.show_all()
response = confirm_question.run()
confirm_question.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if response == Gtk.ResponseType.OK:
SETUP_UI.tabsqlitedb.remove_all_phrases()
SETUP_UI.delete_learned_data_button.set_sensitive(True)
示例6: get_resource_manager_extra_kwargs
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def get_resource_manager_extra_kwargs(f, args, allow_conflicts=False):
"""Return extra_kwargs by calling resource manager kwargs hooks."""
hooks = getattr(f, "resource_manager_kwargs_hooks", [])
extra_kwargs = {}
for hook in hooks:
hook_kwargs = hook(args)
hook_name = hook.__name__
conflicting_keys = set(hook_kwargs.keys()) & set(extra_kwargs.keys())
if conflicting_keys and not allow_conflicts:
msg = (_("Hook '%(hook_name)s' is attempting to redefine "
"attributes '%(conflicting_keys)s'") %
{'hook_name': hook_name,
'conflicting_keys': conflicting_keys})
raise exceptions.NoUniqueMatch(msg)
extra_kwargs.update(hook_kwargs)
return extra_kwargs
示例7: serve
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def serve(api_service, conf, workers=1):
global _launcher
if _launcher:
raise RuntimeError(_('serve() can only be called once'))
_launcher = service.launch(conf, api_service, workers=workers)
示例8: __init__
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def __init__(self, db, lang, storage):
self.db = db
self.lang = lang
self.storage = storage
self.stop_words_re = re.compile(u'^('+u'|'.join(re.escape(_(
u"""am ii iii per po re a about above
across after afterwards again against all almost alone along already also
although always am among ain amongst amoungst amount an and another any aren
anyhow anyone anything anyway anywhere are around as at back be became because
become becomes becoming been before beforehand behind being below beside
besides between beyond bill both but by can cannot cant con could couldnt
describe detail do done down due during each eg eight either eleven else etc
elsewhere empty enough even ever every everyone everything everywhere except
few fifteen fifty fill find fire first five for former formerly forty found
four from front full further get give go had has hasnt have he hence her here
hereafter hereby herein hereupon hers herself him himself his how however
hundred i ie if in inc indeed interest into is it its itself keep last latter
latterly least isn less made many may me meanwhile might mill mine more
moreover most mostly move much must my myself name namely neither never
nevertheless next nine no nobody none noone nor not nothing now nowhere of off
often on once one only onto or other others otherwise our ours ourselves out
over own per perhaps please pre put rather re same see seem seemed seeming
seems serious several she should show side since sincere six sixty so some
somehow someone something sometime sometimes somewhere still such take ten than
that the their theirs them themselves then thence there thereafter thereby
therefore therein thereupon these they thick thin third this those though three
through throughout thru thus to together too toward towards twelve twenty two
un under ve until up upon us very via was wasn we well were what whatever when
whence whenever where whereafter whereas whereby wherein whereupon wherever
whether which while whither who whoever whole whom whose why will with within
without would yet you your yours yourself yourselves""")).split())
+ur')$|.*\d.*', re.U|re.I|re.X)
示例9: _check_path
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def _check_path(self, path):
"""
Ensure that the path is within allowed bounds.
"""
abspath = os.path.abspath(path)
if os.path.islink(path) or os.path.isdir(path):
raise ForbiddenErr(
_(u"Can't use symbolic links or directories as pages"))
if not abspath.startswith(self.path):
raise ForbiddenErr(
_(u"Can't read or write outside of the pages repository"))
示例10: _title_to_file
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def _title_to_file(self, title):
title = title.encode(self.charset).__strip()
filename = quote(title, safe='')
# Escape special windows filenames and dot files
_windows_device_files = ('CON', 'AUX', 'COM1', 'COM2', 'COM3',
'COM4', 'LPT1', 'LPT2', 'LPT3', 'PRN',
'NUL')
if (filename.split('.')[0].upper() in _windows_device_files or
filename.startswith('_') or filename.startswith('.')):
filename = '_' + filename
return os.path.join(self.repo_prefix, filename)
示例11: _file_to_title
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def _file_to_title(self, filepath):
if not filepath.startswith(self.repo_prefix):
raise ForbiddenErr(
_(u"Can't read or write outside of the pages repository"))
name = filepath[len(self.repo_prefix):].strip('/')
# Unescape special windows filenames and dot files
if name.startswith('_') and len(name)>1:
name = name[1:]
return unquote(name)
示例12: names_text
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def names_text(song):
if len(song['names']) > 1:
names = _('<b>Additional names:</b>\n')
for name in song['names']:
if name['value'] != song['name']:
names += name['value'] + '\n'
return names
return _('No additional names found\n')
示例13: album_tracks
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def album_tracks(album, inline):
text = _('<b>Tracks')
if not inline:
text += ' ' + _('on {album_name} by {album_artist}</b>\n').format(album_name=album['name'],
album_artist=album['artistString'])
else:
text += ':</b>\n'
discs = defaultdict(list)
for track in album['tracks']:
discs[track['discNumber']].append(track)
for i, (disc_number, tracks) in enumerate(discs.items()):
if len(discs) > 1:
name = ''
if not i == 0:
text += '\n\n'
if 'discs' in album and album['discs']:
try:
disc = [disc for disc in album['discs'] if disc['discNumber'] == disc_number][0]
# Can't find an album to test this on:
if 'name' in disc:
name = disc['name']
if 'mediaType' in disc:
text += (Emoji.OPTICAL_DISC if disc['mediaType'] == 'Audio' else '??') + ' '
except IndexError:
pass
text += _('<i>Disc {disc_number}').format(disc_number=disc_number)
if name:
text += ' ({})'.format(name)
text += ':</i>\n'
text += content_parser(tracks, inline=inline)
return text
示例14: kill
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def kill(bot, update):
logging.debug("Got /kill from %s" % update.message.from_user.id)
if update.message.from_user.id in OWNER_IDS:
logging.critical("Sending SIGTERM to self!")
import signal
import os
import time
time.sleep(5)
os.kill(os.getpid(), signal.SIGTERM)
else:
update.message.reply_text(_("I can't let you do that, dave."))
示例15: unknown
# 需要导入模块: import i18n [as 别名]
# 或者: from i18n import _ [as 别名]
def unknown(bot, update):
if update.message.chat.type == 'private':
update.message.reply_text(_("Unknown command. Try again or type /help to see list of commands."))
else:
match = re.match(r'^/(?:((?:\S*?){bot_name})|((?:\S*)@(?:\S*))|(\S*))'.format(bot_name=bot.name),
update.message.text)
if match:
if match.groups()[0] or match.groups()[2]:
update.message.reply_text(_("Unknown command. Try again or type /help to see list of commands."))