Skip to content

Commit

Permalink
Add transliterate CLI function.
Browse files Browse the repository at this point in the history
  • Loading branch information
scossu committed Dec 28, 2024
1 parent 8553c6a commit 031eb4b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions sscli
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from os import path

from scriptshifter import DB_PATH
from scriptshifter.tables import init_db as _init_db
from scriptshifter.trans import transliterate as _transliterate
from test.integration import test_sample


Expand Down Expand Up @@ -70,5 +71,40 @@ def trans_grp():
pass


@trans_grp.command()
@click.argument("src", type=click.File("r"))
@click.argument("lang")
@click.option(
"-c", "--capitalize", default=None,
help="Capitalize output: `first`, `all`, ot none (the default).")
@click.option(
"-d", "--t-dir", default="s2r",
help="Transliteration direction: `s2r' (default)) or `r2s'")
@click.option(
"-o", "--option", multiple=True,
help=(
"Language=specific option. Format: key=value. Multiple -o entries "
"are possible."))
def transliterate(src, lang, t_dir, capitalize, option):
"""
Transliterate text from standard input.
e.g.: `echo "王正强" | /path/to/sscli trans transliterate chinese
-o "marc_field=100"'
"""
options = {}
for opt in option:
k, v = opt.split("=", 1)
options[k] = v

trans, warnings = _transliterate(
src.read(), lang, t_dir, capitalize, options)

for w in warnings:
click.echo(click.style("WARNING: ", fg="yellow") + w)

click.echo(trans)


if __name__ == "__main__":
cli()

0 comments on commit 031eb4b

Please sign in to comment.