I18N didn't work right for menus - the messages numbers were wrong.

Added new "msgnum()" method to Fl_Type to handle computing the message
number on the fly.

Now initialize nl_catd and locale settings directly in the static
variables so that menu labels are correctly looked up. This hack shouldn't
be necessary in 2.0...


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1124 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet 2000-05-16 12:26:07 +00:00
parent 3f177d70de
commit 74198871a6
16 changed files with 83 additions and 64 deletions

View File

@ -1,9 +1,9 @@
//
// "$Id: Fl_Function_Type.cxx,v 1.15.2.13 2000/04/25 01:57:48 mike Exp $"
// "$Id: Fl_Function_Type.cxx,v 1.15.2.14 2000/05/16 12:26:02 mike Exp $"
//
// C function type code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -269,11 +269,6 @@ void Fl_Function_Type::write_code1() {
}
if (havewidgets) write_c(" %s* w;\n",subclassname(child));
indentation += 2;
if (i18n_type == 2 && !i18n_file[0])
// Initialize _catalog as needed...
write_c(" if (_catalog == (nl_catd)-1) _catalog = catopen(\"%s\", 0);\n",
i18n_program);
}
void Fl_Function_Type::write_code2() {
@ -677,5 +672,5 @@ void Fl_Class_Type::write_code2() {
}
//
// End of "$Id: Fl_Function_Type.cxx,v 1.15.2.13 2000/04/25 01:57:48 mike Exp $".
// End of "$Id: Fl_Function_Type.cxx,v 1.15.2.14 2000/05/16 12:26:02 mike Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Group_Type.cxx,v 1.4.2.3 1999/08/05 09:01:24 bill Exp $"
// "$Id: Fl_Group_Type.cxx,v 1.4.2.4 2000/05/16 12:26:02 mike Exp $"
//
// Fl_Group object code for the Fast Light Tool Kit (FLTK).
//
@ -7,7 +7,7 @@
// the Fl_Tabs widget, with special stuff to select tab items and
// insure that only one is visible.
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -231,5 +231,5 @@ const char tile_type_name[] = "Fl_Tile";
Fl_Tile_Type Fl_Tile_type; // the "factory"
//
// End of "$Id: Fl_Group_Type.cxx,v 1.4.2.3 1999/08/05 09:01:24 bill Exp $".
// End of "$Id: Fl_Group_Type.cxx,v 1.4.2.4 2000/05/16 12:26:02 mike Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Menu_Type.cxx,v 1.16.2.7 2000/04/25 01:57:49 mike Exp $"
// "$Id: Fl_Menu_Type.cxx,v 1.16.2.8 2000/05/16 12:26:03 mike Exp $"
//
// Menu item code for the Fast Light Tool Kit (FLTK).
//
@ -9,7 +9,7 @@
// This file also contains code to make Fl_Menu_Button, Fl_Menu_Bar,
// etc widgets.
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -47,7 +47,6 @@ Fl_Menu_Item menu_item_type_menu[] = {
extern int reading_file;
extern int force_parent;
extern int msgnum;
extern int i18n_type;
extern const char* i18n_include;
extern const char* i18n_function;
@ -228,7 +227,7 @@ void Fl_Menu_Item_Type::write_item() {
break;
case 2 : /* POSIX catgets */
write_c("catgets(%s,%s,%d,", i18n_file[0] ? i18n_file : "_catalog",
i18n_set, msgnum ++);
i18n_set, msgnum());
write_cstring(label());
write_c(")");
break;
@ -463,5 +462,5 @@ void shortcut_in_cb(Shortcut_Button* i, void* v) {
}
//
// End of "$Id: Fl_Menu_Type.cxx,v 1.16.2.7 2000/04/25 01:57:49 mike Exp $".
// End of "$Id: Fl_Menu_Type.cxx,v 1.16.2.8 2000/05/16 12:26:03 mike Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Type.cxx,v 1.6.2.1 1999/03/13 20:07:19 bill Exp $"
// "$Id: Fl_Type.cxx,v 1.6.2.2 2000/05/16 12:26:03 mike Exp $"
//
// Widget type code for the Fast Light Tool Kit (FLTK).
//
@ -15,7 +15,7 @@
// not in the linked list and are not written to files or
// copied or otherwise examined.
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -387,6 +387,23 @@ void Fl_Type::insert(Fl_Type *g) {
widget_browser->redraw();
}
// Return message number for I18N...
int
Fl_Type::msgnum() {
int count;
Fl_Type *p;
for (count = 0, p = this; p;) {
if (p->is_widget() && p->label() && !((Fl_Widget_Type *)p)->image) count ++;
if (p->prev) p = p->prev;
else p = p->parent;
}
return count;
}
// delete from parent:
Fl_Type *Fl_Type::remove() {
Fl_Type *end = this;
@ -648,5 +665,5 @@ void Fl_Type::read_property(const char *c) {
int Fl_Type::read_fdesign(const char*, const char*) {return 0;}
//
// End of "$Id: Fl_Type.cxx,v 1.6.2.1 1999/03/13 20:07:19 bill Exp $".
// End of "$Id: Fl_Type.cxx,v 1.6.2.2 2000/05/16 12:26:03 mike Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Type.h,v 1.5.2.7 2000/04/24 18:22:47 mike Exp $"
// "$Id: Fl_Type.h,v 1.5.2.8 2000/05/16 12:26:03 mike Exp $"
//
// Widget type header file for the Fast Light Tool Kit (FLTK).
//
@ -11,7 +11,7 @@
// instance of this object. It could also have a "copy()" function,
// but it was easier to implement this by using the file read/write
// that is needed to save the setup anyways.
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -110,6 +110,9 @@ public:
virtual void write_code1(); // code and .h before children
virtual void write_code2(); // code and .h after children
// get message number for I18N
int msgnum();
// fake rtti:
virtual int is_parent() const;
virtual int is_widget() const;
@ -529,5 +532,5 @@ int storestring(const char *n, const char * & p, int nostrip=0);
extern int include_H_from_C;
//
// End of "$Id: Fl_Type.h,v 1.5.2.7 2000/04/24 18:22:47 mike Exp $".
// End of "$Id: Fl_Type.h,v 1.5.2.8 2000/05/16 12:26:03 mike Exp $".
//

View File

@ -1,9 +1,9 @@
//
// "$Id: Fl_Widget_Type.cxx,v 1.15.2.12 2000/04/25 01:57:49 mike Exp $"
// "$Id: Fl_Widget_Type.cxx,v 1.15.2.13 2000/05/16 12:26:03 mike Exp $"
//
// Widget type code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -46,7 +46,6 @@ extern int reading_file;
int force_parent;
extern int gridx;
extern int gridy;
extern int msgnum;
extern int i18n_type;
extern const char* i18n_include;
extern const char* i18n_function;
@ -1351,7 +1350,7 @@ void Fl_Widget_Type::write_code1() {
break;
case 2 : /* POSIX catgets */
write_c("catgets(%s,%s,%d,", i18n_file[0] ? i18n_file : "_catalog",
i18n_set, msgnum ++);
i18n_set, msgnum());
write_cstring(label());
write_c(")");
break;
@ -1769,5 +1768,5 @@ int Fl_Widget_Type::read_fdesign(const char* name, const char* value) {
}
//
// End of "$Id: Fl_Widget_Type.cxx,v 1.15.2.12 2000/04/25 01:57:49 mike Exp $".
// End of "$Id: Fl_Widget_Type.cxx,v 1.15.2.13 2000/05/16 12:26:03 mike Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Widget_Type.h,v 1.4.2.1 1999/03/29 17:39:26 carl Exp $"
// "$Id: Fl_Widget_Type.h,v 1.4.2.2 2000/05/16 12:26:05 mike Exp $"
//
// Widget type header file for the Fast Light Tool Kit (FLTK).
//
@ -7,7 +7,7 @@
// This should have the widget pointer in it, but it is still in the
// Fl_Type base class.
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -36,5 +36,5 @@ void* const LOAD = (void *)9831;
extern Fl_Widget_Type *current_widget; // one of the selected ones
//
// End of "$Id: Fl_Widget_Type.h,v 1.4.2.1 1999/03/29 17:39:26 carl Exp $".
// End of "$Id: Fl_Widget_Type.h,v 1.4.2.2 2000/05/16 12:26:05 mike Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Window_Type.cxx,v 1.13.2.6 2000/04/25 01:57:50 mike Exp $"
// "$Id: Fl_Window_Type.cxx,v 1.13.2.7 2000/05/16 12:26:05 mike Exp $"
//
// Window type code for the Fast Light Tool Kit (FLTK).
//
@ -7,7 +7,7 @@
// for interacting with the overlay, which allows the user to
// select, move, and resize the children widgets.
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -752,5 +752,5 @@ int Fl_Window_Type::read_fdesign(const char* name, const char* value) {
}
//
// End of "$Id: Fl_Window_Type.cxx,v 1.13.2.6 2000/04/25 01:57:50 mike Exp $".
// End of "$Id: Fl_Window_Type.cxx,v 1.13.2.7 2000/05/16 12:26:05 mike Exp $".
//

View File

@ -1,9 +1,9 @@
//
// "$Id: Fluid_Image.cxx,v 1.7.2.1 1999/07/31 08:00:08 bill Exp $"
// "$Id: Fluid_Image.cxx,v 1.7.2.2 2000/05/16 12:26:05 mike Exp $"
//
// Pixmap label support for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -417,5 +417,5 @@ Fluid_Image *ui_find_image(const char *oldname) {
}
//
// End of "$Id: Fluid_Image.cxx,v 1.7.2.1 1999/07/31 08:00:08 bill Exp $".
// End of "$Id: Fluid_Image.cxx,v 1.7.2.2 2000/05/16 12:26:05 mike Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fluid_Image.h,v 1.3.2.1 1999/03/29 17:39:26 carl Exp $"
// "$Id: Fluid_Image.h,v 1.3.2.2 2000/05/16 12:26:05 mike Exp $"
//
// Pixmap image header file for the Fast Light Tool Kit (FLTK).
//
@ -9,7 +9,7 @@
// in Fluid_Image.C for each type of image format. Right now only xpm
// files are supported.
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -56,5 +56,5 @@ Fluid_Image *ui_find_image(const char *);
#endif
//
// End of "$Id: Fluid_Image.h,v 1.3.2.1 1999/03/29 17:39:26 carl Exp $".
// End of "$Id: Fluid_Image.h,v 1.3.2.2 2000/05/16 12:26:05 mike Exp $".
//

View File

@ -1,9 +1,9 @@
//
// "$Id: Shortcut_Button.h,v 1.3 1999/01/07 19:17:12 mike Exp $"
// "$Id: Shortcut_Button.h,v 1.3.2.1 2000/05/16 12:26:05 mike Exp $"
//
// Shortcut header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -35,5 +35,5 @@ public:
};
//
// End of "$Id: Shortcut_Button.h,v 1.3 1999/01/07 19:17:12 mike Exp $".
// End of "$Id: Shortcut_Button.h,v 1.3.2.1 2000/05/16 12:26:05 mike Exp $".
//

View File

@ -1,9 +1,9 @@
//
// "$Id: code.cxx,v 1.9.2.5 2000/04/25 01:57:51 mike Exp $"
// "$Id: code.cxx,v 1.9.2.6 2000/05/16 12:26:06 mike Exp $"
//
// Code output routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -35,7 +35,8 @@
static FILE *code_file;
static FILE *header_file;
int msgnum;
extern char i18n_program[];
extern int i18n_type;
extern const char* i18n_include;
extern const char* i18n_function;
@ -293,12 +294,17 @@ int write_code(const char *s, const char *t) {
write_c("#include %s\n", i18n_include);
if (i18n_type == 2) {
if (i18n_file[0]) write_c("extern nl_catd %s;\n", i18n_file);
else write_c("static nl_catd _catalog = (nl_catd)-1;\n");
else {
write_c("// Initialize I18N stuff now for menus...\n");
write_c("#include <locale.h>\n");
write_c("static char *_locale = setlocale(LC_MESSAGES, \"\");\n");
write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n",
i18n_program);
}
}
}
if (t && include_H_from_C)
write_c("#include \"%s\"\n", filename_name(t));
msgnum = 1;
for (Fl_Type* p = Fl_Type::first; p;) {
// write all static data for this & all children first
p->write_static();
@ -322,6 +328,7 @@ int write_code(const char *s, const char *t) {
int write_strings(const char *sfile) {
FILE *fp = fopen(sfile, "w");
Fl_Type *p;
int i;
if (!fp) return 1;
@ -366,15 +373,14 @@ int write_strings(const char *sfile) {
}
break;
case 2 : /* POSIX catgets, put a .msg file out */
msgnum = 1;
fprintf(fp, "$ generated by Fast Light User Interface Designer (fluid) version %.4f\n",
FL_VERSION);
fprintf(fp, "$set %s\n", i18n_set);
fputs("$quote \"\n", fp);
for (p = Fl_Type::first; p; p = p->next) {
for (i = 1, p = Fl_Type::first; p; p = p->next) {
if (p->is_widget() && p->label() && !((Fl_Widget_Type *)p)->image) {
fprintf(fp, "%d \"", msgnum ++);
fprintf(fp, "%d \"", i ++);
for (const char *s = p->label(); *s; s ++)
if (*s < 32 || *s > 126 || *s == '\"')
fprintf(fp, "\\%03o", *s);
@ -399,5 +405,5 @@ void Fl_Type::write_code1() {
void Fl_Type::write_code2() {}
//
// End of "$Id: code.cxx,v 1.9.2.5 2000/04/25 01:57:51 mike Exp $".
// End of "$Id: code.cxx,v 1.9.2.6 2000/05/16 12:26:06 mike Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: factory.cxx,v 1.4.2.4 1999/11/20 09:17:20 bill Exp $"
// "$Id: factory.cxx,v 1.4.2.5 2000/05/16 12:26:06 mike Exp $"
//
// Widget factory code for the Fast Light Tool Kit (FLTK).
//
@ -11,7 +11,7 @@
// to a factory instance for every class (both the ones defined
// here and ones in other files)
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -693,5 +693,5 @@ int lookup_symbol(const char *name, int &v, int numberok) {
}
//
// End of "$Id: factory.cxx,v 1.4.2.4 1999/11/20 09:17:20 bill Exp $".
// End of "$Id: factory.cxx,v 1.4.2.5 2000/05/16 12:26:06 mike Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: file.cxx,v 1.7.2.3 2000/04/25 01:57:51 mike Exp $"
// "$Id: file.cxx,v 1.7.2.4 2000/05/16 12:26:06 mike Exp $"
//
// Fluid file routines for the Fast Light Tool Kit (FLTK).
//
@ -8,7 +8,7 @@
// They are somewhat similar to tcl, using matching { and }
// to quote strings.
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -639,5 +639,5 @@ void read_fdesign() {
}
//
// End of "$Id: file.cxx,v 1.7.2.3 2000/04/25 01:57:51 mike Exp $".
// End of "$Id: file.cxx,v 1.7.2.4 2000/05/16 12:26:06 mike Exp $".
//

View File

@ -1,9 +1,9 @@
//
// "$Id: fluid.cxx,v 1.15.2.5 2000/04/25 01:57:51 mike Exp $"
// "$Id: fluid.cxx,v 1.15.2.6 2000/05/16 12:26:06 mike Exp $"
//
// FLUID main entry for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -25,7 +25,7 @@
const char *copyright =
"The FLTK user interface designer version 1.0\n"
"Copyright 1998-1999 by Bill Spitzak and others.\n"
"Copyright 1998-2000 by Bill Spitzak and others.\n"
"\n"
"This library is free software; you can redistribute it and/or "
"modify it under the terms of the GNU Library General Public "
@ -460,5 +460,5 @@ int main(int argc,char **argv) {
}
//
// End of "$Id: fluid.cxx,v 1.15.2.5 2000/04/25 01:57:51 mike Exp $".
// End of "$Id: fluid.cxx,v 1.15.2.6 2000/05/16 12:26:06 mike Exp $".
//

View File

@ -1,9 +1,9 @@
//
// "$Id: gif.cxx,v 1.3 1999/01/07 19:17:14 mike Exp $"
// "$Id: gif.cxx,v 1.3.2.1 2000/05/16 12:26:07 mike Exp $"
//
// GIF support for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-1999 by Bill Spitzak and others.
// Copyright 1998-2000 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@ -359,5 +359,5 @@ int gif2xpm(
}
//
// End of "$Id: gif.cxx,v 1.3 1999/01/07 19:17:14 mike Exp $".
// End of "$Id: gif.cxx,v 1.3.2.1 2000/05/16 12:26:07 mike Exp $".
//