Locale

From Amiga Development Wiki
Jump to: navigation, search

Using localized strings

First generate a catalog descriptor file i.e. myapp.cd:

MSG_SAMPLE_TEXT (//)
This is a sample text.
;

Then convert descriptor file to a catalog translation and header files.

catcomp.pl --no-code --no-array --no-array-ids --no-block --cd myapp.cd --cfile myapp.h --blank-translation myapp.ct

Now you can localize strings with the help of catalogs and GetCatalogStr():

#include <proto/dos.h>
#include <proto/locale.h>
 
#include "myapp.h"
 
int main()
{
   struct Catalog *cat = OpenCatalog(NULL, "myapp.catalog", OC_BuiltInLanguage, "english", TAG_DONE);
   CONST_STRPTR s;
 
   s = GetCatalogStr(cat, MSG_SAMPLE_TEXT, MSG_SAMPLE_TEXT_STR);
   Printf("The text is:\n%s\n", s);
 
   CloseCatalog(cat);
 
   return 0;
}