diff --git a/Auto Trans/README.md b/Auto Trans/README.md index 915002b..5dec422 100644 --- a/Auto Trans/README.md +++ b/Auto Trans/README.md @@ -1,30 +1,32 @@ -This was mostly made using the GPL chatbot, enjoy! +This was mostly made using the OpenAI chatbot, enjoy! It requires googletrans and colorama (For le pretty colors) -`pip install googletrans==3.1.0a0` +``` +pip install googletrans==3.1.0a0 +``` and -`pip install colorama` +``` +pip install colorama +``` -It expects a dialogue.txt generated from renpy. I personally only include dialogue (That is, no screen text) but it should work regardless if you choose it. -Including the tags is NECESSARY, otherwise the applier.py will fail. +respectively. -They are meant to be run in this order +It expects a `dialogue.txt` generated from renpy. I personally only include dialogue (that is, no screen text), but it should work regardless if you choose to include it. Including the tags is NECESSARY, otherwise `applier.py` will fail. -- (Place your scripts to translate in the scripts folder) -- (Place dialogue.txt on the same folder as the python script) -- Parser.py -- Translator.py -- Applier.py +They are meant to be run in this order: -And your translated scripts should be in the output folder. -Doing this to snootgame took around an hour to autotranslate, googletrans also doesn't use the official Google API, so don't tell em! +- Place your scripts to translate in the `scripts` folder. +- Place `dialogue.txt` in the same folder as the python script. +- Run `parser.py` +- Run `translator.py` +- Run `applier.py` -# This is not a general use tool, you WILL need to modify it to adjust to your needs, and due the nature of the googletrans library it might break any moment -# I wanted to do this the legit way but the jews at Deppl will NOT give out free tier API keys to south americans (smh, fucking racists). +Your translated scripts should be in the `output` folder. Translating snootgame took around an hour using this method. +Keep in mind that googletrans does not use the official Google API, so don't tell 'em! -If you need help or something just open up an issue ig. +# This is not a general use tool, you WILL need to modify it to fit your needs. Due to the nature of the googletrans library, it may break at any moment. I wanted to do this the legitimate way, but the juice at Deepl will NOT give out free tier API keys to South Americans (smh, fucking racists). -Also, Ñ. \ No newline at end of file +If you need help or have any questions, just open an issue. \ No newline at end of file diff --git a/Auto Trans/Translator.py b/Auto Trans/Translator.py index 5715d34..4cfbe3e 100644 --- a/Auto Trans/Translator.py +++ b/Auto Trans/Translator.py @@ -1,9 +1,10 @@ -#Translates the game using good ol fashioned google translator. Be sure to replace the dialogue code in the translator and the tags in es_tags -#Also this breaks a tiny bit if the dialogue contains \n, but oh well. I don't want to open that can of worms. -#Also by break I mean that it may leave some text in english, is not that it will implode... I think +# Translates the game using good ol fashioned google translator. Be sure to replace the dialogue code in the translator. +# Also this breaks a tiny bit if the dialogue contains \n, but oh well. I don't want to open that can of worms. +# Also by break I mean that it may leave some text in english, is not that it will implode... I think. import csv import os +import re from colorama import init from colorama import Fore from googletrans import Translator @@ -16,12 +17,30 @@ init() times = [] -# Good ol google doesn't know what renpy tags are, so it translates them. This was the cheapest solution. -es_tags = { - "{rápido}":"{fast}", - "{w =": "{w=", - "{alfa":"{alpha" -} +def translate(string): + # Split the string by it's tags + tokens = re.findall(r'\b\w+\b|{[^}]*}|[^\w\s]|\s+', string) + + # We encode this bitch up so that google trans doesn't botch the tags + to_restore = [] + for idx, token in enumerate(tokens): + if token[0] == "{": + to_restore.append(token) + # Emojis aren't touched by the translator and retain their position 😎 + tokens[idx] = "🔠" + encoded_string = "".join(tokens) + + # Translate the encoded string + trans = translator.translate(encoded_string, dest='es') + temp = list(trans.text) + + # Restore the original tags + for tag in to_restore: + for idx, char in enumerate(temp): + if char == "🔠": + temp[idx] = tag + break + return "".join(temp) def avrg(nums): average = sum(nums)/len(nums) @@ -32,6 +51,7 @@ with open('original.csv', 'r', encoding='utf-8') as input_file, \ open('trans.csv', 'w', encoding='utf-8',newline='') as output_file: length = len(input_file.readlines()) + # Wacky hacks to calculate the time left input_file.seek(0) # Create readers and writers for the input and output files @@ -43,13 +63,10 @@ with open('original.csv', 'r', encoding='utf-8') as input_file, \ start_time = datetime.now().replace(microsecond=0) try: # Translate the string - translation = translator.translate(row[0], dest='es') + translation = translate(row[0]) - for tag_es, tag in es_tags.items(): - translation.text = translation.text.replace(tag_es,tag) - - #Hope this works for escaping lol - translation.text = translation.text.replace('"',r'\"') + #Hope this works for escaping, lol + translation = translation.replace('"',r'\"') except Exception as e: print(f'{Fore.RESET}An error occurred: {e}')