sorry, i don’t know how to publish it on github.
sample project is too big for uploading.
here is CCLocalizedString files and test localized files of english and chinese.
useage:
create a helloworld project of cocos2d-x 2.0.1 above.
I have been trying to use this in my current project (iOS & Android). I have it working in iOS but having a hard time getting android to compile properly. I’m pretty sure it has to do with the location of the file and the Android.mk file. The link to the full project is dead so I am justt guessing as to what you changed and did. Here is what I have done so far
1: Place CCLocalizedString.h/cpp inside cocos2dx/platform/
2: Added: #include “platform/CCLocalizedString.h” — to cocos2dx/include/cocos2d.h
3: Added: platform/CCLocalizedString.cpp — to cocos2dx/Android.mk
When I try to test from eclipse I get the following errors:
Description Resource Path Location Type
fatal error: CCString.h: No such file or directory line 13, external location: /Users/Mike/xxx/xxx/cocos2dx/platform/CCLocalizedString.cpp C/C*+ Problem
Description Resource Path Location Type
make: * Error 1 C/C*+ Problem
Can you possibly shed light on the proper location and what I should be adjusting to make it compile correctly for Android. Or perhaps you can post another copy of the full source example to see it al together.
you doesn’t need to place CCLocalizedString.h/cpp inside cocos2dx/platform/.
just place it to your project folder(android) as normal, you can contact me by email: 181399700@qq.com .hope you will solve it ASAP.
Thanks for the reply. I ended up getting it working. I left it in platform since it seems to make sense there for now. I just had to add a directory in front of the include to: #include “cocoa/CCString.h” and it worked along with the other things I did above.
This class is absolutely awesome, it should be incorporated into the actual cocos2dx feature set. I always used NSLocalizedString in pure iOS work so nice to have it available in CC2DX now.
Very nice.
It doesn’t return a good value the first time it is invoked (at least, not in Win32), as string which “c_str()” is returned, is destroyed when function returns.
if (resultStr.length() > 0){
return (string(resultStr)).c_str();
}
return mKey;
Can be fixed easily removing resultStr, and replacing the above with:
+1 on PO / MO files. This requires minimum changes to existing code.
eg. pseudocode. CCLabelTTF::create("text",...);
to something like CCLabelTTF::create(t("text"),...);
where “t” is something like:
string t(const char* text) { return moFileReaderSingleton::GetInstance().Lookup(text); }
You can load a language .mo file like this:
@gelldur I am step closer to use it but I cannot understand one thing. Android assets are no just “folders” and “files” and as far I know: moFileReader::ReadFile(const char* filename) cannot open file from there, even I do that: moFileLib::moFileReaderSingleton::GetInstance().ReadFile(FileUtils::getInstance()->fullPathForFilename("dict/en.mo").c_str());
The problem is later here: std::ifstream stream(filename, std::ios_base::binary | std::ios_base::in); in moFileReader::readFile.
So how exactly I have to read this mo file from assets? I know that NDK has AssetsManager which is used by cocos FileUtils, but this is going to nowhere. I end with cocos2d::Data with binary data of my mo file. How can I get moFileLib working? Please give me some thoughts.
May someone share with some code which can handle reading file with dictionary (but on Android where dictionary is in assets folder like other resources). I cannot achieve this due to fact that I cannot have stream to assets item. Please give some ideas.