[Solved] How to localize the strings in cocos2d-x (multiple language support)

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 but it crashes in the create function of localized string


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 @rajan,

Specially for you I wrote little tutorial with my multi-language approach.

1 Like

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.

Great work Den. I appreciate your approach. It solved my problem and in a good way. thanks

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.

Probably a bit late, but I just write in case anyone arrives here with the same questions. I’ve just published a short tutorial on how I approached the localization of strings for Android in Cocos2d-x. Here is the link: http://becomingindiedev.blogspot.com.es/2015/03/localizing-android-games-in-cocos2d-x.html

Hope it’s useful.

1 Like

Thank you sue602, your CCLocalizedString class works great!

I’ve sent you a update request on github to make it work with cocos2d-x 3.0. For those who want to use my updated version: you can find it here: https://github.com/marcwjj/CCLocalizedStringDemo/commit/b58088f1fe685de6312e6457abaa72a67cdcc7b3