Created
November 24, 2019 23:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
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:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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")