Spanish loaded by FileUtils::getStringFromFile is weird

Hi,

I am loading a localized text file in Spanish. But it does not loaded well. getStringFromFile does not bring Spanish (including char like ‘Ò’) correctly. And when I try to show it in the label, it shows nothing.

This is the log what I get when I try to show it in the logcat.

da\361a (Original text is “daÒa”)

How can I fix this?
Thanks in advance.

Have you tried to hardcode the string in your source code? Does it work then? I think \361 is the Unicode for the letter you are trying to display.
Perhaps your texteditor doesn’t save the file correctly?
See here: Label v3.0 unicode characters?

Make sure the file from which you are loading is encoded in the same format as the FileUtils reads. I always recommend to use UTF8 everywhere. If you use Windows for developing, notice that Windows applications such as the notepad won’t encode in UTF8 by default, so you should be careful.

The following link is about changing the default encoding of the notepad to UTF8, but there are more advices (like using Notepad++ instead):

I would recommend doing it within the IDE you are using for Cocos2d-x. They always allow you to modify a lot of the editor’s settings, including the text encoding. So just make sure to set UTF8 as the default text encoding format and create or modify the text files with the same editor of the IDE. Some IDEs also let you modify the encoding format of individual files in case you need to have different files with different encodings, but that is not the common case.

I hope this helps you!

1 Like

I couldn’t found the solution. So I hard coded. And it works fine, now.