43 lines
1.2 KiB
Python
Executable File
43 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import config
|
|
import parser
|
|
from unidecode import unidecode
|
|
|
|
#with open('enctest.txt', 'w', encoding='shift_jisx0213') as fileout:
|
|
|
|
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 「」)
|
|
]
|
|
|
|
translation = parser.main()
|
|
outfile = open('out.txt', 'w', encoding='shift_jisx0213')
|
|
|
|
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()
|