Skip to contentSkip to conversation

gettext: version string in normal/main.c

PATCH Carles Pina i Estany 1 participant 4 messages Dec 19, 2009

lore
Share & tools
lore
#0 lore raw

Hi,

I've gettextitzzed the version string.

Something to improve before committing?
It's all right?

Thanks,

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

=== modified file 'ChangeLog'

ChangeLog +13 -0
@@ -1,5 +1,18 @@
 2009-12-19  Carles Pina i Estany  <[email protected]>
 
+	* include/grub/normal.h (utf8_to_ucs4): New declaration.
+	(grub_print_ucs4): Likewise.
+	(getstringwidth): Likewise.
+	* normal/main.c (grub_normal_init_page): Gettextize version string.
+	* normal/menu_text.c (utf8_to_ucs4): New declaration.
+	(getstringwidth): Remove `static' qualifier (now used in
+	normal/main.c).  Use `utf8_to_ucs4'.
+	(grub_print_ucs4): Remove `static' qualifer (now used in
+	normal/main.c).
+	* po/POTFILES: Add normal/main.c.
+
+2009-12-19  Carles Pina i Estany  <[email protected]>
+
 	* normal/menu_text.c (STANDARD_MARGIN): New macro.
 	(print_message_indented): Add `margin_left' and `margin_right'
 	parameters.

=== modified file 'include/grub/normal.h'

