Newlines in localized strings


I wonder how to handle new lines in localized strings. I haven’t found a way to insert “\n” (newline) into the strings.

By adding a string replace to the LocalisedStrings::loadFromText, which replaces “/NEWLINE/” with “\n”, everything runs as wanted.

What do you think?

void LocalisedStrings::loadFromText (const String& fileContents) { ... if (newText.isNotEmpty()) translations.set (originalText, newText.replace(T("/NEWLINE/"), T("\n")));


Actually I just fixed that yesterday… Here’s my code, in case it helps:

[code]static const String unescapeString (const String& s)
return s.replace (T("\""), T("""))
.replace (T("\’"), T("’"))
.replace (T("\t"), T("\t"))
.replace (T("\r"), T("\r"))
.replace (T("\n"), T("\n"));

void LocalisedStrings::loadFromText (const String& fileContents)
StringArray lines;
lines.addLines (fileContents);

for (int i = 0; i < lines.size(); ++i)
    String line (lines[i].trim());

    if (line.startsWithChar (T('"')))
        int closeQuote = findCloseQuote (line, 1);

        const String originalText (unescapeString (line.substring (1, closeQuote)));

        if (originalText.isNotEmpty())
            const int openingQuote = findCloseQuote (line, closeQuote + 1);
            closeQuote = findCloseQuote (line, openingQuote + 1);

            const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));

            if (newText.isNotEmpty())
                translations.set (originalText, newText);
    else if (line.startsWithIgnoreCase (T("language:")))
        languageName = line.substring (9).trim();
    else if (line.startsWithIgnoreCase (T("countries:")))
        countryCodes.addTokens (line.substring (10).trim(), true);



That will do. As always, thanks a lot.