[Update] Refactor transliteration function to accept parameters for hiragana and romaji conversion
This commit is contained in:
@@ -298,9 +298,13 @@ class Controller:
|
||||
# その他のエラーは通常通り処理
|
||||
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":
|
||||
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.SEND_MESSAGE_TO_VRC is True:
|
||||
@@ -425,9 +429,13 @@ class Controller:
|
||||
# その他のエラーは通常通り処理
|
||||
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":
|
||||
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.OVERLAY_SMALL_LOG is True and model.overlay.initialized is True:
|
||||
@@ -571,9 +579,13 @@ class Controller:
|
||||
# その他のエラーは通常通り処理
|
||||
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":
|
||||
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
|
||||
if config.SEND_MESSAGE_TO_VRC is True:
|
||||
|
||||
@@ -275,13 +275,21 @@ class Model:
|
||||
self.previous_receive_message = message
|
||||
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)
|
||||
keys_to_keep = {"orig", "hira", "hepburn"}
|
||||
filtered_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)
|
||||
filtered_list = [
|
||||
{key: value for key, value in item.items() if key in keys_to_keep}
|
||||
for item in data_list
|
||||
]
|
||||
return filtered_list
|
||||
|
||||
def setOscIpAddress(self, ip_address):
|
||||
|
||||
Reference in New Issue
Block a user