DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Internationalization

exstr and srchtxt (OS-specific)

Once you have created the message files for the different locales, you can use the exstr command to extract the strings from the original source code and replace them with calls to gettxt. If the name of the source file is prog.c, the command

   $ exstr -e prog.c > prog.strings
will produce the following output in prog.strings:
   prog.c:9:8:::Choose (y/n)
   prog.c:11:8:::yes
   prog.c:13:8:::no
The first three fields in each entry are the file name, the line number in which the string appears in the file, and the character position of the string in the line. You fill in the next two fields with the name of the message file and the index of the string in the file:
   prog.c:9:8:progmsgs:1:Choose (y/n)
   prog.c:11:8:progmsgs:2:yes
   prog.c:13:8:progmsgs:3:no

Now the command

   $ exstr -rd prog.c < prog.strings > intl.c
will produce in intl.c
#include <stdio.h>

extern char *gettxt(); main() { int yes();

while(1) { puts(gettxt("progmsgs:1", "Choose (y/n)")); if (yes()) puts(gettxt("progmsgs:2", "yes")); else puts(gettxt("progmsgs:3", "no")); } }

static int yes() { int i, b;

i = b = getchar(); while (b != '\n' && b != '\0' && b != EOF) b = getchar(); return(i == 'y'); }

The completed source code would look like this:

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <locale.h>
#define RESPLEN 16

char yesstr[RESPLEN]; /* assumed to be long enough */ extern char *gettxt(); main() { int yes();

setlocale(LC_ALL, "");

/* save local yes string for subsequent comparisons */ strcpy(yesstr, gettxt("progmsgs:2", "yes"));

while(1) { puts(gettxt("progmsgs:1", "Choose (y/n)")); if (yes()) puts(yesstr); else puts(gettxt("progmsgs:3", "no")); } }

static int yes() { int i, b;

i = b = getchar(); while (b != '\n' && b != '\0' && b != EOF) b = getchar(); return(i == (int) yesstr[0]); }

The srchtxt command lets you display or search for text strings in message files installed in a given locale. Among other ways, you might want to use it to see how other programs have translated messages similar to yours. See the mkmsgs(CP), exstr(CP), srchtxt(CP) and gettxt(S) manual pages.


Next topic: catopen and catclose (X/Open)
Previous topic: mkmsgs and gettxt (OS-specific)

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005