本文整理汇总了Python中gettext.gettext方法的典型用法代码示例。如果您正苦于以下问题:Python gettext.gettext方法的具体用法?Python gettext.gettext怎么用?Python gettext.gettext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gettext
的用法示例。
在下文中一共展示了gettext.gettext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def __init__(self):
Gtk.HeaderBar.__init__(self)
self.search_btn = HeaderBarToggleButton("system-search-symbolic",
_("Search"))
self.add_btn = HeaderBarButton("list-add-symbolic",
_("Add a new account"))
self.settings_btn = HeaderBarButton("open-menu-symbolic",
_("Settings"))
self.select_btn = HeaderBarButton("object-select-symbolic",
_("Selection mode"))
self.cancel_btn = Gtk.Button(label=_("Cancel"))
self.popover = None
self._build_widgets()
示例2: scan_qr
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def scan_qr(self):
"""
Scans a QRCode and fills the entries with the correct data.
"""
from ...models import QRReader, GNOMEScreenshot
filename = GNOMEScreenshot.area()
if filename:
qr_reader = QRReader(filename)
secret = qr_reader.read()
if qr_reader.ZBAR_FOUND:
if not qr_reader.is_valid():
self.__send_notification(_("Invalid QR code"))
else:
self.token_entry.set_text(secret)
else:
self.__send_notification(_("zbar library is not found. "
"QRCode scanner will be disabled"))
示例3: _build_widgets
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def _build_widgets(self):
"""
Build EmptyAccountList widget.
"""
self.set_border_width(36)
self.set_valign(Gtk.Align.CENTER)
self.set_halign(Gtk.Align.CENTER)
# Image
g_icon = Gio.ThemedIcon(name="dialog-information-symbolic.symbolic")
img = Gtk.Image.new_from_gicon(g_icon, Gtk.IconSize.DIALOG)
# Label
label = Gtk.Label(label=_("There are no accounts yet…"))
self.pack_start(img, False, False, 6)
self.pack_start(label, False, False, 6)
示例4: _build_widgets
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def _build_widgets(self):
header_bar = Gtk.HeaderBar()
header_bar.set_show_close_button(False)
header_bar.set_title(_("Edit {} - {}".format(self._account.username,
self._account.provider)))
self.set_titlebar(header_bar)
# Save btn
self.save_btn = Gtk.Button()
self.save_btn.set_label(_("Save"))
self.save_btn.connect("clicked", self._on_save)
self.save_btn.get_style_context().add_class("suggested-action")
header_bar.pack_end(self.save_btn)
self.close_btn = Gtk.Button()
self.close_btn.set_label(_("Close"))
self.close_btn.connect("clicked", self._on_quit)
header_bar.pack_start(self.close_btn)
self.account_config = AccountConfig(edit=True, account=self._account)
self.account_config.connect("changed", self._on_account_config_changed)
self.add(self.account_config)
示例5: _on_save
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def _on_save(self, *_):
"""
Save Button clicked signal handler.
"""
new_account = self.account_config.account
username = new_account["username"]
provider = new_account["provider"]
old_provider = self._account.provider
# Update the AccountRow widget
self.emit("updated", username, provider)
# Update the providers list
if provider != old_provider:
from .list import AccountsWidget
ac_widget = AccountsWidget.get_default()
ac_widget.update_provider(self._account, provider)
self._on_quit()
示例6: __on_clear_database_clicked
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def __on_clear_database_clicked(self, *__):
notification = Gd.Notification()
notification.set_timeout(5)
notification.connect("dismissed", self.__clear_database)
container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
notification_lbl = Gtk.Label()
notification_lbl.set_text(_("The existing accounts will be erased in 5 seconds"))
container.pack_start(notification_lbl, False, False, 3)
undo_btn = Gtk.Button()
undo_btn.set_label(_("Undo"))
undo_btn.connect("clicked", lambda widget: notification.hide())
container.pack_end(undo_btn, False, False, 3)
notification.add(container)
notification_parent = self.stack.get_child_by_name("behaviour")
notification_parent.add(notification)
notification_parent.reorder_child(notification, 0)
self.show_all()
示例7: _build_widgets
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def _build_widgets(self):
header_bar = Gtk.HeaderBar()
header_bar.set_show_close_button(True)
header_bar.set_title(_("GPG paraphrase"))
apply_btn = Gtk.Button()
apply_btn.set_label(_("Import"))
apply_btn.get_style_context().add_class("suggested-action")
apply_btn.connect("clicked", self.__on_apply)
header_bar.pack_end(apply_btn)
self.set_titlebar(header_bar)
container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.paraphrase_widget = SettingsBoxWithEntry(_("Paraphrase"), True)
container.pack_start(self.paraphrase_widget, False, False, 0)
container.get_style_context().add_class("settings-main-container")
self.add(container)
示例8: __on_apply
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def __on_apply(self, *__):
from ...models import BackupJSON
try:
paraphrase = self.paraphrase_widget.entry.get_text()
if not paraphrase:
paraphrase = " "
output_file = path.join(GLib.get_user_cache_dir(),
path.basename(NamedTemporaryFile().name))
status = GPG.get_default().decrypt_json(self._filename, paraphrase, output_file)
if status.ok:
BackupJSON.import_file(output_file)
self.destroy()
else:
self.__send_notification(_("There was an error during the import of the encrypted file."))
except AttributeError:
Logger.error("[GPG] Invalid JSON file.")
示例9: do_longs
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def do_longs(opts, opt, longopts, args):
try:
i = opt.index('=')
except ValueError:
optarg = None
else:
opt, optarg = opt[:i], opt[i+1:]
has_arg, opt = long_has_args(opt, longopts)
if has_arg:
if optarg is None:
if not args:
raise GetoptError(_('option --%s requires argument') % opt, opt)
optarg, args = args[0], args[1:]
elif optarg is not None:
raise GetoptError(_('option --%s must not have an argument') % opt, opt)
opts.append(('--' + opt, optarg or ''))
return opts, args
# Return:
# has_arg?
# full option name
示例10: long_has_args
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def long_has_args(opt, longopts):
possibilities = [o for o in longopts if o.startswith(opt)]
if not possibilities:
raise GetoptError(_('option --%s not recognized') % opt, opt)
# Is there an exact match?
if opt in possibilities:
return False, opt
elif opt + '=' in possibilities:
return True, opt
# No exact match, so better be unique.
if len(possibilities) > 1:
# XXX since possibilities contains all valid continuations, might be
# nice to work them into the error msg
raise GetoptError(_('option --%s not a unique prefix') % opt, opt)
assert len(possibilities) == 1
unique_match = possibilities[0]
has_arg = unique_match.endswith('=')
if has_arg:
unique_match = unique_match[:-1]
return has_arg, unique_match
示例11: _format_args
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def _format_args(self, action, default_metavar):
get_metavar = self._metavar_formatter(action, default_metavar)
if action.nargs is None:
result = '%s' % get_metavar(1)
elif action.nargs == OPTIONAL:
result = '[%s]' % get_metavar(1)
elif action.nargs == ZERO_OR_MORE:
result = '[%s [%s ...]]' % get_metavar(2)
elif action.nargs == ONE_OR_MORE:
result = '%s [%s ...]' % get_metavar(2)
elif action.nargs == REMAINDER:
result = '...'
elif action.nargs == PARSER:
result = '%s ...' % get_metavar(1)
else:
formats = ['%s' for _ in range(action.nargs)]
result = ' '.join(formats) % get_metavar(action.nargs)
return result
示例12: __call__
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def __call__(self, parser, namespace, values, option_string=None):
parser_name = values[0]
arg_strings = values[1:]
# set the parser name if requested
if self.dest is not SUPPRESS:
setattr(namespace, self.dest, parser_name)
# select the parser
try:
parser = self._name_parser_map[parser_name]
except KeyError:
tup = parser_name, ', '.join(self._name_parser_map)
msg = _('unknown parser %r (choices: %s)' % tup)
raise ArgumentError(self, msg)
# parse all the remaining options into the namespace
parser.parse_args(arg_strings, namespace)
# ==============
# Type classes
# ==============
示例13: _match_argument
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def _match_argument(self, action, arg_strings_pattern):
# match the pattern for this action to the arg strings
nargs_pattern = self._get_nargs_pattern(action)
match = _re.match(nargs_pattern, arg_strings_pattern)
# raise an exception if we weren't able to find a match
if match is None:
nargs_errors = {
None: _('expected one argument'),
OPTIONAL: _('expected at most one argument'),
ONE_OR_MORE: _('expected at least one argument'),
}
default = _('expected %s argument(s)') % action.nargs
msg = nargs_errors.get(action.nargs, default)
raise ArgumentError(action, msg)
# return the number of arguments matched
return len(match.group(1))
示例14: _get_value
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def _get_value(self, action, arg_string):
type_func = self._registry_get('type', action.type, action.type)
if not _callable(type_func):
msg = _('%r is not callable')
raise ArgumentError(action, msg % type_func)
# convert the value to the appropriate type
try:
result = type_func(arg_string)
# ArgumentTypeErrors indicate errors
except ArgumentTypeError:
name = getattr(action.type, '__name__', repr(action.type))
msg = str(_sys.exc_info()[1])
raise ArgumentError(action, msg)
# TypeErrors or ValueErrors also indicate errors
except (TypeError, ValueError):
name = getattr(action.type, '__name__', repr(action.type))
msg = _('invalid %s value: %r')
raise ArgumentError(action, msg % (name, arg_string))
# return the converted value
return result
示例15: __call__
# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import gettext [as 别名]
def __call__(self, string):
# the special argument "-" means sys.std{in,out}
if string == '-':
if 'r' in self._mode:
return _sys.stdin
elif 'w' in self._mode:
return _sys.stdout
else:
msg = _('argument "-" with mode %r' % self._mode)
raise ValueError(msg)
try:
# all other arguments are used as file names
if self._bufsize:
return open(string, self._mode, self._bufsize)
else:
return open(string, self._mode)
except IOError:
err = _sys.exc_info()[1]
message = _("can't open '%s': %s")
raise ArgumentTypeError(message % (string, err))