Dragon Quest Builders 2

Discussion in 'Switch - ROM Hacking, Saves, Translations & Tools' started by ben nahalewski, Jan 6, 2019.

  1. HotdogWithMustard

    HotdogWithMustard Newbie

    Newcomer
    1
    Jan 12, 2019
    United States
    I seen that, I wrote a script in AHK to automatically go through and add <br> in the appropriate places. (Beginning of dialog, after a set amount of words, etc)

    I'll post it here when I get off work.
     
    Minalia likes this.
  2. Minalia

    Minalia Newbie

    Newcomer
    1
    Feb 10, 2019
    United States
    There are a lot of mistranslations as i said... and I'm wondering if you manually copy/pasted things because some "Mistranslations" are obviously misplaced... I can't DM here but if you add Mina#1946 on discord we can talk more. I streamed DQB recently in its entirety and I really want to stream DQB2 as well but I couldn't in good conscience stream until it makes enough sense to explain to the audience :P
     
  3. HotdogWithMustard

    HotdogWithMustard Newbie

    Newcomer
    1
    Jan 12, 2019
    United States
    Here's the script I wrote to fix the text wrapping.
    The script goes through each line and splits the text into words then counts how many words till it hits >= 40 character mark and inserts a new line before or at the mark.

    It's written in AHK (AutoHotKey) so you'll need to install that in-order to use it.
    After you have AHK installed create a new file, name it whatever but make sure the extension ends with .ahk, drop the code in the file and then double click the file to run the script.

    Once you run the script it'll ask for a directory, select the directory that contains the translated text files and then wait till you see the done message.
    (It may take a couple minutes to process all the text)

    Some additional notes:
    • The script will only processes files that match this file format: FILE_*.txt
    • The script will only process lines that contain "<key>", the only exception to this is the item description file, it'll process all lines in that file. ("FILE_10.txt")
    • The character name variable ("<pname>") will be replaced with "Dude". (I did this because the text is normally Japanese and it made for some interesting dialog. :rofl:)
    • Lines that contain "<key>" will start with a new line, I do this because lines that contain <key> require user input and are usually dialog lines, dialog lines tend to have the NPC's name right before the dialog and having a new line after the NPC's name makes the text a bit more readable.
    • The script uses a custom function to calculate the text length (used for detecting when to insert a new line). The function is setup to replace all in-text variables with a space then return the total string length. If it detects a certain variable ("<iname>", "<string>", "<space>") in the text, it'll return an invalid length to trigger a new line, It does this because these variables get replaced with different text in-game and I can't really measure the length of the text If I don't know what the text is going to be..
    • You can process individual files by dragging and dropping them onto the compiled version of the script.
    • I was pretty baked when I wrote this and only briefly glanced over it, so please excuse any redundant code and or other issues that I might of over-looked. :)

    Code:
    #NoEnv
    #SingleInstance, Ignore
    
    if (FileExist(A_Args[1]))
    {
        ProcessFile(A_Args[1])
    }
    else
    {
        FileSelectFolder, Path, % "*" A_ScriptDir, 0, % "Select Translations"
     
        if (!Path)
        {
            ExitApp
        }
     
        loop, Files, % Path "\FILE_*.txt", F
        {
            ProcessFile(A_LoopFilePath)
        }
     
        MsgBox, % "Done!"
    }
    
    GetLength(Input)
    {
        while (RegExMatch(Input, "<[\/\$]?([^<>\(\)]+)[^>]*>", Match))
        {
            if ((Match1 == "iname") || (Match1 == "string") || (Match1 == "space"))
            {
                return 100
            }
     
            Input := StrReplace(Input, Match, " ", , 1)
        }
     
        return StrLen(Input)
    }
    
    ProcessFile(Input)
    {
        Local Text
        RegExMatch(Input, "^FILE_(\d+)", Match)
     
        loop
        {
            FileReadLine, Line, % Input, % A_Index
     
            if (ErrorLevel)
            {
                break
            }
     
            if ((Match1 == 10) || (InStr(Line, "<key>")))
            {
                Line := ProcessLine(Line)
            }
     
            Text := Text Line "`n"
        }
     
        if (Text)
        {
            FileDelete, % Input
            FileAppend, % Text, % Input, % "UTF-8"
        }
    }
    
    ProcessLine(Input)
    {
        Local Line, Prefix, Suffix, Index
     
        if (RegExMatch(Input, "^\d+@", Prefix))
        {
            Input := SubStr(Input, StrLen(Prefix) + 1)
        }
     
        for Index, Text in StrSplit(Input, "|")
        {
            if (Index > 1)
            {
                Line := Line "|"
            }
     
            if (RegExMatch(Text, "\s*<key>\s*$", Suffix))
            {
                Text := SubStr(Text, 1, -StrLen(Suffix))
            }
     
            if (RegExMatch(Text, "(\w+)?<pname>(\w+)?", Match))
            {
                Text := StrReplace(Text, Match, Match1 (Match1 ? " " : "") "Dude" (Match2 ? " " : "") Match2)
            }
     
            Text := StrReplace(Text, "…", "...")
            Text := RegExReplace(Text, "\s*<br>\s*", " ")
            Text := RegExReplace(Text, "\s{2,}", " ")
     
            Array := StrSplit(Text, " ")
            Index := 0
     
            loop, % Array.Length()
            {
                Characters := Array[A_Index]
                Length := GetLength(Characters)
       
                if ((Index + Length >= 40) || ((Array[A_Index + 1]) && (Index + Length + 1 >= 40)))
                {
                    Line := Line "<br>"
                    Index := 1
                }
       
                if ((Index) && ((!InStr(Line, "<br>")) || (InStr(Line, "<br>", 0, 0) != (StrLen(Line) - 3))))
                {
                    Line := Line " "
                    Index++
                }
       
                Line := Line Characters
                Index := Index + Length
            }
     
            if (Suffix)
            {
                Line := "<br>" Line Suffix
            }
        }
     
        return Prefix Line
    }
     
    Last edited by HotdogWithMustard, Feb 10, 2019
  4. Minalia

    Minalia Newbie

    Newcomer
    1
    Feb 10, 2019
    United States
    Where's the output files?

    Edit: oh... it edits the files themselves. ok then :P
     
    Last edited by Minalia, Feb 11, 2019
Loading...