Skip to contentSkip to conversation

gettextize normal/menu_text.c (print_timeout)

PATCH Carles Pina i Estany 3 participants 9 messages Nov 22, 2009 – Nov 26, 2009

lore
Share & tools
lore
#0 lore raw

Hello,

Attached a proposal of gettextize for normal/menu_text.c

------
2009-11-22 Carles Pina i Estany <[email protected]>

* normal/menu_text.c (get_spaces): New function. (print_timeout): Gettexttize and uses get_spaces.
------

If accepted I can combine with the previous patch gettextizing some files in normal/*

Cheers,

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info

=== modified file 'normal/menu_text.c'

menu_text.c +25 -3
@@ -262,12 +262,34 @@
   return entry;
 }
 
+static char*
+get_spaces (int number_spaces)
+{
+  char* spaces = grub_malloc(number_spaces + 1);
+  int i;
+
+  spaces[0] = '\0';
+  
+  for (i=0;i<number_spaces;i++)
+    {
+      grub_strcat(spaces, " ");
+    }
+  return spaces;
+}
+  
 static void
 print_timeout (int timeout, int offset, int second_stage)
 {
-  /* NOTE: Do not remove the trailing space characters.
-     They are required to clear the line.  */
-  char *msg = "   The highlighted entry will be booted automatically in %ds.    ";
+  const char *msg_localized = _("   The highlighted entry will be booted automatically in %ds.");
+  const int msg_localized_len = grub_strlen (msg_localized);
+  const int number_spaces = GRUB_TERM_WIDTH - msg_localized_len;
+  
+  char *msg = grub_malloc (msg_localized_len + number_spaces + 1);
+  char *spaces = get_spaces (number_spaces);
+
+  grub_sprintf (msg,"%s%s", msg_localized, spaces);
+  grub_free (spaces);
+
   char *msg_end = grub_strchr (msg, '%');
 
   grub_gotoxy (second_stage ? (msg_end - msg) : 0, GRUB_TERM_HEIGHT - 3);
#1 lore raw
Quoted 13 lines · Carles Pina i Estany

=== modified file 'normal/menu_text.c'

menu_text.c +6 -0
@@ -262,12 +262,34 @@
   return entry;
 }
 
+static char*
+get_spaces (int number_spaces)
+{
+  char* spaces = grub_malloc(number_spaces + 1);
+  int i;
+

menu_text.c line 290

Quoted 10 lines
menu_text.c +9 -0
+  spaces[0] = '\0';
+  
+  for (i=0;i<number_spaces;i++)
+    {
+      grub_strcat(spaces, " ");
+    }
+  return spaces;
+}
[...]
+  grub_sprintf (msg,"%s%s", msg_localized, spaces);

This could be made much simpler. For example:

void
print_spaces (int number_spaces)
{
int i;
for (i = 0; i < number_spaces; i++)

    grub_putchar (' ');
}

menu_text.c line 285

Quoted 3 lines
menu_text.c +3 -0
+  const char *msg_localized = _("   The highlighted entry will be booted automatically in %ds.");
+  const int msg_localized_len = grub_strlen (msg_localized);
+  const int number_spaces = GRUB_TERM_WIDTH - msg_localized_len;

Seems like the right approach. I wonder if we should do something about the preceding spaces too...

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#2 lore raw

Hi,

Quoted 6 lines

menu_text.c line 285

Quoted 3 lines
menu_text.c +3 -0
+  const char *msg_localized = _("   The highlighted entry will be booted automatically in %ds.");
+  const int msg_localized_len = grub_strlen (msg_localized);
+  const int number_spaces = GRUB_TERM_WIDTH - msg_localized_len;

Seems like the right approach. I wonder if we should do something about the preceding spaces too...

find attached a patch that gettextizes menu_text.c

Would be ok to apply? Any comments?

(Wed and Thu I will not have lot of time, but on Friday-weekend I hope to push more strings)

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info
#3 lore raw

Hi,

Quoted 11 lines · Carles Pina i Estany

Hi,

Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+  const char *msg_localized = _("   The highlighted entry will be booted automatically in %ds.");
+  const int msg_localized_len = grub_strlen (msg_localized);
+  const int number_spaces = GRUB_TERM_WIDTH - msg_localized_len;

Seems like the right approach. I wonder if we should do something about the preceding spaces too...

find attached a patch that gettextizes menu_text.c

now yes, attached

BTW, I left spaces on the left of lot of strings. In my opinion I would
delete it and call print_spaces(3);. Fine? (or call grub_printf (" ");
).

I removed the \n from the end of strings and used grub_putchar ('\n'); or grub_printf ("\n\n"); to not bother the translators and reuse the strings.

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info

