2024-02-16 12:48:18 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2024-02-18 11:44:16 +00:00
|
|
|
import os
|
|
|
|
|
2024-02-16 12:48:18 +00:00
|
|
|
from unidecode import unidecode
|
|
|
|
|
2024-02-18 11:44:16 +00:00
|
|
|
import config
|
|
|
|
import parser
|
2024-02-16 12:48:18 +00:00
|
|
|
|
|
|
|
japanese_ranges = [
|
|
|
|
(0x4E00, 0x9FFF), # Kanji
|
|
|
|
(0x3040, 0x309F), # Hiragana
|
|
|
|
(0x30A0, 0x30FF), # Katakana
|
|
|
|
(0xFF00, 0xFFEF), # Full-width Roman characters and symbols
|
|
|
|
(0x3000, 0x303F), # CJK symbols and punctuation (including 「」)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def write_translated():
|
|
|
|
translation = parser.parse_to_tokens()
|
2024-02-18 11:44:16 +00:00
|
|
|
|
|
|
|
output_filepath = os.path.join(config.get('output_path'), 'out.txt')
|
|
|
|
outfile = open(output_filepath, 'w', encoding='shift_jisx0213')
|
2024-02-16 12:48:18 +00:00
|
|
|
|
|
|
|
with open(config.get('original_path'), 'r', encoding='shift_jisx0213') as file:
|
|
|
|
for line in file:
|
|
|
|
found = False
|
|
|
|
for start, end in japanese_ranges:
|
|
|
|
if start <= ord(line[0]) <= end:
|
|
|
|
found = True
|
|
|
|
|
|
|
|
if found and len(translation) > 0:
|
|
|
|
# outfile.write(unidecode(translation.pop(0)[1]).replace("\\","¥"))
|
|
|
|
amount = line.count("@") + line.count("¥")
|
|
|
|
|
|
|
|
outfile.write('`')
|
|
|
|
|
|
|
|
for _ in range(amount):
|
|
|
|
outfile.write(
|
|
|
|
unidecode(translation.pop(0)[1]).replace("\\", "¥"))
|
|
|
|
|
|
|
|
if amount > 0:
|
|
|
|
outfile.write('\n')
|
|
|
|
else:
|
|
|
|
outfile.write(line)
|
|
|
|
|
|
|
|
outfile.close()
|