Mageia Bugzilla – Attachment 9847 Details for
Bug 22257
grub2: allow run-time translation of theme labels
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
Patch to support run-time translation of theme labels
0001-Enable-run-time-translation-of-theme-labels.patch (text/plain), 3.29 KB, created by
Martin Whitaker
on 2017-12-23 22:31:18 CET
(
hide
)
Description:
Patch to support run-time translation of theme labels
Filename:
MIME Type:
Creator:
Martin Whitaker
Created:
2017-12-23 22:31:18 CET
Size:
3.29 KB
patch
obsolete
>From 580762b60c104631b9208dd79d9246c0d0414511 Mon Sep 17 00:00:00 2001 >From: Martin Whitaker <fsf@martin-whitaker.me.uk> >Date: Fri, 8 Dec 2017 22:44:35 +0000 >Subject: [PATCH] Enable run-time translation of theme labels. > >The existing behaviour is to only translate the template labels when >the theme configuration file is first read and to never translate >ordinary labels. This modifies the behaviour to translate all labels >whenever the labels are displayed (provided the gettext module is >loaded and the $lang variable is set). > >diff --git a/grub-core/gfxmenu/gui_label.c b/grub-core/gfxmenu/gui_label.c >index a4c817891..d7035e8ec 100644 >--- a/grub-core/gfxmenu/gui_label.c >+++ b/grub-core/gfxmenu/gui_label.c >@@ -84,6 +84,7 @@ static void > label_paint (void *vself, const grub_video_rect_t *region) > { > grub_gui_label_t self = vself; >+ char * translated_text = _(self->text); > > if (! self->visible) > return; >@@ -97,10 +98,10 @@ label_paint (void *vself, const grub_video_rect_t *region) > left_x = 0; > else if (self->align == align_center) > left_x = (self->bounds.width >- - grub_font_get_string_width (self->font, self->text)) / 2; >+ - grub_font_get_string_width (self->font, translated_text)) / 2; > else if (self->align == align_right) > left_x = (self->bounds.width >- - grub_font_get_string_width (self->font, self->text)); >+ - grub_font_get_string_width (self->font, translated_text)); > else > return; /* Invalid alignment. */ > >@@ -109,7 +110,7 @@ label_paint (void *vself, const grub_video_rect_t *region) > > grub_video_rect_t vpsave; > grub_gui_set_viewport (&self->bounds, &vpsave); >- grub_font_draw_string (self->text, >+ grub_font_draw_string (translated_text, > self->font, > grub_video_map_rgba_color (self->color), > left_x, >@@ -149,7 +150,7 @@ static void > label_get_minimal_size (void *vself, unsigned *width, unsigned *height) > { > grub_gui_label_t self = vself; >- *width = grub_font_get_string_width (self->font, self->text); >+ *width = grub_font_get_string_width (self->font, _(self->text)); > *height = (grub_font_get_ascent (self->font) > + grub_font_get_descent (self->font)); > } >@@ -183,15 +184,15 @@ label_set_property (void *vself, const char *name, const char *value) > else > { > if (grub_strcmp (value, "@KEYMAP_LONG@") == 0) >- value = _("Press enter to boot the selected OS, " >+ value = "Press enter to boot the selected OS, " > "`e' to edit the commands before booting " >- "or `c' for a command-line. ESC to return previous menu."); >+ "or `c' for a command-line. ESC to return previous menu."; > else if (grub_strcmp (value, "@KEYMAP_MIDDLE@") == 0) >- value = _("Press enter to boot the selected OS, " >+ value = "Press enter to boot the selected OS, " > "`e' to edit the commands before booting " >- "or `c' for a command-line."); >+ "or `c' for a command-line."; > else if (grub_strcmp (value, "@KEYMAP_SHORT@") == 0) >- value = _("enter: boot, `e': options, `c': cmd-line"); >+ value = "enter: boot, `e': options, `c': cmd-line"; > /* FIXME: Add more templates here if needed. */ > self->template = grub_strdup (value); > self->text = grub_xasprintf (value, self->value); >-- >2.13.6 >
From 580762b60c104631b9208dd79d9246c0d0414511 Mon Sep 17 00:00:00 2001 From: Martin Whitaker <fsf@martin-whitaker.me.uk> Date: Fri, 8 Dec 2017 22:44:35 +0000 Subject: [PATCH] Enable run-time translation of theme labels. The existing behaviour is to only translate the template labels when the theme configuration file is first read and to never translate ordinary labels. This modifies the behaviour to translate all labels whenever the labels are displayed (provided the gettext module is loaded and the $lang variable is set). diff --git a/grub-core/gfxmenu/gui_label.c b/grub-core/gfxmenu/gui_label.c index a4c817891..d7035e8ec 100644 --- a/grub-core/gfxmenu/gui_label.c +++ b/grub-core/gfxmenu/gui_label.c @@ -84,6 +84,7 @@ static void label_paint (void *vself, const grub_video_rect_t *region) { grub_gui_label_t self = vself; + char * translated_text = _(self->text); if (! self->visible) return; @@ -97,10 +98,10 @@ label_paint (void *vself, const grub_video_rect_t *region) left_x = 0; else if (self->align == align_center) left_x = (self->bounds.width - - grub_font_get_string_width (self->font, self->text)) / 2; + - grub_font_get_string_width (self->font, translated_text)) / 2; else if (self->align == align_right) left_x = (self->bounds.width - - grub_font_get_string_width (self->font, self->text)); + - grub_font_get_string_width (self->font, translated_text)); else return; /* Invalid alignment. */ @@ -109,7 +110,7 @@ label_paint (void *vself, const grub_video_rect_t *region) grub_video_rect_t vpsave; grub_gui_set_viewport (&self->bounds, &vpsave); - grub_font_draw_string (self->text, + grub_font_draw_string (translated_text, self->font, grub_video_map_rgba_color (self->color), left_x, @@ -149,7 +150,7 @@ static void label_get_minimal_size (void *vself, unsigned *width, unsigned *height) { grub_gui_label_t self = vself; - *width = grub_font_get_string_width (self->font, self->text); + *width = grub_font_get_string_width (self->font, _(self->text)); *height = (grub_font_get_ascent (self->font) + grub_font_get_descent (self->font)); } @@ -183,15 +184,15 @@ label_set_property (void *vself, const char *name, const char *value) else { if (grub_strcmp (value, "@KEYMAP_LONG@") == 0) - value = _("Press enter to boot the selected OS, " + value = "Press enter to boot the selected OS, " "`e' to edit the commands before booting " - "or `c' for a command-line. ESC to return previous menu."); + "or `c' for a command-line. ESC to return previous menu."; else if (grub_strcmp (value, "@KEYMAP_MIDDLE@") == 0) - value = _("Press enter to boot the selected OS, " + value = "Press enter to boot the selected OS, " "`e' to edit the commands before booting " - "or `c' for a command-line."); + "or `c' for a command-line."; else if (grub_strcmp (value, "@KEYMAP_SHORT@") == 0) - value = _("enter: boot, `e': options, `c': cmd-line"); + value = "enter: boot, `e': options, `c': cmd-line"; /* FIXME: Add more templates here if needed. */ self->template = grub_strdup (value); self->text = grub_xasprintf (value, self->value); -- 2.13.6
View Attachment As Raw
Actions:
View
Attachments on
bug 22257
: 9847