Skip to content

Update romanize docs and keep space #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions pythainlp/transliterate/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ def romanize(
fallback_engine: str = DEFAULT_ROMANIZE_ENGINE,
) -> str:
"""
This function renders Thai words in the Latin alphabet or "romanization",
This function renders Thai word in the Latin alphabet or "romanization",
using the Royal Thai General System of Transcription (RTGS)
[#rtgs_transcription]_. RTGS is the official system published
by the Royal Institute of Thailand. (Thai: ถอดเสียงภาษาไทยเป็นอักษรละติน)

:param str text: Thai text to be romanized
:param str text: A Thai word to be romanized. \
The input should not include whitespace because \
the function is support subwords by spliting whitespace.
:param str engine: One of 'royin' (default), 'thai2rom', 'thai2rom_onnx, 'tltk', and 'lookup'. See more in options for engine section.
:param str fallback_engine: If engine equals 'lookup', use `fallback_engine` for words that are not in the transliteration dict.
No effect on other engines. Default to 'royin'.

:return: A string of Thai words rendered in the Latin alphabet.
:return: A string of a Thai word rendered in the Latin alphabet.
:rtype: str

:Options for engines:
Expand Down Expand Up @@ -53,6 +55,9 @@ def romanize(
romanize("ภาพยนตร์", engine="royin")
# output: 'phapn'

romanize("รส ดี", engine="royin") # subwords
# output: 'rot di'

romanize("ภาพยนตร์", engine="thai2rom")
# output: 'phapphayon'

Expand Down Expand Up @@ -87,9 +92,9 @@ def select_romanize_engine(engine: str):
else:
rom_engine = select_romanize_engine(engine)
trans_word = []
for word in text.split(' '):
trans_word.append(rom_engine(word))
new_word = ''.join(trans_word)
for subword in text.split(' '):
trans_word.append(rom_engine(subword))
new_word = ' '.join(trans_word)
return new_word


Expand Down
Loading