grub/normal.h +6 -0
@@ -73,6 +73,12 @@ void grub_parse_color_name_pair (grub_ui
 
 /* Defined in `menu_text.c'.  */
 void grub_wait_after_message (void);
+int utf8_to_ucs4 (const char *msg, grub_uint32_t **unicode_msg,
+			grub_uint32_t **last_position);
+void grub_print_ucs4 (const grub_uint32_t * str,
+			const grub_uint32_t * last_position);
+grub_ssize_t getstringwidth (grub_uint32_t * str,
+			const grub_uint32_t * last_position);
 
 /* Defined in `handler.c'.  */
 void read_handler_list (void);

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

main.c +19 -10
@@ -385,22 +385,31 @@ read_config_file (const char *config)
 void
 grub_normal_init_page (void)
 {
-  grub_uint8_t width, margin;
+  grub_cls ();
+  const char *msg = _("GNU GRUB  version %s");
 
-#define TITLE ("GNU GRUB  version " PACKAGE_VERSION)
+  char *msg_formatted = grub_malloc (grub_strlen(msg) + grub_strlen(PACKAGE_VERSION));
 
-  width = grub_getwh () >> 8;
-  margin = (width - (sizeof(TITLE) + 7)) / 2;
+  grub_sprintf (msg_formatted, msg, PACKAGE_VERSION);
 
-  grub_cls ();
-  grub_putchar ('\n');
+  grub_uint32_t *unicode_msg;
+  grub_uint32_t *last_position;
+  
+  int msg_len;
 
-  while (margin--)
-    grub_putchar (' ');
+  msg_len = utf8_to_ucs4 (msg_formatted, &unicode_msg, &last_position);
+  
+  if (msg_len < 0)
+    {
+      return;
+    }
 
-  grub_printf ("%s\n\n", TITLE);
+  int posx = getstringwidth (unicode_msg, last_position);
+  posx = (GRUB_TERM_WIDTH - posx) / 2;
+  grub_gotoxy (posx, 1);
 
-#undef TITLE
+  grub_print_ucs4 (unicode_msg, last_position);
+  grub_printf("\n\n");
 }
 
 static int reader_nested;

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

menu_text.c +32 -17

75 lines not on this page · raw message

=== modified file 'po/POTFILES'

POTFILES +1 -0
@@ -11,5 +11,6 @@ util/mkisofs/rock.c
 util/mkisofs/tree.c
 util/mkisofs/write.c
 
+normal/main.c
 normal/menu_entry.c
 normal/menu_text.c
#1 lore raw

Hi,

Quoted 1 line · Carles Pina i Estany

Something to improve before committing?

New patch with a missing grub_free.

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

=== modified file 'ChangeLog'

ChangeLog +13 -0
@@ -1,5 +1,18 @@
 2009-12-19  Carles Pina i Estany  <[email protected]>
 
+	* include/grub/normal.h (utf8_to_ucs4): New declaration.
+	(grub_print_ucs4): Likewise.
+	(getstringwidth): Likewise.
+	* normal/main.c (grub_normal_init_page): Gettextize version string.
+	* normal/menu_text.c (utf8_to_ucs4): New declaration.
+	(getstringwidth): Remove `static' qualifier (now used in
+	normal/main.c).  Use `utf8_to_ucs4'.
+	(grub_print_ucs4): Remove `static' qualifer (now used in
+	normal/main.c).
+	* po/POTFILES: Add normal/main.c.
+
+2009-12-19  Carles Pina i Estany  <[email protected]>
+
 	* normal/menu_text.c (STANDARD_MARGIN): New macro.
 	(print_message_indented): Add `margin_left' and `margin_right'
 	parameters.

=== modified file 'include/grub/normal.h'

grub/normal.h +6 -0
@@ -73,6 +73,12 @@ void grub_parse_color_name_pair (grub_ui
 
 /* Defined in `menu_text.c'.  */
 void grub_wait_after_message (void);
+int utf8_to_ucs4 (const char *msg, grub_uint32_t **unicode_msg,
+			grub_uint32_t **last_position);
+void grub_print_ucs4 (const grub_uint32_t * str,
+			const grub_uint32_t * last_position);
+grub_ssize_t getstringwidth (grub_uint32_t * str,
+			const grub_uint32_t * last_position);
 
 /* Defined in `handler.c'.  */
 void read_handler_list (void);

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

main.c +21 -11
@@ -385,22 +385,32 @@ read_config_file (const char *config)
 void
 grub_normal_init_page (void)
 {
-  grub_uint8_t width, margin;
-
-#define TITLE ("GNU GRUB  version " PACKAGE_VERSION)
+  grub_cls ();
+  const char *msg = _("GNU GRUB  version %s");
 
-  width = grub_getwh () >> 8;
-  margin = (width - (sizeof(TITLE) + 7)) / 2;
+  char *msg_formatted = grub_malloc (grub_strlen(msg) + grub_strlen(PACKAGE_VERSION));
 
-  grub_cls ();
-  grub_putchar ('\n');
+  grub_sprintf (msg_formatted, msg, PACKAGE_VERSION);
 
-  while (margin--)
-    grub_putchar (' ');
+  grub_uint32_t *unicode_msg;
+  grub_uint32_t *last_position;
+  
+  int msg_len;
 
-  grub_printf ("%s\n\n", TITLE);
+  msg_len = utf8_to_ucs4 (msg_formatted, &unicode_msg, &last_position);
+  
+  if (msg_len < 0)
+    {
+      return;
+    }
 
-#undef TITLE
+  int posx = getstringwidth (unicode_msg, last_position);
+  posx = (GRUB_TERM_WIDTH - posx) / 2;
+  grub_gotoxy (posx, 1);
+
+  grub_print_ucs4 (unicode_msg, last_position);
+  grub_printf("\n\n");
+  grub_free (unicode_msg);
 }
 
 static int reader_nested;

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

menu_text.c +32 -17

75 lines not on this page · raw message

=== modified file 'po/POTFILES'

POTFILES +1 -0
@@ -11,5 +11,6 @@ util/mkisofs/rock.c
 util/mkisofs/tree.c
 util/mkisofs/write.c
 
+normal/main.c
 normal/menu_entry.c
 normal/menu_text.c
#2 lore raw

Hi,

Quoted 3 lines · Carles Pina i Estany
Quoted 1 line · Carles Pina i Estany

Something to improve before committing?

when this will be reviewed and committed I will adapt (some things has changed) the last part of normal/* files . I sent a week ago aprox. but needs some changes because it conflicts.

After that I will do other changes in commands/*, and this is mainly all for Grub2 loader gettext. I'm sure that there are other strings that I will keep doing but at least from the standard user point of view is quite gettextizzed.

Then I'll do some documentation about how to test, more testing using gfxterm, update the .pot in TP and keep working with the utils part.

As Robert pointed should be done soon so translators can translate, review, spot some deficiencies and sooner better than later.

Cheers,

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

Hi,

Quoted 8 lines · Carles Pina i Estany

Hi,

Quoted 1 line · Carles Pina i Estany

Something to improve before committing?

New patch with a missing grub_free.

reviewed in IRC and committed.

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