Re: XForms: Multiple Languages

Jacques Tremblay (jackt@gel.ulaval.ca)
Thu, 13 Nov 1997 15:49:50 -0500 (EST)

To subscribers of the xforms list from Jacques Tremblay <jackt@gel.ulaval.ca> :

>> Hi all
>>
>> I have a couple of questions about international applications.
>>
>> 1. I am writing a program that must be released in spanish, german and
>> english. I have RTFM and found nothing about this subject. I have decided
>> to create 3 different fd files, which generate three (or better 6)
>> different.h and .c files. All the magic is in the Makefile which chooses
>> the correct files by only setting a LANGUAGE= macro. For hardcoded strings
>> I use another mechanism which has nothing to do with XForms. I found that
>> the only way to use fdesign for my dialogs in different languages without
>> turning myself nuts was to separate them (of course, all forms have the
>> same name, callbacks, etc). It works fine and I have 3 different
>> applications.
>> My question is: does somebody have a better way to do this? (using C, not
>> C++). Thank you all.
>>
>> 2. About fdesign. As you know, spanish and german use a lot of compound
>> characters (a,`,D,v). I can not use this characters in fdesign. Is there
>> any fix for that? is it a fdesign problem or a (miss)configuration of my
>> SGI Irix 6.2 machine. Hardcoded strings with this characters show perfectly
>> well on forms. It's simply that I can not type them on a form (neither
>> forms or fdesign).
>>

Here is a simple way to do it:

start fdesign with -I headerName option.

i.e.

fdesign -I MyFormHeader.h

MyFormHeader.h will contain every string you need as a macro.

i.e.

#include "forms.h"

#ifdef LANGUAGE_ENGLISH

#define LOAD_BUTTON "Load"
#define SAVE_AS_BUTTON "Save as ..."

#else /* French */

#define LOAD_BUTTON "Charger ..."
#define SAVE_AS_BUTTON "Sauvegarder sous..."

#endif

///////////////////////////////////

Then, in your forms, use the macros you have
defined for your strings surrounded by the #
character. i.e. #LOAD_BUTTON#

In the file generated by fdesign, the labels will
look like: "#LOAD_BUTTON#".

Then, you only have to perform a perl search and replace
operation on the .c file generated by fdesign.

perl -pi.bak -e 's/"#([^#]+)#"/$1/' the_file.c

This will replace every string "#TEXT#" by TEXT.

/////////////////////////////////////////////////

You could do something better... Instead of using a macro, you could
have the strings in a table:

#include "forms.h"

#define ENGLISH 0
#define FRENCH 1
#define ITALIAN 2

extern int selectedLanguage;

typedef struct {
char *name;
char *table[3];
} tableEntry;

tableEntry strings[] = {
{ "BUTTON_ONE", "Button 1", "Bouton 1", "???"},
{ 0, 0, 0, 0}
}

char *LabelInSelectedLanguage(char *name);

//////////////////////////////////////////////

The perl script would be then:

perl -pi.bak -e 's/"#([^#]+)#"/LabelInSelectedLanguage("$1")/' the_file.c

With the example above, a typical button creation would look like:

obj = fl_add_button(FL_NORMAL_BUTTON,50,50,130,100,LabelInSelectedLanguage("BUTTON_ONE"));

The LabelInSelectedLanguage function is easy to do, it just compares the name
with everything in the table until it finds it then, it returns the tableEntry
corresponding to the language. In the main, the variable selectedLanguage
should be initialized before calling the form initialization.

Hope this helps...

Jacques

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/