当前位置: 首页>>代码示例>>Python>>正文


Python gettext.ngettext方法代码示例

本文整理汇总了Python中gettext.ngettext方法的典型用法代码示例。如果您正苦于以下问题:Python gettext.ngettext方法的具体用法?Python gettext.ngettext怎么用?Python gettext.ngettext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gettext的用法示例。


在下文中一共展示了gettext.ngettext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_combo_changed

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def on_combo_changed(self, widget=None):
        """
        Updates the backend description and icon.

        @param widget: just to make this function usable as a signal callback.
                       Not used.
        """
        backend_name = self.combo_types.get_selected()
        if backend_name is None:
            return
        backend = BackendFactory().get_backend(backend_name)
        self.label_description.set_markup(backend.Backend.get_description())

        markup = '<big><big><big><b>%s</b></big></big></big>' % \
            backend.Backend.get_human_default_name()
        self.label_name.set_markup(markup)
        authors = backend.Backend.get_authors()
        author_txt = '<b>%s</b>:\n   - %s' % \
            (ngettext("Author", "Authors", len(authors)),
             reduce(lambda a, b: a + "\n" + "   - " + b, authors))
        self.label_author.set_markup(author_txt)
        pixbuf = self.dialog.get_pixbuf_from_icon_name(backend_name, 128)
        self.image_icon.set_from_pixbuf(pixbuf)
        self.show_all() 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:26,代码来源:addpanel.py

示例2: _match_argument

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [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 = ngettext('expected %s argument',
                               'expected %s arguments',
                               action.nargs) % action.nargs
            msg = nargs_errors.get(action.nargs, default)
            raise ArgumentError(action, msg)

        # return the number of arguments matched
        return len(match.group(1)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:argparse.py

示例3: update_status

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def update_status(self, *args):
		"""Update the total time in the statusbar."""
		self.status_bar.pop(0)
		total_time = self.get_total_time()
		message = ngettext("%s picture", "%s pictures", self.view.length) \
		                                              % self.view.length + ' - '
		# XXX ça prend en compte le 0 comme un pluriel cette merde
		message += ngettext("Total time: %s second", "Total time: %s seconds", \
		                                                total_time) % total_time
		if total_time >= 60:
			message += ' = ' + time_to_string(total_time)
		if self.check_24:
			if total_time != 86400:
				self.show_notification(_("The total duration isn't 24 hours."))
				self.fix_24_btn.set_visible(True)
			else:
				self.close_notification()
		self.status_bar.push(0, message)
		return total_time 
开发者ID:maoschanz,项目名称:dynamic-wallpaper-editor,代码行数:21,代码来源:window.py

示例4: filesizeformat

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def filesizeformat(bytes):
    """
    Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
    102 bytes, etc).
    """
    try:
        bytes = float(bytes)
    except TypeError:
        return "0 bytes"

    if bytes < 1024:
        return ngettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes}
    if bytes < 1024 * 1024:
        return _("%.1f KB") % (bytes / 1024)
    if bytes < 1024 * 1024 * 1024:
        return _("%.1f MB") % (bytes / (1024 * 1024))
    return _("%.1f GB") % (bytes / (1024 * 1024 * 1024)) 
开发者ID:gerardpuig,项目名称:ubuntu-cleaner,代码行数:19,代码来源:files.py

示例5: ngettext

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def ngettext(singular, plural, n):
        if n == 1:
            return singular
        return plural 
开发者ID:war-and-code,项目名称:jawfish,代码行数:6,代码来源:optparse.py

示例6: _process_long_opt

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def _process_long_opt(self, rargs, values):
        arg = rargs.pop(0)

        # Value explicitly attached to arg?  Pretend it's the next
        # argument.
        if "=" in arg:
            (opt, next_arg) = arg.split("=", 1)
            rargs.insert(0, next_arg)
            had_explicit_value = True
        else:
            opt = arg
            had_explicit_value = False

        opt = self._match_long_opt(opt)
        option = self._long_opt[opt]
        if option.takes_value():
            nargs = option.nargs
            if len(rargs) < nargs:
                self.error(ngettext(
                    "%(option)s option requires %(number)d argument",
                    "%(option)s option requires %(number)d arguments",
                    nargs) % {"option": opt, "number": nargs})
            elif nargs == 1:
                value = rargs.pop(0)
            else:
                value = tuple(rargs[0:nargs])
                del rargs[0:nargs]

        elif had_explicit_value:
            self.error(_("%s option does not take a value") % opt)

        else:
            value = None

        option.process(opt, value, values, self) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:37,代码来源:optparse.py

示例7: _process_short_opts

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def _process_short_opts(self, rargs, values):
        arg = rargs.pop(0)
        stop = False
        i = 1
        for ch in arg[1:]:
            opt = "-" + ch
            option = self._short_opt.get(opt)
            i += 1                      # we have consumed a character

            if not option:
                raise BadOptionError(opt)
            if option.takes_value():
                # Any characters left in arg?  Pretend they're the
                # next arg, and stop consuming characters of arg.
                if i < len(arg):
                    rargs.insert(0, arg[i:])
                    stop = True

                nargs = option.nargs
                if len(rargs) < nargs:
                    self.error(ngettext(
                        "%(option)s option requires %(number)d argument",
                        "%(option)s option requires %(number)d arguments",
                        nargs) % {"option": opt, "number": nargs})
                elif nargs == 1:
                    value = rargs.pop(0)
                else:
                    value = tuple(rargs[0:nargs])
                    del rargs[0:nargs]

            else:                       # option doesn't take a value
                value = None

            option.process(opt, value, values, self)

            if stop:
                break


    # -- Feedback methods ---------------------------------------------- 
开发者ID:war-and-code,项目名称:jawfish,代码行数:42,代码来源:optparse.py

示例8: test_plural_forms1

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def test_plural_forms1(self):
        eq = self.assertEqual
        x = gettext.ngettext('There is %s file', 'There are %s files', 1)
        eq(x, 'Hay %s fichero')
        x = gettext.ngettext('There is %s file', 'There are %s files', 2)
        eq(x, 'Hay %s ficheros') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_gettext.py

示例9: test_plural_forms2

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def test_plural_forms2(self):
        eq = self.assertEqual
        with open(self.mofile, 'rb') as fp:
            t = gettext.GNUTranslations(fp)
        x = t.ngettext('There is %s file', 'There are %s files', 1)
        eq(x, 'Hay %s fichero')
        x = t.ngettext('There is %s file', 'There are %s files', 2)
        eq(x, 'Hay %s ficheros')

    # Examples from http://www.gnu.org/software/gettext/manual/gettext.html 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_gettext.py

示例10: _initGettext

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
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) 
开发者ID:Yukinoshita47,项目名称:Yuki-Chan-The-Auto-Pentest,代码行数:36,代码来源:i18n.py

示例11: test_plural_forms2

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def test_plural_forms2(self):
        eq = self.assertEqual
        with open(self.mofile, 'rb') as fp:
            t = gettext.GNUTranslations(fp)
        x = t.ngettext('There is %s file', 'There are %s files', 1)
        eq(x, 'Hay %s fichero')
        x = t.ngettext('There is %s file', 'There are %s files', 2)
        eq(x, 'Hay %s ficheros') 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:10,代码来源:test_gettext.py

示例12: update_minutes_label

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def update_minutes_label(self):
        adjustment = int(self.adjustment.get_value())
        self.minutes_label.set_markup(ngettext(" minute", " minutes",
                                               adjustment)) 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:6,代码来源:period.py

示例13: refresh_day_left

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def refresh_day_left(self):
        # If the task is marked as done, we display the delay between the
        # due date and the actual closing date. If the task isn't marked
        # as done, we display the number of days left.
        status = self.task.get_status()
        if status in [Task.STA_DISMISSED, Task.STA_DONE]:
            delay = self.task.get_days_late()
            if delay is None:
                txt = ""
            elif delay == 0:
                txt = "Completed on time"
            elif delay >= 1:
                txt = ngettext("Completed %(days)d day late",
                               "Completed %(days)d days late", delay) % \
                    {'days': delay}
            elif delay <= -1:
                abs_delay = abs(delay)
                txt = ngettext("Completed %(days)d day early",
                               "Completed %(days)d days early", abs_delay) % \
                    {'days': abs_delay}
        else:
            due_date = self.task.get_due_date()
            result = due_date.days_left()
            if due_date.is_fuzzy():
                txt = ""
            elif result > 0:
                txt = ngettext("Due tomorrow!", "%(days)d days left", result)\
                    % {'days': result}
            elif result == 0:
                txt = _("Due today!")
            elif result < 0:
                abs_result = abs(result)
                txt = ngettext("Due yesterday!", "Was %(days)d days ago",
                               abs_result) % {'days': abs_result}

        style_context = self.window.get_style_context()
        color = style_context.get_color(Gtk.StateFlags.INSENSITIVE).to_color()
        self.dayleft_label.set_markup(
            f"<span color='{color.to_string()}'>{txt}</span>") 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:41,代码来源:editor.py

示例14: to_readable_string

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def to_readable_string(self):
        """ Return nice representation of date.

        Fuzzy dates => localized version
        Close dates => Today, Tomorrow, In X days
        Other => with locale dateformat, stripping year for this year
        """
        if self._fuzzy is not None:
            return STRINGS[self._fuzzy]

        days_left = self.days_left()
        if days_left == 0:
            return _('Today')
        elif days_left < 0:
            abs_days = abs(days_left)
            return ngettext('Yesterday', '%(days)d days ago', abs_days) % \
                {'days': abs_days}
        elif days_left > 0 and days_left <= 15:
            return ngettext('Tomorrow', 'In %(days)d days', days_left) % \
                {'days': days_left}
        else:
            locale_format = locale.nl_langinfo(locale.D_FMT)
            if calendar.isleap(datetime.date.today().year):
                year_len = 366
            else:
                year_len = 365
            if float(days_left) / year_len < 1.0:
                # if it's in less than a year, don't show the year field
                locale_format = locale_format.replace('/%Y', '')
                locale_format = locale_format.replace('.%Y', '.')
            return self._real_date.strftime(locale_format) 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:33,代码来源:dates.py

示例15: _handle_conflict_error

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import ngettext [as 别名]
def _handle_conflict_error(self, action, conflicting_actions):
        message = ngettext('conflicting option string: %s',
                           'conflicting option strings: %s',
                           len(conflicting_actions))
        conflict_string = ', '.join([option_string
                                     for option_string, action
                                     in conflicting_actions])
        raise ArgumentError(action, message % conflict_string) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:argparse.py


注:本文中的gettext.ngettext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。