[Update] Refactor transliteration function to accept parameters for hiragana and romaji conversion

This commit is contained in:
misyaguziya
2025-09-12 16:06:12 +09:00
parent 484d201cb0
commit 5a9a13146c
2 changed files with 32 additions and 12 deletions

View File

@@ -298,9 +298,13 @@ class Controller:
# その他のエラーは通常通り処理 # その他のエラーは通常通り処理
raise raise
if config.CONVERT_MESSAGE_TO_ROMAJI is True or config.CONVERT_MESSAGE_TO_HIRAGANA is True: if config.CONVERT_MESSAGE_TO_HIRAGANA is True or config.CONVERT_MESSAGE_TO_ROMAJI is True:
if config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] == "Japanese": if config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] == "Japanese":
transliteration = model.convertMessageToTransliteration(translation[0]) transliteration = model.convertMessageToTransliteration(
translation[0],
hiragana=config.CONVERT_MESSAGE_TO_HIRAGANA,
romaji=config.CONVERT_MESSAGE_TO_ROMAJI
)
if config.ENABLE_TRANSCRIPTION_SEND is True: if config.ENABLE_TRANSCRIPTION_SEND is True:
if config.SEND_MESSAGE_TO_VRC is True: if config.SEND_MESSAGE_TO_VRC is True:
@@ -425,9 +429,13 @@ class Controller:
# その他のエラーは通常通り処理 # その他のエラーは通常通り処理
raise raise
if config.CONVERT_MESSAGE_TO_ROMAJI is True or config.CONVERT_MESSAGE_TO_HIRAGANA is True: if config.CONVERT_MESSAGE_TO_HIRAGANA is True or config.CONVERT_MESSAGE_TO_ROMAJI is True:
if config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] == "Japanese": if config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] == "Japanese":
transliteration = model.convertMessageToTransliteration(message) transliteration = model.convertMessageToTransliteration(
message,
hiragana=config.CONVERT_MESSAGE_TO_HIRAGANA,
romaji=config.CONVERT_MESSAGE_TO_ROMAJI
)
if config.ENABLE_TRANSCRIPTION_RECEIVE is True: if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
if config.OVERLAY_SMALL_LOG is True and model.overlay.initialized is True: if config.OVERLAY_SMALL_LOG is True and model.overlay.initialized is True:
@@ -571,9 +579,13 @@ class Controller:
# その他のエラーは通常通り処理 # その他のエラーは通常通り処理
raise raise
if config.CONVERT_MESSAGE_TO_ROMAJI is True or config.CONVERT_MESSAGE_TO_HIRAGANA is True: if config.CONVERT_MESSAGE_TO_HIRAGANA is True or config.CONVERT_MESSAGE_TO_ROMAJI is True:
if config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] == "Japanese": if config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] == "Japanese":
transliteration = model.convertMessageToTransliteration(translation[0]) transliteration = model.convertMessageToTransliteration(
translation[0],
hiragana=config.CONVERT_MESSAGE_TO_HIRAGANA,
romaji=config.CONVERT_MESSAGE_TO_ROMAJI
)
# send OSC message # send OSC message
if config.SEND_MESSAGE_TO_VRC is True: if config.SEND_MESSAGE_TO_VRC is True:

View File

@@ -275,13 +275,21 @@ class Model:
self.previous_receive_message = message self.previous_receive_message = message
return repeat_flag return repeat_flag
def convertMessageToTransliteration(self, message: str) -> str: def convertMessageToTransliteration(self, message: str, hiragana: bool=True, romaji: bool=True) -> str:
if hiragana is False and romaji is False:
return message
keys_to_keep = {"orig"}
if hiragana:
keys_to_keep.add("hira")
if romaji:
keys_to_keep.add("hepburn")
data_list = self.kks.convert(message) data_list = self.kks.convert(message)
keys_to_keep = {"orig", "hira", "hepburn"} filtered_list = [
filtered_list = [] {key: value for key, value in item.items() if key in keys_to_keep}
for item in data_list: for item in data_list
filtered_item = {key: value for key, value in item.items() if key in keys_to_keep} ]
filtered_list.append(filtered_item)
return filtered_list return filtered_list
def setOscIpAddress(self, ip_address): def setOscIpAddress(self, ip_address):