#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
}