Generalize tag translation using emojis heck yeah
This commit is contained in:
@ -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)
|
It requires googletrans and colorama (For le pretty colors)
|
||||||
|
|
||||||
`pip install googletrans==3.1.0a0`
|
```
|
||||||
|
pip install googletrans==3.1.0a0
|
||||||
|
```
|
||||||
|
|
||||||
and
|
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.
|
respectively.
|
||||||
Including the tags is NECESSARY, otherwise the applier.py will fail.
|
|
||||||
|
|
||||||
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)
|
They are meant to be run in this order:
|
||||||
- (Place dialogue.txt on the same folder as the python script)
|
|
||||||
- Parser.py
|
|
||||||
- Translator.py
|
|
||||||
- Applier.py
|
|
||||||
|
|
||||||
And your translated scripts should be in the output folder.
|
- Place your scripts to translate in the `scripts` 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 `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
|
Your translated scripts should be in the `output` folder. Translating snootgame took around an hour using this method.
|
||||||
# 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).
|
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, Ñ.
|
If you need help or have any questions, just open an issue.
|
@ -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
|
# 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 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
|
# Also by break I mean that it may leave some text in english, is not that it will implode... I think.
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from colorama import init
|
from colorama import init
|
||||||
from colorama import Fore
|
from colorama import Fore
|
||||||
from googletrans import Translator
|
from googletrans import Translator
|
||||||
@ -16,12 +17,30 @@ init()
|
|||||||
|
|
||||||
times = []
|
times = []
|
||||||
|
|
||||||
# Good ol google doesn't know what renpy tags are, so it translates them. This was the cheapest solution.
|
def translate(string):
|
||||||
es_tags = {
|
# Split the string by it's tags
|
||||||
"{rápido}":"{fast}",
|
tokens = re.findall(r'\b\w+\b|{[^}]*}|[^\w\s]|\s+', string)
|
||||||
"{w =": "{w=",
|
|
||||||
"{alfa":"{alpha"
|
# 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):
|
def avrg(nums):
|
||||||
average = sum(nums)/len(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:
|
open('trans.csv', 'w', encoding='utf-8',newline='') as output_file:
|
||||||
|
|
||||||
length = len(input_file.readlines())
|
length = len(input_file.readlines())
|
||||||
|
# Wacky hacks to calculate the time left
|
||||||
input_file.seek(0)
|
input_file.seek(0)
|
||||||
|
|
||||||
# Create readers and writers for the input and output files
|
# 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)
|
start_time = datetime.now().replace(microsecond=0)
|
||||||
try:
|
try:
|
||||||
# Translate the string
|
# Translate the string
|
||||||
translation = translator.translate(row[0], dest='es')
|
translation = translate(row[0])
|
||||||
|
|
||||||
for tag_es, tag in es_tags.items():
|
#Hope this works for escaping, lol
|
||||||
translation.text = translation.text.replace(tag_es,tag)
|
translation = translation.replace('"',r'\"')
|
||||||
|
|
||||||
#Hope this works for escaping lol
|
|
||||||
translation.text = translation.text.replace('"',r'\"')
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'{Fore.RESET}An error occurred: {e}')
|
print(f'{Fore.RESET}An error occurred: {e}')
|
||||||
|
Reference in New Issue
Block a user