suminb / hanja

한글, 한자 라이브러리
130 stars 16 forks source link

Consolidate mode, string_format parameters #9

Open suminb opened 4 years ago

suminb commented 4 years ago

It is possible to specify a translation mode when calling translate().

hanja.translate('大韓民國은 民主共和國이다.', 'substitution')
hanja.translate('大韓民國은 民主共和國이다.', 'combination-text')

It is also possible to provide a custom translation mode by supplying format_string parameter.

hanja.translate('大韓民國은 民主共和國이다.', 'combination-text', format_string='{hanja} {hangul}')

In such cases, the mode parameter does not serve any purposes.

I would like to revise translate() so it only takes format_string parameter, and we provide pre-defined format strings for existing translation modes (substitution, combination-text, combination-html). It will look like this:

hanja.translate('大韓民國은 民主共和國이다.', Mode.substitution)
hanja.translate('大韓民國은 民主共和國이다.', Mode.combination_text)
hanja.translate('大韓民國은 民主共和國이다.', '{hanja} <{hangul}>')