LocalisedStrings and Chinese characters


I am in the process of localising an iOS app I have made. I use the LocalisedStrings class for this.

I have made a method that returns a single string containing the localised versions of the rather few strings that needs to be translated:

String Settings::getLanguage (String language)
    String r(String::empty);
    if (language == "french")
        r += ("\"preplay note\"=\"préjouer note\"\n");
        r += ("\"language\"=\"langue\"\n");
        r += ("\"metronome\"=\"métronome\"\n");
        r += ("\"restore purchases\"=\"restaurer les achats\"\n");
        r += ("\"colors\"=\"couleurs\"\n");
        r += ("\"note names\"=\"nom des notes\"\n");
    return r;


I set the current language like this:

translationsFrench = getLanguage("french");

LocalisedStrings* ls;

ls = new LocalisedStrings (translationsFrench,true);
LocalisedStrings::setCurrentMappings (ls);


The problem I run into is when I start adding chinese characters in the getLanguage method like this:

r += ("\"preplay note\"=\"调音\"\n");


Doing so will fail to create a valid string when running the code. I get an assertion in the String class that I am trying to create a string from 8-bit data that contains values greater than 127. I see that this is true, but I am not shure how to do this in and nice and elegant way (as I always expect is possible with Juce ;-))?

Help is highly appreciated

best regards

John Parbo Andersen

You can't just slap a bunch of unicode into a C++ source file, because the compiler won't know what encoding the file has. I explain this in the juce coding standards page.

The introjucer has a string literal helper tool to convert unicode strings into valid utf8 escape sequences.

Hi Jules

Thanks. I am kind of new to this text encoding stuff, so thank you for spending time on this basic question. I tried to copy these characters into the Introjucer tool you suggested:


The tool generates the literal, but it does not show them as expected (in the upper window). They are not shown as chinese characters. Does this mean that the text i paste into the tool is not in the correct format or?

If I copy the generated literal into my code it also shows the characters wrong in my app, but it is also not the same characters as in the Introjucer tool.

Any suggestions?



Most likely the font you're using is missing those characters, I don't think there'll be a problem with the utf8 conversion, even if they don't display.

Thanks alot. You are rigth, setting the font to Heiti solved it.