DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2861
Version: 1.3-feature


The code as in fluid-1.3 now uses dynamic i18n within a class constructor
or function call. However implemented approach does not allow automatic
extraction of translated strings to .po files.

Attached patch fixes that as it allows definition of a name of
"no-operation" macro, which can then indicate translated strings. For
instance by defining this macro as NOOP (in the i18n dialog), following
code is added after inclusion of i18n header:

#ifndef NOOP
  #define NOOP(s) s
#endif

and menus are generated as

Fl_Menu_Item menu[] = {
 {NOOP("Item 1"), ... }
 0
};

Note that this addition allows also "static initialization" if the macro
is defined (i.e. in i18n header) as actually calling the translation
function. In such a case the user should also define
macro FL_USE_STATIC_I18N, in which case the "dynamic" translation is
commented out by a preprocessor macro.

To me translation during static initialization is preferable and 1.1
produced simple yet valid and fast i18n code. I believe that the
initialization fiasco problems arise for people initializing gettext in
the beginning of main(), which is too late. The proper solution is
wrapping this initialization at the first use of translation function,
then it should work fine.


Link: http://www.fltk.org/str.php?L2861
Version: 1.3-feature
Index: fluid/alignment_panel.fl
===================================================================
--- fluid/alignment_panel.fl    (revision 9635)
+++ fluid/alignment_panel.fl    (working copy)
@@ -58,7 +58,8 @@
 decl {Fl_Text_Buffer *shell_run_buffer;} {public local
 } 
 
