Improve_punctuation Japanese punctuation problem

In the improve_translation_formatting function, if improve_punctuation is set to ‘True’ or the default value (True) is used, it is programmed to add missing punctuation marks when there are missing punctuation marks in the translation result.

In Japanese, the punctuation mark is ‘。’. However, in other languages it is ‘.’.

improve_translation_formatting does not take this into account, so when translating a sentence ending in a punctuation mark (’.’) into Japanese, a problem occurs when the Japanese sentence ends in ‘。.’.

Source Code

def improve_translation_formatting(source, translation, improve_punctuation=True):
    source = source.strip()

    if not len(source):
        return ""
    if not len(translation):
        return source
    if improve_punctuation:
        source_last_char = source[len(source) - 1]
        translation_last_char = translation[len(translation) - 1]

        punctuation_chars = ['!', '?', '.', ',', ';']
        if source_last_char in punctuation_chars:
            if translation_last_char != source_last_char:
                if translation_last_char in punctuation_chars:
                    translation = translation[:-1]

                translation += source_last_char
        elif translation_last_char in punctuation_chars:
            translation = translation[:-1]

    if source.islower():
        return translation.lower()

    if source.isupper():
        return translation.upper()

    if source[0].islower():
        return translation[0].lower() + translation[1:]

    if source[0].isupper():
        return translation[0].upper() + translation[1:]

    return translation