Cocos2D-X Localized Strings

Simple class to localize strings, using plist files. If the corresponding value was not found the key value itself will be returned.
Note: If you need to create plist in windows or linux there are nice free java API online or you can just use python.
Plist files are nothing more than xml files, they just follow a specific schema.

  • Hello Ljapo,
    My name is Olga, I am from GAF Media.

    We are launched a web based converter from Flash CS to GAF format (you can add GAF file to your Cocos2dx, Unity or Starling project).

    Now we are working on desktop version of the Converter.

    If you find the tool interesting and worthy we could really use some publicity. I would really appreciate your unbiased feedback on the tool posted in a form of post on your blog.

    Please let me know what do you think.
    Best Regards,

    • metin

      I’ll be glad to try your software and write about it as soon as I find some time. Converting flash animations to cocos2dx can be really useful.

  • Khang Azun

    Thanks bro! This is really helpful. I have it in my app.

  • Pingback: Đánh dấu | Bầu Bí()

  • This example has deprecated cocos attributes.
    You can use this example instead:

  • #ifndef LocalizedString_hpp
    #define LocalizedString_hpp

    #include “cocos2d.h”

    class LocalizedString {
    static void init();
    static void init(std::string lang);
    static std::string get(std::string key);
    static cocos2d::ValueMap _languageData;
    static std::string getSystemLang();

    #endif /* LocalizedString_hpp */

    #include “LocalizedString.hpp”


    ValueMap LocalizedString::_languageData;

    void LocalizedString::init(){
    auto lang = getSystemLang();
    std::string fname = “languages/” ;
    fname += lang;
    fname += “.plist”;
    _languageData = FileUtils::getInstance()->getValueMapFromFile(fname);

    void LocalizedString::init(std::string lang){
    std::string fname = “languages/” ;
    fname += lang;
    fname += “.plist”;
    _languageData = FileUtils::getInstance()->getValueMapFromFile(fname);

    std::string LocalizedString::get(std::string key){
    auto it = _languageData.find(key);
    if (it != _languageData.end()) {
    return it->second.asString();
    else {
    return key;

    std::string LocalizedString::getSystemLang()
    auto curLanguage = Application::getInstance()->getCurrentLanguage();
    switch (curLanguage) {
    case LanguageType::ENGLISH:
    return “en”;
    case LanguageType::GERMAN:
    return “de”;
    return “en”;

Recent Posts

Recent Comments