=== modified file 'normal/menu_text.c'

menu_text.c +40 -16
@@ -39,7 +39,8 @@ static grub_uint8_t grub_color_menu_high
 void
 grub_wait_after_message (void)
 {
-  grub_printf ("\nPress any key to continue...");
+  grub_putchar('\n');
+  grub_printf (_("Press any key to continue..."));
   (void) grub_getkey ();
   grub_putchar ('\n');
 }
@@ -84,25 +85,31 @@ static void
 print_message (int nested, int edit)
 {
   grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
-
+  
+  grub_putchar ('\n');
   if (edit)
     {
-      grub_printf ("\n\
+      grub_printf (_("\
       Minimum Emacs-like screen editing is supported. TAB lists\n\
       completions. Press Ctrl-x to boot, Ctrl-c for a command-line\n\
-      or ESC to return menu.");
+      or ESC to return menu."));
     }
   else
     {
-      grub_printf (_("\n\
-      Use the %C and %C keys to select which entry is highlighted.\n"),
+      grub_printf (_("\
+      Use the %C and %C keys to select which entry is highlighted."),
 		   (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN);
-      grub_printf ("\
+      grub_putchar ('\n');
+
+      grub_printf (_("\
       Press enter to boot the selected OS, \'e\' to edit the\n\
-      commands before booting or \'c\' for a command-line.");
+      commands before booting or \'c\' for a command-line."));
       if (nested)
-	grub_printf ("\n\
-      ESC to return previous menu.");
+        {
+	  grub_putchar ('\n');
+	  grub_printf (_("\
+        ESC to return previous menu."));
+	}
     }
 }
 
@@ -263,15 +270,28 @@ get_entry_number (const char *name)
 }
 
 static void
+print_spaces (int number_spaces)
+{
+  int i;
+  for (i = 0; i < number_spaces; i++)
+    grub_putchar(' ');
+}
+
+static void
 print_timeout (int timeout, int offset, int second_stage)
 {
   /* NOTE: Do not remove the trailing space characters.
      They are required to clear the line.  */
-  char *msg = "   The highlighted entry will be booted automatically in %ds.    ";
+  const char *msg = _("   The highlighted entry will be booted automatically in %ds.");
+  const int msg_localized_len = grub_strlen (msg);
+  const int number_spaces = GRUB_TERM_WIDTH - msg_localized_len;
+  
   char *msg_end = grub_strchr (msg, '%');
 
   grub_gotoxy (second_stage ? (msg_end - msg) : 0, GRUB_TERM_HEIGHT - 3);
   grub_printf (second_stage ? msg_end : msg, timeout);
+  print_spaces (second_stage ? number_spaces : 0);
+
   grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
   grub_refresh ();
 };
@@ -360,8 +380,7 @@ run_menu (grub_menu_t menu, int nested, 
 	  if (timeout >= 0)
 	    {
 	      grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
-              grub_printf ("\
-                                                                        ");
+	      print_spaces (GRUB_TERM_WIDTH - 1);
 	      grub_env_unset ("timeout");
 	      grub_env_unset ("fallback");
 	      grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
@@ -517,7 +536,8 @@ static void
 notify_booting (grub_menu_entry_t entry,
 		void *userdata __attribute__((unused)))
 {
-  grub_printf ("  Booting \'%s\'\n\n", entry->title);
+  grub_printf (_("  Booting \'%s\'"), entry->title);
+  grub_printf ("\n\n");
 }
 
 /* Callback invoked when a default menu entry executed because of a timeout
@@ -527,7 +547,9 @@ static void
 notify_fallback (grub_menu_entry_t entry,
 		 void *userdata __attribute__((unused)))
 {
-  grub_printf ("\n  Falling back to \'%s\'\n\n", entry->title);
+  grub_putchar('\n');
+  grub_printf (_("  Falling back to \'%s\'"), entry->title);
+  grub_printf ("\n\n");
   grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS);
 }
 
@@ -541,7 +563,9 @@ notify_execution_failure (void *userdata
       grub_print_error ();
       grub_errno = GRUB_ERR_NONE;
     }
-  grub_printf ("\n  Failed to boot default entries.\n");
+  grub_putchar ('\n');
+  grub_printf (_("  Failed to boot default entries."));
+  grub_putchar ('\n');
   grub_wait_after_message ();
 }
 
#4 lore raw
Quoted 3 lines · Carles Pina i Estany

BTW, I left spaces on the left of lot of strings. In my opinion I would
delete it and call print_spaces(3);. Fine? (or call grub_printf (" ");
).

Yes.

menu_text.c static void · line 95

Quoted 6 lines
menu_text.c +2 -2
-      grub_printf ("\n\
+      grub_printf (_("\
       Minimum Emacs-like screen editing is supported. TAB lists\n\
       completions. Press Ctrl-x to boot, Ctrl-c for a command-line\n\
-      or ESC to return menu.");
+      or ESC to return menu."));

These are still not right. We can't have newlines in the middle of a translatable string.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#5 lore raw

Hi,

Quoted 6 lines · Robert Millan
Quoted 3 lines · Carles Pina i Estany

BTW, I left spaces on the left of lot of strings. In my opinion I would
delete it and call print_spaces(3);. Fine? (or call grub_printf (" ");
).

Yes.

ok!

Quoted 9 lines

menu_text.c static void · line 95

Quoted 6 lines
menu_text.c +2 -2
-      grub_printf ("\n\
+      grub_printf (_("\
       Minimum Emacs-like screen editing is supported. TAB lists\n\
       completions. Press Ctrl-x to boot, Ctrl-c for a command-line\n\
-      or ESC to return menu.");
+      or ESC to return menu."));

These are still not right. We can't have newlines in the middle of a translatable string.

I disagree. We have to give to the translators the minimum unit of "sense", and in this case it's three lines. We cannot force translators to translate the same sentence line by line because:

a) they will not have enough context
b) they cannot rephrase enough
c) maybe in other language the first line would be longer and the second shorter, and if we split they cannot fix (less flexibility for them).

Agree with me?

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info
#6 lore raw
Quoted 32 lines · Carles Pina i Estany

Hi,

Quoted 8 lines · Robert Millan
Quoted 4 lines · Carles Pina i Estany

BTW, I left spaces on the left of lot of strings. In my opinion I would
delete it and call print_spaces(3);. Fine? (or call grub_printf (" ");
).

Yes.

ok!

Quoted 10 lines

menu_text.c static void · line 95

Quoted 7 lines
menu_text.c +2 -2
-      grub_printf ("\n\
+      grub_printf (_("\
       Minimum Emacs-like screen editing is supported. TAB lists\n\
       completions. Press Ctrl-x to boot, Ctrl-c for a command-line\n\
-      or ESC to return menu.");
+      or ESC to return menu."));

These are still not right. We can't have newlines in the middle of a translatable string.

I disagree. We have to give to the translators the minimum unit of "sense", and in this case it's three lines. We cannot force translators to translate the same sentence line by line because:

Quoted 8 lines

a) they will not have enough context
b) they cannot rephrase enough
c) maybe in other language the first line would be longer and the second shorter, and if we split they cannot fix (less flexibility for them).

Agree with me?

The real problem is that these newlines are hardcoded into string whereas they should be put on runtime since terminal width may vary (the string as is is tailored for 80 columns terminal)

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#7 lore raw

Hi,

Quoted 38 lines · Vladimir '??-coder/phcoder' Serbinenko
Quoted 37 lines · Carles Pina i Estany

Hi,

Quoted 8 lines · Robert Millan
Quoted 4 lines · Carles Pina i Estany

BTW, I left spaces on the left of lot of strings. In my opinion I would
delete it and call print_spaces(3);. Fine? (or call grub_printf (" ");
).

Yes.

ok!

Quoted 10 lines

menu_text.c static void · line 95

Quoted 7 lines
menu_text.c +2 -2
-      grub_printf ("\n\
+      grub_printf (_("\
       Minimum Emacs-like screen editing is supported. TAB lists\n\
       completions. Press Ctrl-x to boot, Ctrl-c for a command-line\n\
-      or ESC to return menu.");
+      or ESC to return menu."));

These are still not right. We can't have newlines in the middle of a translatable string.

I disagree. We have to give to the translators the minimum unit of "sense", and in this case it's three lines. We cannot force translators to translate the same sentence line by line because:

a) they will not have enough context
b) they cannot rephrase enough
c) maybe in other language the first line would be longer and the second shorter, and if we split they cannot fix (less flexibility for them).

Quoted 6 lines
Quoted 3 lines

Agree with me?

The real problem is that these newlines are hardcoded into string whereas they should be put on runtime since terminal width may vary (the string as is is tailored for 80 columns terminal)

this makes more sense (I didn't had in mind that the terminal width can vary). I will delete the new lines and make a function that splits the string after WIDTH_TERMINAL without splitting words.

I thought that Robert wanted to have 3 strings to translate, one per line, not one long dynamic string.

Thanks,

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info
#8 lore raw
Quoted 3 lines · Carles Pina i Estany

I thought that Robert wanted to have 3 strings to translate, one per line, not one long dynamic string.

Not at all! That would be even worse :-)

The problem is if we don't remove the newlines, we're putting a burden on
translators: they would have to check that their string fits well with our terminal layout.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."