So, I'm working on translating my C++ app into multiple languages. What I'm currently using is something like:
#define TR(x) (lookupTranslatedString( currentLocale(), x ))
wcout << TR(L"This phrase is in English") << endl;
The translations are from a CSV file which maps the english string to the translated string.
"This phrase is in English","Nasa Tagalog itong pagsabi"
This is simplified, but that's the basic idea.
My question is about generating the list of English phrases that need to be translated. I just need the CSV with all the english phrases, and blank translated phrases. I was hoping that it might be possible to either generate this list at compile time or at runtime. At compiletime I was thinking something like this:
#define TR(x) \
#warning x \
(lookupTranslatedString( currentLocale(), x ))
and then maybe parse the compile log, or something. This seems not to work so well.
At runtime would also be great. I was thinking of just starting the app and having a hidden command that would dump the english CSV. I've seen similar methods used to register commands with a central list, using global variables. It might look something like this:
class TrString
{
public:
static std::set< std::wstring > sEnglishPhrases;
TrString( std::wstring english_phrase ) { sEnglishPhrases.insert( english_phrase ); }
};
#define TR(x) do {static TrString trstr(x);} while( false ); (lookupTranslatedString( currentLocale(), x ));
I know there's two problems with the above code. I doubt it compiles, but more importantly, in order to generate a list of all english phrases, I'd need to hit every single code path before accessing sEnglishPhrases.
It looks like I'll end up writing a small parser to read through all my code and look for TR strings, which isn't really that tough. I was just hoping to learn a little more about C++, and if there's a better way to do this.