-Function {make_project_window()} {} {
+Function {make_project_window()} {open
+} {
   Fl_Window project_window {
     label {Project Settings} open
     xywh {393 460 399 252} type Double
@@ -111,7 +112,7 @@
         Fl_Choice i18n_type_chooser {
           label {Use:}
           callback i18n_type_cb open
-          tooltip {Type of internationalization to use.} xywh {100 48 136 25} 
box THIN_UP_BOX down_box BORDER_BOX labelfont 1
+          tooltip {Type of internationalization to use.} xywh {115 48 136 25} 
box THIN_UP_BOX down_box BORDER_BOX labelfont 1
         } {
           MenuItem {} {
             label None
@@ -129,23 +130,28 @@
         Fl_Input i18n_include_input {
           label {\#include:}
           callback i18n_text_cb
-          tooltip {The include file for internationalization.} xywh {100 78 
272 20} box THIN_DOWN_BOX labelfont 1 textfont 4
+          tooltip {The include file for internationalization.} xywh {115 75 
257 23} box THIN_DOWN_BOX labelfont 1 textfont 4
         }
         Fl_Input i18n_file_input {
           label {File:}
           callback i18n_text_cb
-          tooltip {The name of the message catalog.} xywh {100 104 272 20} box 
THIN_DOWN_BOX labelfont 1 textfont 4
+          tooltip {The name of the message catalog.} xywh {115 104 257 20} box 
THIN_DOWN_BOX labelfont 1 textfont 4
         }
         Fl_Input i18n_set_input {
           label {Set:}
           callback i18n_int_cb
-          tooltip {The message set number.} xywh {100 128 272 20} type Int box 
THIN_DOWN_BOX labelfont 1 textfont 4
+          tooltip {The message set number.} xywh {115 128 257 20} type Int box 
THIN_DOWN_BOX labelfont 1 textfont 4
         }
         Fl_Input i18n_function_input {
           label {Function:}
           callback i18n_text_cb
-          tooltip {The function to call to internationalize the labels and 
tooltips.} xywh {100 103 272 20} box THIN_DOWN_BOX labelfont 1 textfont 4
+          tooltip {The function to call to internationalize the labels and 
tooltips.} xywh {115 103 257 20} box THIN_DOWN_BOX labelfont 1 textfont 4
         }
+        Fl_Input i18n_noopmacro_input {
+          label {No-op macro:}
+          callback i18n_text_cb selected
+          tooltip {Macro for no-operation  gettext extraction or static 
initialization} xywh {115 128 257 20} box THIN_DOWN_BOX labelfont 1 textfont 4
+        }
       }
     }
   }
@@ -160,7 +166,7 @@
 Function {make_settings_window()} {} {
   Fl_Window settings_window {
     label {GUI Settings} open
-    xywh {393 191 339 241} type Double non_modal visible
+    xywh {393 191 339 241} type Double hide non_modal
   } {
     Fl_Choice scheme_choice {
       label {Scheme: }
@@ -260,7 +266,7 @@
 Function {make_shell_window()} {} {
   Fl_Window shell_window {
     label {Shell Command} open
-    xywh {741 195 365 125} type Double visible
+    xywh {741 195 365 125} type Double hide
   } {
     Fl_Input shell_command_input {
       label {Command:}
@@ -325,7 +331,7 @@
 Function {make_layout_window()} {} {
   Fl_Window grid_window {
     label {Layout Settings} open
-    xywh {760 427 285 245} type Double non_modal visible
+    xywh {760 427 285 245} type Double hide non_modal
   } {
     Fl_Input horizontal_input {
       label x
@@ -508,14 +514,13 @@
        "ALL users on this machine.\\n\\n"
        "Please choose these settings carefully, or reset\\n"
        "user and system settings to \\"default\\".");
-global_settings_window->show();} {selected
-  }
+global_settings_window->show();} {}
 } 
 
 Function {make_global_settings_window()} {} {
   Fl_Window global_settings_window {
     label {FLTK Preferences} open
-    xywh {444 220 403 317} type Double color 50 visible
+    xywh {444 220 403 317} type Double color 50 hide
   } {
     Fl_Group {} {
       label {Keyboard Focus Options} open
Index: fluid/code.cxx
===================================================================
--- fluid/code.cxx      (revision 9635)
+++ fluid/code.cxx      (working copy)
@@ -32,6 +32,7 @@
 extern int i18n_type;
 extern const char* i18n_include;
 extern const char* i18n_function;
+extern const char* i18n_noopmacro;
 extern const char* i18n_file;
 extern const char* i18n_set;
 
@@ -403,7 +404,9 @@
         write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n",
                    i18n_program);
       }
-    }
+    }else if (*i18n_noopmacro)
+         write_c("\n#ifndef %s\n  #define %s(string) string\n#endif\n\n", 
i18n_noopmacro, i18n_noopmacro);
+       
   }
   if (t && include_H_from_C) {
     if (*header_file_name == '.' && strchr(header_file_name, '/') == NULL) {
Index: fluid/file.cxx
===================================================================
--- fluid/file.cxx      (revision 9635)
+++ fluid/file.cxx      (working copy)
@@ -299,6 +299,7 @@
 extern int i18n_type;
 extern const char* i18n_include;
 extern const char* i18n_function;
+extern const char* i18n_noopmacro;
 extern const char* i18n_file;
 extern const char* i18n_set;
 
@@ -322,6 +323,7 @@
     switch (i18n_type) {
     case 1 : /* GNU gettext */
        write_string("\ni18n_function %s", i18n_function);
+       write_string("\ni18n_noopmacro %s", i18n_noopmacro);
         break;
     case 2 : /* POSIX catgets */
         if (i18n_file[0]) write_string("\ni18n_file %s", i18n_file);
@@ -409,6 +411,10 @@
       i18n_function = strdup(read_word());
       goto CONTINUE;
     }
+       if (!strcmp(c,"i18n_noopmacro")) {
+      i18n_noopmacro = strdup(read_word());
+      goto CONTINUE;
+    }
     if (!strcmp(c,"i18n_file")) {
       i18n_file = strdup(read_word());
       goto CONTINUE;
Index: fluid/Fl_Function_Type.cxx
===================================================================
--- fluid/Fl_Function_Type.cxx  (revision 9635)
+++ fluid/Fl_Function_Type.cxx  (working copy)
@@ -29,6 +29,7 @@
 extern int i18n_type;
 extern const char* i18n_include;
 extern const char* i18n_function;
+extern const char* i18n_noopmacro;
 extern const char* i18n_file;
 extern const char* i18n_set;
 extern char i18n_program[];
Index: fluid/Fl_Menu_Type.cxx
===================================================================
--- fluid/Fl_Menu_Type.cxx      (revision 9635)
+++ fluid/Fl_Menu_Type.cxx      (working copy)
@@ -45,6 +45,7 @@
 extern int i18n_type;
 extern const char* i18n_include;
 extern const char* i18n_function;
+extern const char* i18n_noopmacro;
 extern const char* i18n_file;
 extern const char* i18n_set;
 
@@ -292,9 +293,16 @@
   };
 
   write_c(" {");
-  if (image) write_c("0");
-  else if (label()) write_cstring(label()); // we will call i18n when the 
widget is instantiated for the first time
-  else write_c("\"\"");
+  if (image)
+    write_c("0");
+  else if (label()){
+    if(*i18n_noopmacro)
+      write_c("%s(", i18n_noopmacro);
+    write_cstring(label()); // we will call i18n when the widget is 
instantiated for the first time
+    if(*i18n_noopmacro)
+      write_c(")");
+  } else
+    write_c("\"\"");
   if (((Fl_Button*)o)->shortcut()) {
                int s = ((Fl_Button*)o)->shortcut();
                if (use_FL_COMMAND && (s & (FL_CTRL|FL_META))) {
@@ -470,6 +478,8 @@
        nItem += 1 + ((thislevel > nextlevel) ? (thislevel-nextlevel) : 0);
       }
       if (nLabel) {
+        if(*i18n_noopmacro)
+         write_c("#ifndef FL_USE_STATIC_I18N\n");
         write_c("%sif (!%s_i18n_done) {\n", indent(), mName);
         write_c("%s  int i=0;\n", indent());
         write_c("%s  for ( ; i<%d; i++)\n", indent(), nItem);
@@ -487,6 +497,8 @@
         }
         write_c("%s  %s_i18n_done = 1;\n", indent(), mName);
         write_c("%s}\n", indent());
+       if(*i18n_noopmacro)
+         write_c("#endif\n");
       }
     }
     write_c("%s%s->menu(%s);\n", indent(), name() ? name() : "o",
Index: fluid/Fl_Widget_Type.cxx
===================================================================
--- fluid/Fl_Widget_Type.cxx    (revision 9635)
+++ fluid/Fl_Widget_Type.cxx    (working copy)
@@ -44,6 +44,7 @@
 extern int i18n_type;
 extern const char* i18n_include;
 extern const char* i18n_function;
+extern const char* i18n_noopmacro;
 extern const char* i18n_file;
 extern const char* i18n_set;
 
Index: fluid/Fl_Window_Type.cxx
===================================================================
--- fluid/Fl_Window_Type.cxx    (revision 9635)
+++ fluid/Fl_Window_Type.cxx    (working copy)
@@ -44,6 +44,7 @@
 extern int i18n_type;
 extern const char* i18n_include;
 extern const char* i18n_function;
+extern const char* i18n_noopmacro;
 extern const char* i18n_file;
 extern const char* i18n_set;
 
@@ -116,6 +117,13 @@
   fluid_prefs.set("widget_size", Fl_Widget_Type::default_size);
 }
 
+static const char * format_nooppacro(const char * m){
+  if(!m) return "";
+  while(isspace(*m))
+       m++;
+  if(*m) return m;
+  return "";  
+}
 
 void i18n_type_cb(Fl_Choice *c, void *) {
   undo_checkpoint();
@@ -126,16 +134,20 @@
       i18n_file_input->hide();
       i18n_set_input->hide();
       i18n_function_input->hide();
+         i18n_noopmacro_input->hide();
       break;
   case 1 : /* GNU gettext */
       i18n_include_input->value("<libintl.h>");
       i18n_include = i18n_include_input->value();
       i18n_function_input->value("gettext");
       i18n_function = i18n_function_input->value();
+         i18n_noopmacro_input->value("");
+         i18n_noopmacro = format_nooppacro(i18n_noopmacro_input->value());
       i18n_include_input->show();
       i18n_file_input->hide();
       i18n_set_input->hide();
       i18n_function_input->show();
+         i18n_noopmacro_input->show();
       break;
   case 2 : /* POSIX cat */
       i18n_include_input->value("<nl_types.h>");
@@ -148,6 +160,7 @@
       i18n_file_input->show();
       i18n_set_input->show();
       i18n_function_input->hide();
+         i18n_noopmacro_input->hide();
       break;
   }
 
@@ -163,6 +176,8 @@
     i18n_file = i->value();
   else if (i == i18n_include_input)
     i18n_include = i->value();
+  else if (i == i18n_noopmacro_input)
+    i18n_noopmacro = format_nooppacro(i18n_noopmacro_input->value());
   
   set_modflag(1);
 }
@@ -187,6 +202,7 @@
   code_file_input->value(code_file_name);
   i18n_type_chooser->value(i18n_type);
   i18n_function_input->value(i18n_function);
+  i18n_noopmacro_input->value(i18n_noopmacro);
   i18n_file_input->value(i18n_file);
   i18n_set_input->value(i18n_set);
   i18n_include_input->value(i18n_include);
@@ -196,18 +212,21 @@
       i18n_file_input->hide();
       i18n_set_input->hide();
       i18n_function_input->hide();
+         i18n_noopmacro_input->hide();
       break;
   case 1 : /* GNU gettext */
       i18n_include_input->show();
       i18n_file_input->hide();
       i18n_set_input->hide();
       i18n_function_input->show();
+         i18n_noopmacro_input->show();
       break;
   case 2 : /* POSIX cat */
       i18n_include_input->show();
       i18n_file_input->show();
       i18n_set_input->show();
       i18n_function_input->hide();
+         i18n_noopmacro_input->hide();
       break;
   }
   project_window->hotspot(project_window);
Index: fluid/fluid.cxx
===================================================================
--- fluid/fluid.cxx     (revision 9635)
+++ fluid/fluid.cxx     (working copy)
@@ -643,6 +643,7 @@
 int i18n_type = 0;
 const char* i18n_include = "";
 const char* i18n_function = "";
+const char* i18n_noopmacro = "";
 const char* i18n_file = "";
 const char* i18n_set = "";
 char i18n_program[FL_PATH_MAX] = "";
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to