def to_gettext(rule):
 rule = PluralRule.parse(rule)
 used_tags = (rule.tags | set([_fallback_tag]))
 _compile = _GettextCompiler().compile
 _get_index = [tag for tag in _plural_tags if (tag in used_tags)].index
 result = [('nplurals=%d; plural=(' % len(used_tags))]
 for (tag, ast) in rule.abstract:
  result.append(('%s ? %d : ' % (_compile(ast), _get_index(tag))))
 result.append(('%d)' % _get_index(_fallback_tag)))
 return ''.join(result)

def to_gettext ( rule ) : rule = PluralRule . parse ( rule ) used_tags = ( rule . tags | set ( [ _fallback_tag ] ) ) _compile = _GettextCompiler ( ) . compile _get_index = [ tag for tag in _plural_tags if ( tag in used_tags ) ] . index result = [ ( 'nplurals=%d; plural=(' % len ( used_tags ) ) ] for ( tag , ast ) in rule . abstract : result . append ( ( '%s ? %d : ' % ( _compile ( ast ) , _get_index ( tag ) ) ) ) result . append ( ( '%d)' % _get_index ( _fallback_tag ) ) ) return '' . join ( result )
the plural rule as gettext expression .