@@ -10,6 +10,7 @@ from os import path
1010
1111from scriptshifter import DB_PATH
1212from scriptshifter .tables import init_db as _init_db
13+ from scriptshifter .trans import transliterate as _transliterate
1314from test .integration import test_sample
1415
1516
@@ -70,5 +71,40 @@ def trans_grp():
7071 pass
7172
7273
74+ @trans_grp .command ()
75+ @click .argument ("src" , type = click .File ("r" ))
76+ @click .argument ("lang" )
77+ @click .option (
78+ "-c" , "--capitalize" , default = None ,
79+ help = "Capitalize output: `first`, `all`, ot none (the default)." )
80+ @click .option (
81+ "-d" , "--t-dir" , default = "s2r" ,
82+ help = "Transliteration direction: `s2r' (default)) or `r2s'" )
83+ @click .option (
84+ "-o" , "--option" , multiple = True ,
85+ help = (
86+ "Language=specific option. Format: key=value. Multiple -o entries "
87+ "are possible." ))
88+ def transliterate (src , lang , t_dir , capitalize , option ):
89+ """
90+ Transliterate text from standard input.
91+
92+ e.g.: `echo "王正强" | /path/to/sscli trans transliterate chinese
93+ -o "marc_field=100"'
94+ """
95+ options = {}
96+ for opt in option :
97+ k , v = opt .split ("=" , 1 )
98+ options [k ] = v
99+
100+ trans , warnings = _transliterate (
101+ src .read (), lang , t_dir , capitalize , options )
102+
103+ for w in warnings :
104+ click .echo (click .style ("WARNING: " , fg = "yellow" ) + w )
105+
106+ click .echo (trans )
107+
108+
73109if __name__ == "__main__" :
74110 cli ()
0 commit comments