So, I am working on translating my C ++ application into several languages. I am currently using something like:
#define TR(x) (lookupTranslatedString( currentLocale(), x )) wcout << TR(L"This phrase is in English") << endl;
Translation is carried out from a CSV file that maps the English string to the translated string.
"This phrase is in English","Nasa Tagalog itong pagsabi"
This is simplified, but the main idea.
My question is about creating a list of English phrases to translate. I just need a CSV with all English phrases and empty translated phrases. I was hoping that it might be possible to generate this list at compile time or at runtime. In compiletime, I thought something like this:
#define TR(x) \ #warning x \ (lookupTranslatedString( currentLocale(), x ))
and then maybe analyze the compilation log or something else. It doesn't seem so good.
Runtime will also be great. I only thought about starting the application and had a hidden command that would reset the CSV. I have 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 two problems with the above code. I doubt that it compiles, but more importantly, to create a list of all English phrases, I would have to hit every path of the code before accessing sEnglishPhrases.
It looks like I'll write a small parser to read all my code and look for TR lines, which is actually not that difficult. I was just hoping to learn a little more about C ++, and if there is a better way to do this.