Common Desktop Environment: Internationalization Programmer's Guide

XPG4 Messaging Examples

There are three parts to this example which demonstrates how to retrieve a message from a catalog. The first part shows the message source file and the second part shows the method used to generate the catalog file. The third part shows an example program using this catalog.

Message Source File

The message catalog can be specified as follows:

example.msg file:
$quote "  
$ every message catalog should have a beginning set number.
$set 1 This is the set 1 of messages  
1 "Hello world\n"  
2 "Good Morning\n"  
3 "example: 1000.220 Read permission is denied for the file  
%s.\n"  
$set 2  
1 "Howdy\n"
Generation of Catalog File

This file is input to the gencat utility to generate the message catalog example.cat as follows:

gencat example example.msg
Accessing the Catalog in a Program
#include <locale.h>  
#include <nl_types.h>  
char *MF_EXAMPLE = "example.cat"   

main()  
{
  		nl_catd catd;
  		int error;

 		(void)setlocale(LC_ALL, "");

   	catd = catopen(MF_EXAMPLE, 0);
 			/* Get the message number 1 from the first set.*/

   	printf( catgets(catd,1,1,"Hello world\n") );
  			/* Get the message number 1 from the second set.*/

   	printf( catgets(catd, 2, 1,"Howdy\n") );
  			/* Display an error message.*/

   	printf( catgets(catd, 1, 4,"example: 100.220
  			Permission is denied to read the file %s.\n") ,
  			MF_EXAMPLE);
  		catclose(catd);  
}