|
|
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.stringswill produce the following output in prog.strings:
prog.c:9:8:::Choose (y/n) prog.c:11:8:::yes prog.c:13:8:::noThe 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.cwill 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 16char 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(1), exstr(1), srchtxt(1) and gettxt(3C) manual pages.