jed-users mailing list

[2006 Date Index] [2006 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Next coup: Menus in foreign languages


Jörg Sommer <joerg@xxxxxxxxxxxx> wrote:
> Hi,
>
> I found a really nice way to translate the menus without changing the
> code. The trick is: I reimplement the menu_* functions to translate the
> entries. This way I could set up the menus in German. Download the files
>   http://www.minet.uni-jena.de/~joergs/jjm/menus_trans.sl and
>   http://www.minet.uni-jena.de/~joergs/jjm/menus_de.sl
> and run ()=evalfile("menus_de");
>
> Unfortunately, Jed does not support non-ascii characters in menus. Due to
> this the menus looks mangled.

Here is a fix for it.

#v+
Index: menu.c
===================================================================
--- menu.c	(Revision 35)
+++ menu.c	(Arbeitskopie)
@@ -968,41 +968,39 @@
 
 static void draw_name (char *name, int color0, int color1, unsigned int field_width)
 {
-   char *s;
-   unsigned int n;
+   const size_t name_len = strlen(name);
+   SLuchar_Type *s = name, *next_s;
+   SLuchar_Type * const name_end = name + name_len;
 
-   s = name;
+   while (s != name_end && (*s != '&'))
+     s = SLutf8_skip_char(s, name_end);
 
-   while (*s && (*s != '&'))
-     s++;
+    SLsmg_set_color (color0);
+    if (s == name_end)
+    {
+        if (field_width < name_len)
+          SLsmg_write_string(name);
+        else
+          SLsmg_write_nstring(name, field_width);
 
-   n = (unsigned int) (s - name);
-   if (n)
-     {
-	SLsmg_set_color (color0);
-	SLsmg_write_nchars (name, n);
-     }
+        return;
+    }
 
-   if (*s != 0)
-     {
-	unsigned int dn;
+    SLsmg_write_chars (name, s);
+    SLsmg_set_color (color1);
 
-	s++;
-	SLsmg_set_color (color1);
-	SLsmg_write_nchars (s, 1);
-	n++;
-	SLsmg_set_color (color0);
-	if (*s != 0)
-	  {
-	     s++;
-	     dn = strlen (s);
-	     SLsmg_write_nchars (s, dn);
-	     n += dn;
-	  }
-     }
+    ++s;            /* skip the ampersand */
+    next_s = SLutf8_skip_char(s, name_end);
+    SLsmg_write_chars (s, next_s);
+    SLsmg_set_color (color0);
 
-   if (n < field_width)
-     SLsmg_write_nstring ("", field_width - n);
+    if (field_width < name_len)
+      SLsmg_write_string(next_s);
+    else
+    {
+        field_width -= (SLutf8_strlen(name, 0)-1) - SLutf8_strlen(next_s, 0);
+        SLsmg_write_nstring(next_s, field_width);
+    }
 }
 
 	  
#v-

Bye, Jörg.
-- 
Es liegt in der Natur des Menschen, vernünftig zu denken und
unlogisch zu handeln! Das Gesagte ist nicht das Gemeinte und das Gehörte
nicht das Verstandene!

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2006 date index] [2006 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]