Scripting Documentation: Add tips about line breaks (\n)

There’s some line breaks related undocumented erratas I have found out by an hour of head-banging and trial-and-error, I hope this can make it into the documentation.

Here’s the discoveries:

When you want to add line breaks in the translation, the source string you put into SV:T() function can include normal line break '\n'.

But in the translation dictionary, you should replace '\n' with '\\n' (so the string becomes \n after escaping), both for the source string and translated string. Otherwise the translation won’t work. String concatenation is allowed.

Example in Lua:

function getTranslations(langCode)
    if langCode == "zh-cn" then
        return {
            {"Some tips here\\n"..
             "Warning text\\n\\n"..
             "Some other tips",
             "提示语\\n警告语\\n\\n"..
             "还是提示语"}
        }
    end
end
-- When using the translation
SV:showMessageBox("", SV:T("Some tips here\nWarning text\n\nSome other tips"))
1 Like