Node+Next AI translator (WIP)

What is this?

I made an automatic translator for RMMV using AI in Node+Next.

I am just learning Node, so my code quality is not that good, but the results are really good.

I am giving this project as open source, so if anyone want to help to improve it is welcome!

I made it for RMMV, I don't know if it could work for RMMZ.

IMPORTANT: OpenAI's API offers a $18 credit for the first month; afterwards, a payment is required to continue using their services.

How it works?

RMMV stores the dialogues in data/MapXXX.json, every line is a code 401 command, so, you could have a dialogue like this:

1684886439707.png

Code:
"Really!?"
"Adversity may test us, but it also presents an"
"opportunity for growth and transformation."

The program joins the lines not ending in any of these separators: ,.?!
This way the line "Adversity may test us, but it also presents an" is not translated alone, the whole sentence is joined to get context: "Adversity may test us, but it also presents an opportunity for growth and transformation".

The translation is made with OpenAI (Chat GPT).

As the translation can has different length, the translation is splited again on the last space character before reaching the window limit.

So you could get something like this translating to spanish:

Code:
"¿¡En serio!?"
"La adversidad puede ponernos a prueba,"
"pero también nos presenta una"
"oportunidad para el crecimiento y la"
"transformación"
1684886466533.png

1684886473493.png


As you can see, the first line is separated, and the other lines made more characters than the original text, so a a new line appears in a new window, it also remove lines if the translation is shorter.

Choices are also translated, here I translated to "traditional chinese":

1685154409700.png


How to install it?

Install node js from here.

Download the translator for RMMV folder form here.

Before runing the server edit the .env file and write your Open AI API key, you can create a new key here.

Extract the folder and copy you maps.json (Map001.json, Map002.json, Map003.json...) in the maps folder.

Right click on the "RMMVTranslatorAI" folder and select "Open command windows here" or "Open in windows terminal".

run the following commands:

Code:
npm run build
npm run dev

finally open http://localhost:3000/

How to use it?

When you run the server you will see something like this:

1684637863548.png


You have to write a language, you could wirte something like "italian" or "medieval chinese".
And select a file, you will see a list of all the files you drop in the "maps" folder.

When you press "Translate file", you will see the translation below and a new file will appear in the maps folder.

1684638055575.png


1684638085906.png


And that is all, you now have all the dialogues in that map translated.

What can be translated?

Dialogues and choices can be translated for the following files:
  • Map files (mapXXX.json)
  • Troops.json
  • CommonEvents.json

How can you help?

If you think you can help improve this, you are welcome. There are many things I don't know how to do as I am relatively new to programming in Node.

Some features needed:
  • Set character per line based on the portrait, with no portrait characters are 55, with portrait characters are 43
  • Currently the program translates dialogues only (code 401), other texts like "Show Choices" needs to be included
  • "Show scrolling text" should also be translated.
Changelog
  • 2023-05-23: Fixed some bugs related to spaces, line breaks and question marks.
  • 2023-05-26: Fixed some bugs related to indentation, now the character limit with portrait decreases from 55 and 43, both values are editable.
  • 2023-05-26: Now choices are also translated.
  • 2023-11-22: Changed the code to use the GPT 3.5-Turbo, it is faster and cheaper.
    1700697767484.png
  • 2023-11-22: Fixed some bugs related to game codes (like \V[51] ).
  • 2023-11-22: Fixed a bug which caused some choices translation to have double double quotes (""option"").
I hope this help you to translate your project easier. 😀

If you have any problem tell me.
easier? it sure could and it looks nice, the problem, if they have a fix
size of the message box or using default, this might not exactly work,
as it need more line than 4 as default.

but for what I see on the images, it looks really neat, and a easy way
to convert it fast, but most translations aren't 100% accurate, so tests
and correction should still be done in most cases.

but keep up the nice job though.
Oh! I think I didn't explain well, the fixed size is the best part and more than 4 lines are not a problem.

This is an example in english:
1684886930206.png


Translating it to spanish generates more characters, because spanish has usually longer words, so it generates 5 lines, but RMMV adds a new window for it:
1684887013047.png

1684887016680.png


I made a 40 characters limit because I didn't remember how many characters a dialogue windows has, I just checked and by default with no portrait characters are 55, with portrait characters are 43, I going to add a condition to set character based on the portrait.

(If you are using a different font size or a different screen size, you will be able to change these values)
Updated!
  • Now message portraits are used to cut the text (to 43 characters by default).
  • Now choices are also translated.
  • Fixed some bugs related to indentation.
"Unexpected token '<', "<!DOCTYPE "... is not valid JSON". Can you help me with this ?
Sorry for taking too long to answer, I will try helping you by PM
"Unexpected token '<', "<!DOCTYPE "... is not valid JSON". Can you help me with this ?
I have same Error.
Oh no, I didn't get any answers from Marcewarcom23, so I don't know what caused this problem, I'll try to help you by PM too and post the solution here.
I tried installing it, but I get this error when running "npm run build" :

Error: Cannot find module 'D:\RMMVTranslatorAIForum\RMMVTranslatorAIForum\readFiles.js'

Nodejs is up to date, with package-yaml installed, and I'm using Windows


EDIT : Some modifications had to be made to package.json

I corrected the path to readFiles.js (./pages/api/readFiles.js)

I added the line "type": "module", otherwise an error message says that you can't load that file outside of a module.

Now I'm facing a new error when running the server :
1712348549800.png


Google says that it's because require does not exist client side. But idk where or what to edit to make it work.

Original thread: https://forums.rpgmakerweb.com/threads/node-next-ai-translator-wip.157683/