I have my C++ iOS game engine ported to Android, and it works fine on the device back to Android 2.2, but I’m running into an issue when it comes to supporting localisation.
The C++ engine loads in .po (gettext) localisation files created using poedit and puts them into a std::wstring. This works absolutely fine on the other platforms I support, but doesn’t work on Android since the NDK doesn’t support wchar/wstring properly. See github for my current (very basic) implementation.
Now, I guess I can manually convert from a multibyte string to a custom defined std::basic_string<uint_32>. As suggested in – Android NDK C++ 'wstring' support
And that would be fine for the most part, but how are people handling string formatting? Though the majority of my strings are just text without any formatting required, some are along the lines of “Well done %1$s, you scored %2$d!“.
How are people handling formatting these strings without swprintf support?
Is there a recommended way to reliably handle cross platform localisation without relying on wchar/wstring support (which I gather isn’t recommend anyway – but no-one seems to suggest a viable alternative that doesn’t rely on 20MB+ libraries that are unsuitable for mobile)?
Many thanks.
I’ve managed to get this to work. Rather than using wide strings throughout the app I’ve converted it to use UTF8 throughout. This allows me to use
sprintfas normal (with certain exceptions of course, like capping string lengths that won’t work). I’m then converting the strings to UTF32 within the font renderer so I don’t have to decode UTF8 on the fly.The implementation has just been uploaded to github for the localisation and font renderer
References
Unicode usage in video games
UTF8 everywhere