I want to localize the strings, the text of labels for multiple language support. I am using cocos2d-x 2.2.5
I have been searching and found some links but these links are not with the proper procedure from the scratch.
This link has explained well but the project upload link is broken. There is no proper procedure also
I tried this link too but was unable to succeed. I have been struggling with multiple language support since 2 days. Can anyone please post a tutorial or a sample. Any help will be highly appreciated.
Well, I don’t know what the most comftible way to do it in c++ might be, but for cocos2d-js I just load all my strings in a json file and then copy it with the text in the different languages.
Then, instead of var myLabel = cc.LabelTTF.create("hello world!"); I’d go var myLabel = cc.LabelTTF.create(STRINGS.helloWorld);, where the STRINGS object has been populated with the texts for the currently selected language.
Hi @Den. First of all thanks for the tutorial. It was really appreciable.
I am getting this error as I don’t have this en.json file. Is this file is automatically created or whether we have to externally create it. Please explain how to proceed. the error is
Cocos2d: Get data from file(en.json) failed!
libc++abi.dylib: terminating with uncaught exception of type std::logic_error: basic_string::_S_construct NULL not valid```
You need to create localization files in the “Resource” directory. “en.json” - is a kind of that file. That is simple text file with content of the next form.
Where “key_1”, … , “key_n” - are unique identifiers for strings you want to localize. “value_1”, … , “value_n” - translated variants of strings.
Pay attention to the class LanguageManager constructor. There the appropriate localization file name is defined. As far as you will have all necessary files in your Resource directory errors you get will gone.
I also attach source code for version 3.2 in tutorial, maybe it can helps.
@Den
My game sometimes takes json successfully and sometimes it provides this error
I am using cocos2dx 2.2.5
``
Cocos2d: Language file parsing error!
Assertion failed: (IsObject()), function FindMember, file /Users/rajanmaheshwari/Documents/cocos2d-x-2.2.5/extensions/CocoStudio/Json/rapidjson/document.h, line 620.```
I am unable to understand why this is happening.out of 7 times it crashes 3 times with the above error message and sometimes it takes everything successfully.