Skip to content

Instantly share code, notes, and snippets.

@imankulov
Created December 17, 2012 14:54
Show Gist options
  • Save imankulov/4318857 to your computer and use it in GitHub Desktop.
Save imankulov/4318857 to your computer and use it in GitHub Desktop.
Get gettext formatted plural forms from CLDR description using android2po (to do the main job) and opterator (for command line parsing)
#!/usr/bin/env python
"""
Requirements:
android2po
opterator
Sample:
$ python android2po_plurals.py pl
nplurals=3; plural=((n == 1) ? 0 : ((((n % 10) >= 2 && (n % 10) <= 4) && (!((n % 100) >= 12 && (n % 100) <= 14))) && (!((n % 100) >= 22 && (n % 100) <= 24))) ? 1 : 2)
"""
from opterator import opterate
from android2po.convert import plural_to_gettext
from android2po.env import Language
@opterate
def plural_form(language):
nplurals, plural = plural_to_gettext(Language(language).locale.plural_form)
print 'nplurals=%d; plural=%s' % (nplurals, plural)
plural_form()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment