Few days ago i bought an “old games” emulator, the problem was that all games names was in Chinese although all the menus was in English
I removed the memory card from the emulator and connected it to my PC, then i saw all games files (.zip) names was in Chinese, so i decided to translate file names to English and hope that the games list will also be in English
I looked for a program to do that in the internet with no luck, so i wrote a small python script to translate using google translate API, Here is how it looked like while the translate was running:
The script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
from googletrans import Translator import os import sys import glob import shutil import ntpath import time def isEnglish(s): try: s.encode(encoding='utf-8').decode('ascii') except UnicodeDecodeError: return False else: return True translator = Translator() path=u'J:\\roms\\' def walkdirs(path): rename(path) for root, dirs, files in os.walk(path, topdown=True): for dir in dirs: dir_path=path+dir+"\\" print("Moving to dir " +dir_path) sys.stdout.flush() walkdirs(dir_path) def rename(path): files=glob.glob(path + "*") i=0 for file in files: if isEnglish(file): print (file) else: i=i+1 old_name=file try: file_base=ntpath.basename(file) file_arr=os.path.splitext(file_base) file_name=file_arr[0] file_ext=file_arr[1] new_name=ntpath.dirname(file)+ "\\"+translator.translate(file_name).text.replace(":","-") new_name=new_name+"."+file_ext except: print ("Translating error") sys.stdout.flush() i=i-1 pass continue try: print ("renaming "+ str(old_name) +" to "+ str(new_name)) sys.stdout.flush() except: try: print ("renaming XXX to "+ str(new_name)) sys.stdout.flush() except: print ("renaming XXX to YYY") sys.stdout.flush() pass shutil.move(old_name, new_name) time.sleep(.300) print (str(i) +" files translated") walkdirs(path) |
I had few problems:
- Google limits the number of translates per day – you need to change your IP address after something like 500 translates (By restarting your internet router or by using a VPN (the error was – “JSONDecodeError: Expecting value: line 1 column 1 (char 0)“
- Some of the names python even can’t show with print, so i added try to the ‘print’ command
Here is how it looks after: