ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Silly question about localizing C/C++ applications

<< < (2/2)

Eóin:
The the native MS approach is indeed resource DLLs as vlastimil suggests though the recommended way to use them is through Microsoft Multilingual User (MUI). I personally found this example, Hello MUI, great for getting up to speed with the API.

The FSF guys have long used gettext as mouser mentioned. Recently Boost added a localisation library, Boost.Locale, to their ever expanding collection. I haven't yet had a chance to use it, but looks neat. It seems to build on both gettext and ICU.

Some C++ apps come with language files that look like this:


--- ---HELLOWORLD "Hello, World!"
I'm curious: how is this loaded and interpreted? Is HELLOWORLD a string literal, and you have a long list of conditionals such as  "if id equals "HELLOWORLD" then sHelloWorld = id, else if..."? (That would be quite slow and it's one of the things I'm trying to avoid in Delphi.) Or do these strings map to numeric values somehow? Or something else yet?

Silly question!
-tranglos (January 03, 2012, 12:38 PM)
--- End quote ---


Nope not silly, my guess is that the file is loaded into an associative array of some kind. In C++ that could be as simple as an STL std::map<std::string, std::string> container.

tranglos:
Nope not silly, my guess is that the file is loaded into an associative array of some kind. In C++ that could be as simple as an STL std::map<std::string, std::string> container.-Eóin (January 03, 2012, 03:26 PM)
--- End quote ---

Thanks, Eóin! A hash table totally makes sense, it's on the top of my choices right now as well.

I'm trying hard to figure out a way to do this in Delphi so that it is convenient both for the users of my apps and for myself. I've done that once before, an entirely home-made localization mechanism, still running in my password manager Oubliette. Now I need to update it for Unicode, but I'm trying to design something better. It's such a pain to write code when instead of saying


--- ---showmessage( 'This is a test' );
I have to say


--- ---showmessage( translate( msgThisIsaTest ));
...and always remember to add somewhere else


--- ---resourcestring
  msgThisIsaTest = 'This is a test';
...and repeat it hundreds of times.

GetText wins here, because it does not require adding these identifiers all over the place; it works directly with string literals. But, apart from my earlier comments, I'd rather not use compiled language files, since they're a nuisance. Though I am considering it as well.

tranglos:
There always are resource DLLs. I believe Microsoft still recommends them. They contain string tables (numeric_id=>"string value") and also dialog resources (allowing you to rearrange controls if they do not fit). You can have multiple different translations for the same phrase and you can have larger labels on dialogs if they are needed in a translation, you can have even different pictures or accelerator tables. Accessing the resources is fast. It all works perfectly - on the paper.-vlastimil (January 03, 2012, 02:26 PM)
--- End quote ---

Resource DLLs are the built-in solution in Delphi as well, but they workflow they require is quite impossible for a one-person freeware shop. Send text to translator, get it back, compile, send back for testing, recompile... Whatever design I settle on, it will have plain text Unicode language files that anyone can edit freely.

Thanks for all the thoughts and pointers, everyone!

Navigation

[0] Message Index

[*] Previous page

Go to full version