Verified Commit 92f377d2 authored by Carl Schwan's avatar Carl Schwan 🚴🏻

Use argparse instead of click

parent 9b8b46f5
......@@ -11,7 +11,7 @@ function export_pot_file # First parameter will be the path of the pot file we h
function import_po_files # First parameter will be a path that will contain several .po files with the format LANG.po
{
podir=$1
python3 translations.py import-po $podir
python3 translations.py import $podir
python3 translations.py generate-translations
rm -rf locale
}
......
import click
import os
import subprocess
import shutil
@click.group()
@click.pass_context
def cli(ctx: dict):
ctx.ensure_object(dict)
import argparse
def webpage_list():
"""
......@@ -14,12 +9,11 @@ def webpage_list():
"""
return ['content/about-kate.md']
@cli.command()
@click.argument("pot")
def extract(pot):
def extract(args):
"""
First parameter will be the path of the pot file we have to create
"""
pot = args.pot
webpages = ""
for webpage in webpage_list():
webpages += " --master \"" + webpage + "\""
......@@ -27,19 +21,17 @@ def extract(pot):
subprocess.run(command, shell=True, check=True, text=True)
@cli.command()
@click.argument("directory")
def import_po(directory):
def import_po(args):
"""
First parameter will be a path that will contain several .po files with the format LANG.po
"""
directory = args.directory
for translation in os.listdir(directory):
lang = os.path.splitext(translation)[0]
os.makedirs("locale/" + lang + "/LC_MESSAGES/")
shutil.copyfile(directory + "/" + translation, "locale/" + lang + "/LC_MESSAGES/kate-editor-org.po")
@cli.command()
def generate_translations():
def generate_translations(args):
"""
Assume translation located at `locale/$LANG/LC_MESSAGES/`
"""
......@@ -52,5 +44,19 @@ def generate_translations():
subprocess.run(command, shell=True, check=True, text=True)
if __name__ == "__main__":
cli(obj={})
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(help='sub-command help')
extract_cmd = subparsers.add_parser('extract', help='extract strings for translations')
extract_cmd.add_argument('pot')
extract_cmd.set_defaults(func=extract)
import_po_cmd = subparsers.add_parser('import', help='import translated strings')
import_po_cmd.add_argument('directory')
import_po_cmd.set_defaults(func=import_po)
generate_translations_cmd = subparsers.add_parser('generate-translations', help='generate translated content')
generate_translations_cmd.set_defaults(func=generate_translations)
args = parser.parse_args()
args.func(args)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment