Skip to content

Instantly share code, notes, and snippets.

@math-a3k
Created November 24, 2019 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save math-a3k/7189c1410ef32a810f57d253947e547b to your computer and use it in GitHub Desktop.
Save math-a3k/7189c1410ef32a810f57d253947e547b to your computer and use it in GitHub Desktop.
A shamefull, bad, ugly and dirty script that will add the remaining entries for updating the plurals of a po file
#
import argparse
from sys import stdout
parser = argparse.ArgumentParser(
description='Updates the plural forms of a .po from initial to final')
parser.add_argument('pofile', type=str, help='Po file to be updated')
parser.add_argument("--from", type=int, dest='from_plural',
help="Initial number of plural forms")
parser.add_argument("--to", type=int, dest='to_plural',
help="Final number of plural forms")
args = parser.parse_args()
with open(args.pofile) as file:
for line in file:
stdout.write(line)
if line.startswith("msgstr[%i]" % (args.from_plural - 1)):
for i in range(args.from_plural, args.to_plural):
stdout.write(("msgstr[%i] " % i) + line[10:])
@math-a3k
Copy link
Author

Usage: python update-po-plurals.py your.po --from=N --to=M > your_new.po
(you will have to adjust manually the header, "nplurals=M")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment