本文整理汇总了Python中babel.messages.plurals.get_plural函数的典型用法代码示例。如果您正苦于以下问题:Python get_plural函数的具体用法?Python get_plural怎么用?Python get_plural使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_plural函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_get_plural
def test_get_plural():
assert plurals.get_plural(locale='en') == (2, '(n != 1)')
assert plurals.get_plural(locale='ga') == (3, '(n==1 ? 0 : n==2 ? 1 : 2)')
tup = plurals.get_plural("ja")
assert tup.num_plurals == 1
assert tup.plural_expr == '0'
assert tup.plural_forms == 'npurals=1; plural=0'
assert str(tup) == 'npurals=1; plural=0'
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:9,代码来源:test_plurals.py
示例2: plural_expr
def plural_expr(self):
if self._plural_expr is None:
expr = "(n != 1)"
if self.locale:
expr = get_plural(self.locale)[1]
self._plural_expr = expr
return self._plural_expr
开发者ID:songmm19900210,项目名称:galaxy-tools-prok,代码行数:7,代码来源:catalog.py
示例3: num_plurals
def num_plurals(self):
if self._num_plurals is None:
num = 2
if self.locale:
num = get_plural(self.locale)[0]
self._num_plurals = num
return self._num_plurals
开发者ID:songmm19900210,项目名称:galaxy-tools-prok,代码行数:7,代码来源:catalog.py
示例4: test_get_plural
def test_get_plural():
# See https://localization-guide.readthedocs.io/en/latest/l10n/pluralforms.html for more details.
assert plurals.get_plural(locale='en') == (2, '(n != 1)')
assert plurals.get_plural(locale='ga') == (5, '(n==1 ? 0 : n==2 ? 1 : n>=3 && n<=6 ? 2 : n>=7 && n<=10 ? 3 : 4)')
plural_ja = plurals.get_plural("ja")
assert str(plural_ja) == 'nplurals=1; plural=0;'
assert plural_ja.num_plurals == 1
assert plural_ja.plural_expr == '0'
assert plural_ja.plural_forms == 'nplurals=1; plural=0;'
plural_en_US = plurals.get_plural('en_US')
assert str(plural_en_US) == 'nplurals=2; plural=(n != 1);'
assert plural_en_US.num_plurals == 2
assert plural_en_US.plural_expr == '(n != 1)'
plural_fr_FR = plurals.get_plural('fr_FR')
assert str(plural_fr_FR) == 'nplurals=2; plural=(n > 1);'
assert plural_fr_FR.num_plurals == 2
assert plural_fr_FR.plural_expr == '(n > 1)'
plural_pl_PL = plurals.get_plural('pl_PL')
assert str(plural_pl_PL) == 'nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);'
assert plural_pl_PL.num_plurals == 3
assert plural_pl_PL.plural_expr == '(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'
开发者ID:cloudera,项目名称:hue,代码行数:25,代码来源:test_plurals.py
示例5: plural_expr
def plural_expr(self):
"""The plural expression used by the catalog or locale.
>>> Catalog(locale='en').plural_expr
'(n != 1)'
>>> Catalog(locale='ga').plural_expr
'(n==1 ? 0 : n==2 ? 1 : 2)'
:type: `string_types`"""
if self._plural_expr is None:
expr = '(n != 1)'
if self.locale:
expr = get_plural(self.locale)[1]
self._plural_expr = expr
return self._plural_expr
开发者ID:A-Tran,项目名称:Indecisive,代码行数:15,代码来源:catalog.py
示例6: num_plurals
def num_plurals(self):
"""The number of plurals used by the catalog or locale.
>>> Catalog(locale='en').num_plurals
2
>>> Catalog(locale='ga').num_plurals
3
:type: `int`"""
if self._num_plurals is None:
num = 2
if self.locale:
num = get_plural(self.locale)[0]
self._num_plurals = num
return self._num_plurals
开发者ID:A-Tran,项目名称:Indecisive,代码行数:15,代码来源:catalog.py
示例7: plural_expr
def plural_expr(self):
"""The plural expression used by the catalog or locale.
>>> Catalog(locale='en').plural_expr
'(n != 1)'
>>> Catalog(locale='ga').plural_expr
'(n==1 ? 0 : n==2 ? 1 : n>=3 && n<=6 ? 2 : n>=7 && n<=10 ? 3 : 4)'
>>> Catalog(locale='ding').plural_expr # unknown locale
'(n != 1)'
:type: `string_types`"""
if self._plural_expr is None:
expr = '(n != 1)'
if self.locale:
expr = get_plural(self.locale)[1]
self._plural_expr = expr
return self._plural_expr
开发者ID:JonathanRRogers,项目名称:babel,代码行数:17,代码来源:catalog.py
示例8: test_get_plural_falls_back_to_default
def test_get_plural_falls_back_to_default():
assert plurals.get_plural('ii') == (2, '(n != 1)')
开发者ID:cloudera,项目名称:hue,代码行数:2,代码来源:test_plurals.py
示例9: test_get_plural_accpets_strings
def test_get_plural_accpets_strings():
assert plurals.get_plural(locale='ga') == (5, '(n==1 ? 0 : n==2 ? 1 : n>=3 && n<=6 ? 2 : n>=7 && n<=10 ? 3 : 4)')
开发者ID:cloudera,项目名称:hue,代码行数:2,代码来源:test_plurals.py
示例10: test_get_plural_selection
def test_get_plural_selection(locale, num_plurals, plural_expr):
assert plurals.get_plural(locale) == (num_plurals, plural_expr)
开发者ID:cloudera,项目名称:hue,代码行数:2,代码来源:test_plurals.py
示例11: test_get_plural_accpets_strings
def test_get_plural_accpets_strings():
assert plurals.get_plural(locale='ga') == (3, '(n==1 ? 0 : n==2 ? 1 : 2)')
开发者ID:Mabusto,项目名称:babel,代码行数:2,代码来源:test_plurals.py
示例12: test_plural_tuple_attributes
def test_plural_tuple_attributes():
tup = plurals.get_plural("ja")
assert tup.num_plurals == 1
assert tup.plural_expr == '0'
assert tup.plural_forms == 'npurals=1; plural=0'
assert str(tup) == 'npurals=1; plural=0'
开发者ID:FlowSea,项目名称:babel,代码行数:6,代码来源:test_plurals.py
示例13: add_locale
def add_locale(self, req):
data = {}
errors = []
catalog_template_id = req.args.get('catalog_template', None)
locale = req.args.get('locale')
locale_admins = req.args.getlist('admins')
def add_error(error):
errors.append(error)
data['error'] = tag.ul(*[tag.li(e) for e in errors if e])
data['locale'] = locale
return data
if not catalog_template_id:
errors.append(_("You must first create a catalog template"))
if not locale:
return add_error(_("You must define the new catalog's locale"))
if not locale_admins:
return add_error(_("You must define at least one locale admin"))
Session = session(self.env)
catalog = Session.query(Catalog).get(catalog_template_id)
num_plurals = get_plural(locale=locale).num_plurals
_locale = Session.query(Locale).filter_by(locale=locale,
catalog_id=catalog.id).first()
if _locale:
data['locale'] = _locale
return add_error(_("Locale Exists Already"))
locale = Locale(catalog, locale, num_plurals)
for sid in locale_admins:
locale.admins.append(LocaleAdmin(locale, sid))
catalog.locales.append(locale)
Session.commit()
perm = PermissionSystem(self.env)
sids_without_necessary_perms = []
for admin in locale.admins:
if not 'L10N_MODERATE' in perm.get_user_permissions(admin.sid):
sids_without_necessary_perms.append(admin.sid)
if sids_without_necessary_perms:
msg = ngettext(
"%s does not have the required permissions to administrate." % \
', '.join(["'%s'" % s for s in sids_without_necessary_perms]),
"%s don't have the required permissions to administrate." % \
', '.join(["'%s'" % s for s in sids_without_necessary_perms]),
len(sids_without_necessary_perms))
add_error(tag(msg, _(" Don't forget to "),
tag.a(_('update permissions'),
href=req.href.admin('general', 'perm')),
'.'))
add_notice(req, _("Locale added."))
# Are we importing existing data
locale_catalog_path = req.args.get('catalog')
include_fuzzy = req.args.get('include_fuzzy') == '1'
if not locale_catalog_path or locale_catalog_path == '/':
return data
repos = self.env.get_repository(req.authname)
revision = repos.youngest_rev
try:
node = get_existing_node(req, repos, locale_catalog_path, revision)
except NoSuchChangeset, e:
raise ResourceNotFound(e.message, _('Invalid Changeset Number'))
开发者ID:UfSoft,项目名称:trac-l10n-manager,代码行数:73,代码来源:locales.py
注:本文中的babel.messages.plurals.get_plural函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论