From 203ffbfa31729f828a0564538499613e07561861 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Fri, 13 Nov 2009 20:39:33 +0000 Subject: [PATCH 01/20] Adds gettext support in Grub. Building system needs to be improved and maybe userland utilites improved. YYYY-MM-DD Carles Pina i Estany * Makefile.in: Add uptrans target to help to update .pot file * conf/common.rmk: Add grub-gettext_lib target, dependency and SOURCES, CFLAGS, LDFLAGS * kern/misc.c: Define grub_gettext symbol and add implement grub_gettext_dummy function * po/TODO: Temporary file with instructions of what Makefile.in will do * po/ca.po: Catalan translation stub * include/grub/misc.h: Define macro _(char *s). Declare grub_gettext_dummy and grub_gettext * gettext/gettext.c: New file with gettext implementation * normal/menu.c (print_message): add _( ) to some strings * util/grub.d/10_linux.in: include grub-gettext_lib file. For the Linux menuentry, call eval_gettext * util/grub.d/00_header.in: add locale_prefix and gettext locale detection and setting up the access to the mo directory * util/grub-mkconfig_lib.in: add get_locale_lang * util/grub-gettext_lib.in: new file --- conf/common.rmk | 13 +- gettext/gettext.c | 285 ++++++++++++++++++++++++++++++++++++++ include/grub/misc.h | 7 +- kern/misc.c | 9 ++ normal/menu_text.c | 4 +- util/grub-gettext_lib.in | 23 +++ util/grub-mkconfig_lib.in | 11 ++ util/grub.d/00_header.in | 16 +++ util/grub.d/10_linux.in | 8 +- 9 files changed, 368 insertions(+), 8 deletions(-) create mode 100644 gettext/gettext.c create mode 100644 util/grub-gettext_lib.in diff --git a/conf/common.rmk b/conf/common.rmk index a66bd97fd..deb18372b 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -162,6 +162,12 @@ update-grub_lib: util/update-grub_lib.in config.status lib_SCRIPTS += update-grub_lib CLEANFILES += update-grub_lib +grub-gettext_lib: util/grub-gettext_lib.in config.status + ./config.status --file=$@:$< + chmod +x $@ +lib_DATA += grub-gettext_lib +CLEANFILES += grub-gettext_lib + %: util/grub.d/%.in config.status ./config.status --file=$@:$< chmod +x $@ @@ -178,7 +184,7 @@ grub-mkconfig_DATA += util/grub.d/README pkglib_MODULES += fshelp.mod fat.mod ufs1.mod ufs2.mod ext2.mod ntfs.mod \ ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod \ affs.mod sfs.mod hfsplus.mod reiserfs.mod cpio.mod tar.mod \ - udf.mod afs.mod afs_be.mod befs.mod befs_be.mod + udf.mod afs.mod afs_be.mod befs.mod befs_be.mod gettext.mod # For fshelp.mod. fshelp_mod_SOURCES = fs/fshelp.c @@ -609,6 +615,11 @@ bufio_mod_SOURCES = io/bufio.c bufio_mod_CFLAGS = $(COMMON_CFLAGS) bufio_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For gettext.mod. +gettext_mod_SOURCES = gettext/gettext.c +gettext_mod_CFLAGS = $(COMMON_CFLAGS) +gettext_mod_LDFLAGS = $(COMMON_LDFLAGS) + # Misc. pkglib_MODULES += xnu_uuid.mod diff --git a/gettext/gettext.c b/gettext/gettext.c new file mode 100644 index 000000000..089f59db4 --- /dev/null +++ b/gettext/gettext.c @@ -0,0 +1,285 @@ +/* gettext.c - gettext module */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + .mo file information from: + http://www.gnu.org/software/autoconf/manual/gettext/MO-Files.html . +*/ + + +static grub_file_t grub_mofile_open (const char *name); +static grub_file_t fd_mo; + +static int grub_gettext_offsetoriginal; +static int grub_gettext_max; + +static const char* (*grub_gettext_original) (const char *s); + +#define GETTEXT_MAGIC_NUMBER 0 +#define GETTEXT_FILE_FORMAT 4 +#define GETTEXT_NUMBER_OF_STRINGS 8 +#define GETTEXT_OFFSET_ORIGINAL 12 +#define GETTEXT_OFFSET_TRANSLATION 16 + +#define MO_MAGIC_NUMBER 0x950412de + +static grub_uint32_t +grub_gettext_get_info (int offset) +{ + grub_uint32_t value; + + grub_file_seek (fd_mo, offset); + grub_file_read (fd_mo, (char*) &value, 4); + value = grub_cpu_to_le32 (value); + return value; +} + +static void +grub_gettext_getstring_from_offset (grub_uint32_t offset, grub_uint32_t length, char *translation) +{ + grub_file_seek (fd_mo, offset); + grub_file_read (fd_mo, translation, length); + translation[length] = '\0'; +} + +static char* +grub_gettext_gettranslation_from_position (int position) +{ + int offsettranslation; + int internal_position; + grub_uint32_t length, offset; + char *translation; + + offsettranslation = grub_gettext_get_info (GETTEXT_OFFSET_TRANSLATION); + + internal_position = offsettranslation + position * 8; + + grub_file_seek (fd_mo, internal_position); + grub_file_read (fd_mo, (char*) &length, 4); + length = grub_cpu_to_le32 (length); + + grub_file_seek (fd_mo, internal_position + 4), + grub_file_read (fd_mo, (char*) &offset, 4); + offset = grub_cpu_to_le32 (offset); + + translation = grub_malloc(length + 1); + grub_gettext_getstring_from_offset (offset, length, translation); + + return translation; +} + +static char* +grub_gettext_getstring_from_position (int position) +{ + int internal_position; + int length, offset; + char *original; + + /* Get position for string i. */ + internal_position = grub_gettext_offsetoriginal + (position * 8); + + /* Get the length of the string i. */ + grub_file_seek (fd_mo, internal_position); + grub_file_read (fd_mo, (char *) &length, 4); + + /* Get the offset of the string i. */ + grub_file_seek (fd_mo, internal_position + 4); + grub_file_read (fd_mo, (char *) &offset, 4); + + /* Get the string i. */ + original = grub_malloc (length + 1); + grub_gettext_getstring_from_offset (offset, length, original); + + return original; +} + +static const char* +grub_gettext_translate (const char *orig) +{ + char *current_string; + char *ret; + + int min,max,current; + + if (fd_mo == 0) + return orig; + + min = 0; + max = grub_gettext_max; + + current = (max + min) / 2; + + while (current != min && current != max) + { + current_string = grub_gettext_getstring_from_position (current); + + /* Search by bisection. */ + if (grub_strcmp (current_string, orig) < 0) + { + grub_free(current_string); + min=current; + } + else if (grub_strcmp (current_string, orig) > 0) + { + grub_free(current_string); + max=current; + } + else if (grub_strcmp (current_string, orig) == 0) + { + grub_free(current_string); + return grub_gettext_gettranslation_from_position (current); + } + current = (max+min)/2; + } + + ret = grub_malloc(grub_strlen(orig) + 1); + grub_strcpy(ret,orig); + return ret; +} + +/* This is similar to grub_gzfile_open. */ +static grub_file_t +grub_mofile_open (const char *filename) +{ + int unsigned magic; + int version; + + /* Using fd_mo and not another variable because + it's needed for grub_gettext_get_info. */ + + fd_mo = grub_file_open (filename); + if (! fd_mo) + { + grub_error (GRUB_ERR_FILE_READ_ERROR, "Cannot read %s",filename); + return 0; + } + + magic = grub_gettext_get_info (GETTEXT_MAGIC_NUMBER); + + if (magic != MO_MAGIC_NUMBER) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, "mo: invalid mo file: %s", filename); + grub_file_close (fd_mo); + fd_mo = 0; + return 0; + } + + version = grub_gettext_get_info (GETTEXT_FILE_FORMAT); + + if (version != 0) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, "mo: invalid mo version in file: %s", filename); + fd_mo = 0; + return 0; + } + + /* + Do we want .mo.gz files? Then, the code: + file = grub_gzio_open (io, 0); // 0: transparent + if (! file) + { + grub_printf("Problems opening the file\n"); + grub_file_close (io); + return 0; + } + */ + + return fd_mo; +} + +static void +grub_gettext_init_ext (const char *lang) +{ + char *mo_file; + char *grub_prefix; + + grub_prefix = grub_env_get ("prefix"); + + fd_mo = 0; + + // mo_file e.g.: /boot/grub/locale/ca.mo + + mo_file = grub_malloc (grub_strlen (grub_prefix) + sizeof ("/locale/") + grub_strlen (lang) + sizeof(".mo")); + + // Warning: if changing some paths in the below line, change the grub_malloc + // contents below + + grub_sprintf (mo_file, "%s/locale/%s.mo", grub_prefix, lang); + grub_dprintf(" -------------- %s ",mo_file); + + fd_mo = grub_mofile_open(mo_file); + grub_free (mo_file); + + if (fd_mo) + { + grub_gettext_offsetoriginal = grub_gettext_get_info(GETTEXT_OFFSET_ORIGINAL); + grub_gettext_max = grub_gettext_get_info(GETTEXT_NUMBER_OF_STRINGS); + + grub_gettext_original = grub_gettext; + grub_gettext = grub_gettext_translate; + } +} + +static char* +grub_gettext_env_write_lang (struct grub_env_var *var __attribute__ ((unused)), + const char *val) +{ + grub_gettext_init_ext (val); + + return grub_strdup (val); +} + +GRUB_MOD_INIT(gettext) +{ + (void)mod; /* To stop warning. */ + + const char *lang; + + lang = grub_env_get ("lang"); + + grub_gettext_init_ext (lang); + + /* Testing: + grub_register_command ("_", grub_cmd_translate, GRUB_COMMAND_FLAG_BOTH, + "_", "internalization support trans", 0); + */ + + /* Reload .mo file information if lang changes. */ + grub_register_variable_hook ("lang", NULL, grub_gettext_env_write_lang); + + /* Preserve hooks after context changes. */ + grub_env_export ("lang"); +} + +GRUB_MOD_FINI(gettext) +{ + if (fd_mo != 0) + grub_file_close(fd_mo); + + grub_gettext = grub_gettext_original; +} diff --git a/include/grub/misc.h b/include/grub/misc.h index faa2d5c42..0a3406737 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -1,7 +1,7 @@ /* misc.h - prototypes for misc functions */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +34,8 @@ /* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */ #define grub_memcpy(d,s,n) grub_memmove ((d), (s), (n)) +#define _(s) grub_gettext(s) + void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n); char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src); char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, int c); @@ -191,6 +193,9 @@ grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest, grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, grub_uint32_t d, grub_uint32_t *r); +const char *EXPORT_FUNC(grub_gettext_dummy) (const char *s); +extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s);// = grub_gettext_dummy; + #ifdef NEED_ENABLE_EXECUTE_STACK void EXPORT_FUNC(__enable_execute_stack) (void *addr); #endif diff --git a/kern/misc.c b/kern/misc.c index cacfbc753..827f864c4 100644 --- a/kern/misc.c +++ b/kern/misc.c @@ -30,6 +30,8 @@ grub_iswordseparator (int c) return (grub_isspace (c) || c == ',' || c == ';' || c == '|' || c == '&'); } +const char* (*grub_gettext) (const char *s) = grub_gettext_dummy; + void * grub_memmove (void *dest, const void *src, grub_size_t n) { @@ -984,6 +986,13 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize, return p - dest; } +/* grub_gettext_dummy is not translating anything. */ +const char * +grub_gettext_dummy (const char *s) +{ + return s; +} + /* Abort GRUB. This function does not return. */ void grub_abort (void) diff --git a/normal/menu_text.c b/normal/menu_text.c index e0d96c47f..e757110c0 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -93,8 +93,8 @@ print_message (int nested, int edit) } else { - grub_printf ("\n\ - Use the %C and %C keys to select which entry is highlighted.\n", + grub_printf (_("\n\ + Use the %C and %C keys to select which entry is highlighted.\n"), (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); grub_printf ("\ Press enter to boot the selected OS, \'e\' to edit the\n\ diff --git a/util/grub-gettext_lib.in b/util/grub-gettext_lib.in new file mode 100644 index 000000000..00d1bdd98 --- /dev/null +++ b/util/grub-gettext_lib.in @@ -0,0 +1,23 @@ +# Configuration of grub-gettext +# Copyright (C) 2009 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see . + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ + +TEXTDOMAINDIR=@prefix@/share/locale +TEXTDOMAIN=grub +. gettext.sh diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index bb30cc475..47e37f265 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -215,3 +215,14 @@ version_find_latest () done echo "$a" } + +get_locale_lang () +{ + lang="`echo ${LANG} | cut -d _ -f 1`" + if [ "x${lang}" = "x" ] ; then + return 1 + else + echo "${lang}" + return 0 + fi +} diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 9f421dc1c..fe1352883 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -22,6 +22,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ grub_prefix=`echo /boot/grub | sed ${transform}` +locale_prefix="/usr/share/locale" # TODO: dynamic with exec_prefix ? . ${libdir}/grub/grub-mkconfig_lib @@ -100,6 +101,21 @@ EOF ;; esac +if test -e ${grub_prefix}/gettext.mod -a -d /usr/share/locale; then + # Make the locales accesible + prepare_grub_to_access_device `${grub_probe} --target=device ${locale_prefix}` + lang=`get_locale_lang` + grub_locale_prefix=`make_system_path_relative_to_its_root ${locale_prefix}` + cat << EOF +# Gettext variables and module +set locale_prefix=${grub_locale_prefix} +set lang=${lang} +insmod gettext +EOF +else + echo "gettext module or /usr/share/locale is not available" +fi + if [ "x${GRUB_HIDDEN_TIMEOUT}" != "x" ] ; then if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then verbose= diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index f17955846..9cb39e41c 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -95,11 +95,11 @@ while [ "x$list" != "x" ] ; do linux_root_device_thisversion=${GRUB_DEVICE} fi - linux_entry "${OS}, with Linux ${version}" \ - "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + linux_entry $eval_gettext ("${OS}, with Linux ${version}" \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}") if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then - linux_entry "${OS}, with Linux ${version} (recovery mode)" \ - "single ${GRUB_CMDLINE_LINUX}" + linux_entry $eval_gettext ("${OS}, with Linux ${version} (recovery mode)" \ + "single ${GRUB_CMDLINE_LINUX}") fi list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '` From 44883dfbd5d05c159cba64e903de5b3afb593123 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Thu, 19 Nov 2009 21:43:09 +0000 Subject: [PATCH 02/20] 2009-11-19 Carles Pina i Estany * include/grb/i18n_grub.h: same than i18n.h but for Grub Kernel. * include/grub/misc.h: includes i18n_grub.h. * normal/menu_text.c: gettize more strings. * po/POTFILES: Update with new file. * po/ca.po: New strings. --- include/grub/i18n_grub.h | 24 ++++++++++++++++++++++++ include/grub/misc.h | 2 -- normal/menu_text.c | 1 + po/POTFILES | 2 ++ po/ca.po | 11 ++++++++++- 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 include/grub/i18n_grub.h diff --git a/include/grub/i18n_grub.h b/include/grub/i18n_grub.h new file mode 100644 index 000000000..ed3382568 --- /dev/null +++ b/include/grub/i18n_grub.h @@ -0,0 +1,24 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_I18N_GRUB_H +#define GRUB_I18N_GRUB_H 1 + +# define _(str) grub_gettext(str) + +#endif /* GRUB_I18N_GRUB_H */ diff --git a/include/grub/misc.h b/include/grub/misc.h index 0a3406737..bc725f9ca 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -34,8 +34,6 @@ /* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */ #define grub_memcpy(d,s,n) grub_memmove ((d), (s), (n)) -#define _(s) grub_gettext(s) - void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n); char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src); char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, int c); diff --git a/normal/menu_text.c b/normal/menu_text.c index e757110c0..66a0bcfb4 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -25,6 +25,7 @@ #include #include #include +#include /* Time to delay after displaying an error message about a default/fallback entry failing to boot. */ diff --git a/po/POTFILES b/po/POTFILES index 5b1239a5e..c0fc40c30 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -10,3 +10,5 @@ util/mkisofs/multi.c util/mkisofs/rock.c util/mkisofs/tree.c util/mkisofs/write.c + +normal/menu_text.c diff --git a/po/ca.po b/po/ca.po index 3f9b0ac32..02cfe3751 100644 --- a/po/ca.po +++ b/po/ca.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: GNU GRUB\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-11-19 00:16+0100\n" +"POT-Creation-Date: 2009-11-19 21:37+0000\n" "PO-Revision-Date: 2009-11-17 12:26+0100\n" "Last-Translator: Robert Millan \n" "Language-Team: None \n" @@ -882,6 +882,15 @@ msgstr "" msgid "Path table size(bytes): %d\n" msgstr "" +#: normal/menu_text.c:97 +#, c-format +msgid "" +"\n" +" Use the %C and %C keys to select which entry is highlighted.\n" +msgstr "" +"\n" +" Utilitzeu les tecles %C i %C per a seleccionar l'entrada.\n" + #: util/grub.d/10_kfreebsd.in:40 msgid "%s, with kFreeBSD %s" msgstr "" From cb681ffd7af8aac37c2718eedb041c9b5330abcb Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sat, 21 Nov 2009 21:18:12 +0000 Subject: [PATCH 03/20] Deletes grub-gettext_lib.in (not needed after Robert's changes) --- util/grub-gettext_lib.in | 23 ----------------------- util/grub-mkconfig_lib.in | 11 ----------- 2 files changed, 34 deletions(-) delete mode 100644 util/grub-gettext_lib.in diff --git a/util/grub-gettext_lib.in b/util/grub-gettext_lib.in deleted file mode 100644 index 00d1bdd98..000000000 --- a/util/grub-gettext_lib.in +++ /dev/null @@ -1,23 +0,0 @@ -# Configuration of grub-gettext -# Copyright (C) 2009 Free Software Foundation, Inc. -# -# GRUB is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# GRUB is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GRUB. If not, see . - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ - -TEXTDOMAINDIR=@prefix@/share/locale -TEXTDOMAIN=grub -. gettext.sh diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 47e37f265..bb30cc475 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -215,14 +215,3 @@ version_find_latest () done echo "$a" } - -get_locale_lang () -{ - lang="`echo ${LANG} | cut -d _ -f 1`" - if [ "x${lang}" = "x" ] ; then - return 1 - else - echo "${lang}" - return 0 - fi -} From 414092d75a54ad4b6c86c2131fe61778d93ce79f Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sat, 21 Nov 2009 22:19:16 +0000 Subject: [PATCH 04/20] Adds the ChangeLog.gettext file --- ChangeLog.gettext | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ChangeLog.gettext diff --git a/ChangeLog.gettext b/ChangeLog.gettext new file mode 100644 index 000000000..6bce3f38b --- /dev/null +++ b/ChangeLog.gettext @@ -0,0 +1,15 @@ +YYYY-MM-DD Carles Pina i Estany + + * conf/common.rmk: Add grub-gettext_lib target, dependency and + SOURCES, CFLAGS, LDFLAGS + * gettext/gettext.c: New file with gettext implementation + * include/grub/i18n_grub.h: New file with grub_gettext macros + * include/grub/misc.h: Define macro _(char *s). Declare + grub_gettext_dummy and grub_gettext + * kern/misc.c: Define grub_gettext symbol implementation of the + grub_gettext_dummy function + * normal/menu_text.c: Gettextize one message in print_message + * po/POTFILES: Adds normal/menu_text.c + * po/ca.po: Adds the new string + * util/grub.d/00_header.in: defines gettext variables and loads + the module From 43fa69467ceb2a55eb8176c474159a4806f05614 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sat, 21 Nov 2009 23:06:37 +0000 Subject: [PATCH 05/20] Moves where pkglib_MODULS += gettext.mod is defined --- conf/common.rmk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conf/common.rmk b/conf/common.rmk index da56015ba..a4c3c80e8 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -185,7 +185,7 @@ grub-mkconfig_DATA += util/grub.d/README pkglib_MODULES += fshelp.mod fat.mod ufs1.mod ufs2.mod ext2.mod ntfs.mod \ ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod \ affs.mod sfs.mod hfsplus.mod reiserfs.mod cpio.mod tar.mod \ - udf.mod afs.mod afs_be.mod befs.mod befs_be.mod gettext.mod + udf.mod afs.mod afs_be.mod befs.mod befs_be.mod # For fshelp.mod. fshelp_mod_SOURCES = fs/fshelp.c @@ -617,6 +617,7 @@ bufio_mod_CFLAGS = $(COMMON_CFLAGS) bufio_mod_LDFLAGS = $(COMMON_LDFLAGS) # For gettext.mod. +pkglib_MODULES += gettext.mod gettext_mod_SOURCES = gettext/gettext.c gettext_mod_CFLAGS = $(COMMON_CFLAGS) gettext_mod_LDFLAGS = $(COMMON_LDFLAGS) From ee99edc8099de8e47355dbdb8b6d27d8c9f13594 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sat, 21 Nov 2009 23:11:14 +0000 Subject: [PATCH 06/20] Some comments following Grub standard of code. --- gettext/gettext.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gettext/gettext.c b/gettext/gettext.c index 9a658f5db..ca00a86b7 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -222,12 +222,12 @@ grub_gettext_init_ext (const char *lang) fd_mo = 0; - // mo_file e.g.: /boot/grub/locale/ca.mo + /* mo_file e.g.: /boot/grub/locale/ca.mo */ mo_file = grub_malloc (grub_strlen (locale_dir) + sizeof ("/") + grub_strlen (lang) + sizeof(".mo")); - // Warning: if changing some paths in the below line, change the grub_malloc - // contents below + /* Warning: if changing some paths in the below line, change the grub_malloc + contents below. */ grub_sprintf (mo_file, "%s/%s.mo", locale_dir, lang); From 0648f857eade0c094b08baab277de4d9e74bbe90 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 11:49:54 +0000 Subject: [PATCH 07/20] Different changes following Robert's email 20091121230904.GA29740@thorin --- gettext/gettext.c | 167 +++++++++++++++++++-------------------- include/grub/file.h | 2 + include/grub/i18n.h | 2 +- include/grub/i18n_grub.h | 24 ------ kern/file.c | 10 +++ normal/menu_text.c | 4 +- po/ca.po | 7 +- util/grub.d/00_header.in | 4 +- 8 files changed, 107 insertions(+), 113 deletions(-) delete mode 100644 include/grub/i18n_grub.h diff --git a/gettext/gettext.c b/gettext/gettext.c index ca00a86b7..c488f0e50 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -25,6 +25,7 @@ #include #include #include +#include /* .mo file information from: @@ -32,42 +33,41 @@ */ -static grub_file_t grub_mofile_open (const char *name); static grub_file_t fd_mo; static int grub_gettext_offsetoriginal; static int grub_gettext_max; -static const char* (*grub_gettext_original) (const char *s); +static const char *(*grub_gettext_original) (const char *s); -#define GETTEXT_MAGIC_NUMBER 0 -#define GETTEXT_FILE_FORMAT 4 -#define GETTEXT_NUMBER_OF_STRINGS 8 -#define GETTEXT_OFFSET_ORIGINAL 12 -#define GETTEXT_OFFSET_TRANSLATION 16 +#define GETTEXT_MAGIC_NUMBER 0 +#define GETTEXT_FILE_FORMAT 4 +#define GETTEXT_NUMBER_OF_STRINGS 8 +#define GETTEXT_OFFSET_ORIGINAL 12 +#define GETTEXT_OFFSET_TRANSLATION 16 -#define MO_MAGIC_NUMBER 0x950412de +#define MO_MAGIC_NUMBER 0x950412de static grub_uint32_t grub_gettext_get_info (int offset) { grub_uint32_t value; - grub_file_seek (fd_mo, offset); - grub_file_read (fd_mo, (char*) &value, 4); + grub_file_pread (fd_mo, (char *) &value, 4, offset); + value = grub_cpu_to_le32 (value); return value; } static void -grub_gettext_getstring_from_offset (grub_uint32_t offset, grub_uint32_t length, char *translation) +grub_gettext_getstring_from_offset (grub_uint32_t offset, + grub_uint32_t length, char *translation) { - grub_file_seek (fd_mo, offset); - grub_file_read (fd_mo, translation, length); + grub_file_pread (fd_mo, translation, length, offset); translation[length] = '\0'; } -static char* +static char * grub_gettext_gettranslation_from_position (int position) { int offsettranslation; @@ -79,21 +79,19 @@ grub_gettext_gettranslation_from_position (int position) internal_position = offsettranslation + position * 8; - grub_file_seek (fd_mo, internal_position); - grub_file_read (fd_mo, (char*) &length, 4); + grub_file_pread (fd_mo, (char *) &length, 4, internal_position); length = grub_cpu_to_le32 (length); - - grub_file_seek (fd_mo, internal_position + 4), - grub_file_read (fd_mo, (char*) &offset, 4); + + grub_file_pread (fd_mo, (char *) &offset, 4, internal_position + 4); offset = grub_cpu_to_le32 (offset); - translation = grub_malloc(length + 1); + translation = grub_malloc (length + 1); grub_gettext_getstring_from_offset (offset, length, translation); return translation; } -static char* +static char * grub_gettext_getstring_from_position (int position) { int internal_position; @@ -104,12 +102,10 @@ grub_gettext_getstring_from_position (int position) internal_position = grub_gettext_offsetoriginal + (position * 8); /* Get the length of the string i. */ - grub_file_seek (fd_mo, internal_position); - grub_file_read (fd_mo, (char *) &length, 4); + grub_file_pread (fd_mo, (char *) &length, 4, internal_position); /* Get the offset of the string i. */ - grub_file_seek (fd_mo, internal_position + 4); - grub_file_read (fd_mo, (char *) &offset, 4); + grub_file_pread (fd_mo, (char *) &offset, 4, internal_position + 4); /* Get the string i. */ original = grub_malloc (length + 1); @@ -118,13 +114,13 @@ grub_gettext_getstring_from_position (int position) return original; } -static const char* +static const char * grub_gettext_translate (const char *orig) { char *current_string; char *ret; - int min,max,current; + int min, max, current; if (fd_mo == 0) return orig; @@ -140,25 +136,25 @@ grub_gettext_translate (const char *orig) /* Search by bisection. */ if (grub_strcmp (current_string, orig) < 0) - { - grub_free(current_string); - min=current; - } + { + grub_free (current_string); + min = current; + } else if (grub_strcmp (current_string, orig) > 0) - { - grub_free(current_string); - max=current; - } + { + grub_free (current_string); + max = current; + } else if (grub_strcmp (current_string, orig) == 0) - { - grub_free(current_string); - return grub_gettext_gettranslation_from_position (current); - } - current = (max+min)/2; + { + grub_free (current_string); + return grub_gettext_gettranslation_from_position (current); + } + current = (max + min) / 2; } - ret = grub_malloc(grub_strlen(orig) + 1); - grub_strcpy(ret,orig); + ret = grub_malloc (grub_strlen (orig) + 1); + grub_strcpy (ret, orig); return ret; } @@ -168,46 +164,42 @@ grub_mofile_open (const char *filename) { int unsigned magic; int version; + grub_file_t new_fd; /* Using fd_mo and not another variable because it's needed for grub_gettext_get_info. */ - fd_mo = grub_file_open (filename); - if (! fd_mo) + new_fd = grub_gzfile_open (filename, 1); + grub_errno = GRUB_ERR_NONE; + + if (!new_fd) { - grub_error (GRUB_ERR_FILE_READ_ERROR, "Cannot read %s",filename); + grub_dprintf ("gettext: Cannot read %s", filename); return 0; } + fd_mo = new_fd; + magic = grub_gettext_get_info (GETTEXT_MAGIC_NUMBER); if (magic != MO_MAGIC_NUMBER) { - grub_error (GRUB_ERR_BAD_FILE_TYPE, "mo: invalid mo file: %s", filename); + grub_error (GRUB_ERR_BAD_FILE_TYPE, "mo: invalid mo file: %s", + filename); grub_file_close (fd_mo); fd_mo = 0; return 0; } - + version = grub_gettext_get_info (GETTEXT_FILE_FORMAT); if (version != 0) { - grub_error (GRUB_ERR_BAD_FILE_TYPE, "mo: invalid mo version in file: %s", filename); + grub_error (GRUB_ERR_BAD_FILE_TYPE, + "mo: invalid mo version in file: %s", filename); fd_mo = 0; return 0; } - - /* - Do we want .mo.gz files? Then, the code: - file = grub_gzio_open (io, 0); // 0: transparent - if (! file) - { - grub_printf("Problems opening the file\n"); - grub_file_close (io); - return 0; - } - */ return fd_mo; } @@ -219,57 +211,64 @@ grub_gettext_init_ext (const char *lang) char *locale_dir; locale_dir = grub_env_get ("locale_dir"); - - fd_mo = 0; - + if (locale_dir == NULL) + { + grub_printf ("locale_dir variable is not setted up."); + return; + } + + fd_mo = NULL; + /* mo_file e.g.: /boot/grub/locale/ca.mo */ - mo_file = grub_malloc (grub_strlen (locale_dir) + sizeof ("/") + grub_strlen (lang) + sizeof(".mo")); - + mo_file = + grub_malloc (grub_strlen (locale_dir) + grub_strlen ("/") + + grub_strlen (lang) + grub_strlen (".mo") + 1); + /* Warning: if changing some paths in the below line, change the grub_malloc contents below. */ - + grub_sprintf (mo_file, "%s/%s.mo", locale_dir, lang); - grub_dprintf("gettext", "Will try to open file: %s " ,mo_file); + fd_mo = grub_mofile_open (mo_file); - fd_mo = grub_mofile_open(mo_file); - grub_free (mo_file); + /* Will try adding .gz as well. */ + if (fd_mo == NULL) + { + grub_sprintf (mo_file, "%s.gz", mo_file); + fd_mo = grub_mofile_open (mo_file); + } if (fd_mo) { - grub_gettext_offsetoriginal = grub_gettext_get_info(GETTEXT_OFFSET_ORIGINAL); - grub_gettext_max = grub_gettext_get_info(GETTEXT_NUMBER_OF_STRINGS); + grub_gettext_offsetoriginal = + grub_gettext_get_info (GETTEXT_OFFSET_ORIGINAL); + grub_gettext_max = grub_gettext_get_info (GETTEXT_NUMBER_OF_STRINGS); grub_gettext_original = grub_gettext; grub_gettext = grub_gettext_translate; } } -static char* -grub_gettext_env_write_lang (struct grub_env_var *var __attribute__ ((unused)), - const char *val) +static char * +grub_gettext_env_write_lang (struct grub_env_var *var + __attribute__ ((unused)), const char *val) { grub_gettext_init_ext (val); return grub_strdup (val); } -GRUB_MOD_INIT(gettext) +GRUB_MOD_INIT (gettext) { - (void)mod; /* To stop warning. */ - + (void) mod; /* To stop warning. */ + const char *lang; - lang = grub_env_get ("lang"); + lang = grub_env_get ("lang"); grub_gettext_init_ext (lang); - /* Testing: - grub_register_command ("_", grub_cmd_translate, GRUB_COMMAND_FLAG_BOTH, - "_", "internalization support trans", 0); - */ - /* Reload .mo file information if lang changes. */ grub_register_variable_hook ("lang", NULL, grub_gettext_env_write_lang); @@ -277,10 +276,10 @@ GRUB_MOD_INIT(gettext) grub_env_export ("lang"); } -GRUB_MOD_FINI(gettext) +GRUB_MOD_FINI (gettext) { if (fd_mo != 0) - grub_file_close(fd_mo); + grub_file_close (fd_mo); grub_gettext = grub_gettext_original; } diff --git a/include/grub/file.h b/include/grub/file.h index 2aacf936f..6625e045d 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -55,6 +55,8 @@ grub_file_t EXPORT_FUNC(grub_file_open) (const char *name); grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf, grub_size_t len); grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset); +grub_ssize_t EXPORT_FUNC(grub_file_pread) (grub_file_t file, void *buf, grub_size_t len, grub_off_t offset); + grub_err_t EXPORT_FUNC(grub_file_close) (grub_file_t file); static inline grub_off_t diff --git a/include/grub/i18n.h b/include/grub/i18n.h index e436f6e28..96317fd33 100644 --- a/include/grub/i18n.h +++ b/include/grub/i18n.h @@ -24,7 +24,7 @@ # include # define _(str) gettext(str) #else -# define _(str) str +# define _(str) grub_gettext(str) #endif #endif /* GRUB_I18N_H */ diff --git a/include/grub/i18n_grub.h b/include/grub/i18n_grub.h deleted file mode 100644 index ed3382568..000000000 --- a/include/grub/i18n_grub.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_I18N_GRUB_H -#define GRUB_I18N_GRUB_H 1 - -# define _(str) grub_gettext(str) - -#endif /* GRUB_I18N_GRUB_H */ diff --git a/kern/file.c b/kern/file.c index f713acbca..00f69f05d 100644 --- a/kern/file.c +++ b/kern/file.c @@ -164,3 +164,13 @@ grub_file_seek (grub_file_t file, grub_off_t offset) file->offset = offset; return old; } + +grub_ssize_t +grub_file_pread (grub_file_t file, void *buf, grub_size_t len, grub_off_t offset) +{ + if (grub_file_seek (file, offset) == (grub_off_t)-1) + { + return -1; + } + return grub_file_read (file, buf, len); +} diff --git a/normal/menu_text.c b/normal/menu_text.c index 66a0bcfb4..fe86195dc 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include /* Time to delay after displaying an error message about a default/fallback entry failing to boot. */ @@ -267,7 +267,7 @@ 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. "); char *msg_end = grub_strchr (msg, '%'); grub_gotoxy (second_stage ? (msg_end - msg) : 0, GRUB_TERM_HEIGHT - 3); diff --git a/po/ca.po b/po/ca.po index 02cfe3751..bf4f89c30 100644 --- a/po/ca.po +++ b/po/ca.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: GNU GRUB\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-11-19 21:37+0000\n" +"POT-Creation-Date: 2009-11-22 11:45+0000\n" "PO-Revision-Date: 2009-11-17 12:26+0100\n" "Last-Translator: Robert Millan \n" "Language-Team: None \n" @@ -891,6 +891,11 @@ msgstr "" "\n" " Utilitzeu les tecles %C i %C per a seleccionar l'entrada.\n" +#: normal/menu_text.c:270 +#, c-format +msgid " The highlighted entry will be booted automatically in %ds. " +msgstr " L entrada seleccionada sera arrancada automaticament en %ds. " + #: util/grub.d/10_kfreebsd.in:40 msgid "%s, with kFreeBSD %s" msgstr "" diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index d1e25dfe3..96352cdae 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -103,11 +103,13 @@ EOF esac # Gettext variables and module -cat << EOF +if [ "x${LANG}" != "xC" ] ; then + cat << EOF set locale_dir=${locale_dir} set lang=${grub_lang} insmod gettext EOF +fi if [ "x${GRUB_HIDDEN_TIMEOUT}" != "x" ] ; then if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then From e5fb78c684240e2db5e38dac1b93d1c19b142dfe Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 12:50:46 +0000 Subject: [PATCH 08/20] This commit is the same than gettext08.patch (see mailing list) --- ChangeLog.gettext | 29 ++++++++++++++++------------- conf/common.rmk | 2 +- gettext/gettext.c | 23 +++++++++++++++++------ include/grub/file.h | 2 -- include/grub/misc.h | 2 +- kern/file.c | 10 ---------- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/ChangeLog.gettext b/ChangeLog.gettext index 6bce3f38b..a62869861 100644 --- a/ChangeLog.gettext +++ b/ChangeLog.gettext @@ -1,15 +1,18 @@ YYYY-MM-DD Carles Pina i Estany - * conf/common.rmk: Add grub-gettext_lib target, dependency and - SOURCES, CFLAGS, LDFLAGS - * gettext/gettext.c: New file with gettext implementation - * include/grub/i18n_grub.h: New file with grub_gettext macros - * include/grub/misc.h: Define macro _(char *s). Declare - grub_gettext_dummy and grub_gettext - * kern/misc.c: Define grub_gettext symbol implementation of the - grub_gettext_dummy function - * normal/menu_text.c: Gettextize one message in print_message - * po/POTFILES: Adds normal/menu_text.c - * po/ca.po: Adds the new string - * util/grub.d/00_header.in: defines gettext variables and loads - the module + * conf/common.rmk: Add grub-gettext_lib target and updates + lib_DATA and CLEANFILES. Adds gettext.mod SOURCES, CFLAGS, + LDFLAGS. + * gettext/gettext.c: New file. (Reads mo files). + * include/grub/file.h (grub_file_pread): New prototype. + * include/grub/i18n.h (_): New prototype. + * include/grub/misc.h (grub_gettext_dummy, grub_gettext): New + prototypes. + * kern/misc.c (grub_gettext_dummy): New function. + * menu/menu_text.c: Include . + * menu/menu_text.c (print_timeout): Gettexttize string. + * menu/menu_text.c (print_message): Gettexttize string. + * po/POTFILES: Add `normal/menu_text.c'. + * po/ca.po: Add new translations. + * util/grub.d/00_header.in: Define locale_dir and lang. insmod + gettext module and defines locale_dir and lang in grub.cfg. diff --git a/conf/common.rmk b/conf/common.rmk index a4c3c80e8..be0543d83 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -185,7 +185,7 @@ grub-mkconfig_DATA += util/grub.d/README pkglib_MODULES += fshelp.mod fat.mod ufs1.mod ufs2.mod ext2.mod ntfs.mod \ ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod \ affs.mod sfs.mod hfsplus.mod reiserfs.mod cpio.mod tar.mod \ - udf.mod afs.mod afs_be.mod befs.mod befs_be.mod + udf.mod afs.mod afs_be.mod befs.mod befs_be.mod # For fshelp.mod. fshelp_mod_SOURCES = fs/fshelp.c diff --git a/gettext/gettext.c b/gettext/gettext.c index c488f0e50..799d8a037 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -48,12 +48,23 @@ static const char *(*grub_gettext_original) (const char *s); #define MO_MAGIC_NUMBER 0x950412de +static grub_ssize_t +grub_gettext_pread (grub_file_t file, void *buf, grub_size_t len, + grub_off_t offset) +{ + if (grub_file_seek (file, offset) == (grub_off_t) - 1) + { + return -1; + } + return grub_file_read (file, buf, len); +} + static grub_uint32_t grub_gettext_get_info (int offset) { grub_uint32_t value; - grub_file_pread (fd_mo, (char *) &value, 4, offset); + grub_gettext_pread (fd_mo, (char *) &value, 4, offset); value = grub_cpu_to_le32 (value); return value; @@ -63,7 +74,7 @@ static void grub_gettext_getstring_from_offset (grub_uint32_t offset, grub_uint32_t length, char *translation) { - grub_file_pread (fd_mo, translation, length, offset); + grub_gettext_pread (fd_mo, translation, length, offset); translation[length] = '\0'; } @@ -79,10 +90,10 @@ grub_gettext_gettranslation_from_position (int position) internal_position = offsettranslation + position * 8; - grub_file_pread (fd_mo, (char *) &length, 4, internal_position); + grub_gettext_pread (fd_mo, (char *) &length, 4, internal_position); length = grub_cpu_to_le32 (length); - grub_file_pread (fd_mo, (char *) &offset, 4, internal_position + 4); + grub_gettext_pread (fd_mo, (char *) &offset, 4, internal_position + 4); offset = grub_cpu_to_le32 (offset); translation = grub_malloc (length + 1); @@ -102,10 +113,10 @@ grub_gettext_getstring_from_position (int position) internal_position = grub_gettext_offsetoriginal + (position * 8); /* Get the length of the string i. */ - grub_file_pread (fd_mo, (char *) &length, 4, internal_position); + grub_gettext_pread (fd_mo, (char *) &length, 4, internal_position); /* Get the offset of the string i. */ - grub_file_pread (fd_mo, (char *) &offset, 4, internal_position + 4); + grub_gettext_pread (fd_mo, (char *) &offset, 4, internal_position + 4); /* Get the string i. */ original = grub_malloc (length + 1); diff --git a/include/grub/file.h b/include/grub/file.h index 6625e045d..2aacf936f 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -55,8 +55,6 @@ grub_file_t EXPORT_FUNC(grub_file_open) (const char *name); grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf, grub_size_t len); grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset); -grub_ssize_t EXPORT_FUNC(grub_file_pread) (grub_file_t file, void *buf, grub_size_t len, grub_off_t offset); - grub_err_t EXPORT_FUNC(grub_file_close) (grub_file_t file); static inline grub_off_t diff --git a/include/grub/misc.h b/include/grub/misc.h index bc725f9ca..8ec8ad822 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -192,7 +192,7 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, grub_uint32_t d, grub_uint32_t *r); const char *EXPORT_FUNC(grub_gettext_dummy) (const char *s); -extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s);// = grub_gettext_dummy; +extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s); #ifdef NEED_ENABLE_EXECUTE_STACK void EXPORT_FUNC(__enable_execute_stack) (void *addr); diff --git a/kern/file.c b/kern/file.c index 00f69f05d..f713acbca 100644 --- a/kern/file.c +++ b/kern/file.c @@ -164,13 +164,3 @@ grub_file_seek (grub_file_t file, grub_off_t offset) file->offset = offset; return old; } - -grub_ssize_t -grub_file_pread (grub_file_t file, void *buf, grub_size_t len, grub_off_t offset) -{ - if (grub_file_seek (file, offset) == (grub_off_t)-1) - { - return -1; - } - return grub_file_read (file, buf, len); -} From 938d89c04d905b185eed012b7813839acacec52e Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 13:01:49 +0000 Subject: [PATCH 09/20] Corrects Catalan translation --- po/ca.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/po/ca.po b/po/ca.po index bf4f89c30..750574847 100644 --- a/po/ca.po +++ b/po/ca.po @@ -63,7 +63,7 @@ msgstr "" #: util/i386/pc/grub-mkimage.c:321 util/i386/pc/grub-setup.c:587 #, c-format msgid "Try ``%s --help'' for more information.\n" -msgstr "Proveu «%s --help» per a obtenir més informació.\n" +msgstr "Proveu «%s --help» per a obtenir més informació.\n" #: util/i386/pc/grub-mkimage.c:323 #, c-format @@ -894,7 +894,7 @@ msgstr "" #: normal/menu_text.c:270 #, c-format msgid " The highlighted entry will be booted automatically in %ds. " -msgstr " L entrada seleccionada sera arrancada automaticament en %ds. " +msgstr " L' entrada seleccionada serà arrancada automàticament en %ds. " #: util/grub.d/10_kfreebsd.in:40 msgid "%s, with kFreeBSD %s" From c505aa627f4e9cc43d72d7f2516d91c1f6c25b2d Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 16:57:17 +0000 Subject: [PATCH 10/20] Removes a debug variable (new_fd) --- gettext/gettext.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/gettext/gettext.c b/gettext/gettext.c index 799d8a037..355bb75a0 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -175,22 +175,19 @@ grub_mofile_open (const char *filename) { int unsigned magic; int version; - grub_file_t new_fd; /* Using fd_mo and not another variable because it's needed for grub_gettext_get_info. */ - new_fd = grub_gzfile_open (filename, 1); + fd_mo = grub_gzfile_open (filename, 1); grub_errno = GRUB_ERR_NONE; - if (!new_fd) + if (!fd_mo) { - grub_dprintf ("gettext: Cannot read %s", filename); + grub_dprintf ("gettext", "Cannot read %s", filename); return 0; } - fd_mo = new_fd; - magic = grub_gettext_get_info (GETTEXT_MAGIC_NUMBER); if (magic != MO_MAGIC_NUMBER) From 30144059239f9e3475349e2d0e9a5e5092faf0f1 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 16:59:20 +0000 Subject: [PATCH 11/20] Changes catalan strings like it was before (test) --- po/ca.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/ca.po b/po/ca.po index 750574847..e0e6e4d06 100644 --- a/po/ca.po +++ b/po/ca.po @@ -894,7 +894,7 @@ msgstr "" #: normal/menu_text.c:270 #, c-format msgid " The highlighted entry will be booted automatically in %ds. " -msgstr " L' entrada seleccionada serà arrancada automàticament en %ds. " +msgstr " L' entrada seleccionada sera arrancada automaticament en %ds. " #: util/grub.d/10_kfreebsd.in:40 msgid "%s, with kFreeBSD %s" From b6c871b0d7879f1848d70ebde302e453a6ca50a2 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 18:58:19 +0000 Subject: [PATCH 12/20] Some more changes... --- gettext/gettext.c | 21 +++++++++++++++++++-- po/ca.po | 6 +++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/gettext/gettext.c b/gettext/gettext.c index 355bb75a0..46ceb3432 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -184,7 +184,7 @@ grub_mofile_open (const char *filename) if (!fd_mo) { - grub_dprintf ("gettext", "Cannot read %s", filename); + grub_dprintf ("gettext", "Cannot read %s\n", filename); return 0; } @@ -204,7 +204,7 @@ grub_mofile_open (const char *filename) if (version != 0) { grub_error (GRUB_ERR_BAD_FILE_TYPE, - "mo: invalid mo version in file: %s", filename); + "mo: invalid mo version in file: %s\n", filename); fd_mo = 0; return 0; } @@ -267,6 +267,19 @@ grub_gettext_env_write_lang (struct grub_env_var *var return grub_strdup (val); } +static grub_err_t +grub_cmd_translate (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) +{ + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "text to translate required"); + + const char *translation; + translation = grub_gettext_translate (args[0]); + grub_printf ("%s\n", translation); + return 0; +} + GRUB_MOD_INIT (gettext) { (void) mod; /* To stop warning. */ @@ -277,6 +290,10 @@ GRUB_MOD_INIT (gettext) grub_gettext_init_ext (lang); + grub_register_command_p1 ("gettext", grub_cmd_translate, + "gettext STRING", + "Translates the string with the current settings."); + /* Reload .mo file information if lang changes. */ grub_register_variable_hook ("lang", NULL, grub_gettext_env_write_lang); diff --git a/po/ca.po b/po/ca.po index e0e6e4d06..12d57b0af 100644 --- a/po/ca.po +++ b/po/ca.po @@ -63,7 +63,7 @@ msgstr "" #: util/i386/pc/grub-mkimage.c:321 util/i386/pc/grub-setup.c:587 #, c-format msgid "Try ``%s --help'' for more information.\n" -msgstr "Proveu «%s --help» per a obtenir més informació.\n" +msgstr "Proveu «%s --help» per a obtenir més informació.\n" #: util/i386/pc/grub-mkimage.c:323 #, c-format @@ -889,12 +889,12 @@ msgid "" " Use the %C and %C keys to select which entry is highlighted.\n" msgstr "" "\n" -" Utilitzeu les tecles %C i %C per a seleccionar l'entrada.\n" +" Utilitzeu les tecles %C i %C per a seleccionar l'entrada ressaltada.\n" #: normal/menu_text.c:270 #, c-format msgid " The highlighted entry will be booted automatically in %ds. " -msgstr " L' entrada seleccionada sera arrancada automaticament en %ds. " +msgstr " L' entrada seleccionada arrencarà automàticament en %ds. " #: util/grub.d/10_kfreebsd.in:40 msgid "%s, with kFreeBSD %s" From 6e2621b9ffc088b54a859337d463b01de607c662 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 21:41:33 +0000 Subject: [PATCH 13/20] Final touches (don't gettextize a string, chang setted by set) --- gettext/gettext.c | 2 +- normal/menu_text.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gettext/gettext.c b/gettext/gettext.c index 46ceb3432..5c1279dc3 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -221,7 +221,7 @@ grub_gettext_init_ext (const char *lang) locale_dir = grub_env_get ("locale_dir"); if (locale_dir == NULL) { - grub_printf ("locale_dir variable is not setted up."); + grub_printf ("locale_dir variable is not set up."); return; } diff --git a/normal/menu_text.c b/normal/menu_text.c index fe86195dc..4ff22e928 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -267,7 +267,7 @@ print_timeout (int timeout, int offset, int second_stage) { /* NOTE: Do not remove the trailing space characters. They are required to clear the line. */ - const char *msg = _(" The highlighted entry will be booted automatically in %ds. "); + char *msg = " The highlighted entry will be booted automatically in %ds. "; char *msg_end = grub_strchr (msg, '%'); grub_gotoxy (second_stage ? (msg_end - msg) : 0, GRUB_TERM_HEIGHT - 3); From 347687cf6e51c424c26a71ccff87b1019f4cab3c Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 21:42:28 +0000 Subject: [PATCH 14/20] Removes the non-gettext string --- po/ca.po | 5 ----- 1 file changed, 5 deletions(-) diff --git a/po/ca.po b/po/ca.po index 12d57b0af..509ea3c7d 100644 --- a/po/ca.po +++ b/po/ca.po @@ -891,11 +891,6 @@ msgstr "" "\n" " Utilitzeu les tecles %C i %C per a seleccionar l'entrada ressaltada.\n" -#: normal/menu_text.c:270 -#, c-format -msgid " The highlighted entry will be booted automatically in %ds. " -msgstr " L' entrada seleccionada arrencarà automàticament en %ds. " - #: util/grub.d/10_kfreebsd.in:40 msgid "%s, with kFreeBSD %s" msgstr "" From 4baf87d9e44f10c3ab1fb287f77edf7d681734b6 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 21:45:40 +0000 Subject: [PATCH 15/20] merging to trunk... --- ChangeLog | 19 +++++++++++++++++++ ChangeLog.gettext | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-) delete mode 100644 ChangeLog.gettext diff --git a/ChangeLog b/ChangeLog index 4a26413d4..d9f2cee2a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2009-11-22 Carles Pina i Estany + + * conf/common.rmk: Add grub-gettext_lib target and updates + lib_DATA and CLEANFILES. Adds gettext.mod SOURCES, CFLAGS, + LDFLAGS. + * gettext/gettext.c: New file. (Reads mo files). + * include/grub/file.h (grub_file_pread): New prototype. + * include/grub/i18n.h (_): New prototype. + * include/grub/misc.h (grub_gettext_dummy, grub_gettext): New + prototypes. + * kern/misc.c (grub_gettext_dummy): New function. + * menu/menu_text.c: Include . + * menu/menu_text.c (print_timeout): Gettexttize string. + * menu/menu_text.c (print_message): Gettexttize string. + * po/POTFILES: Add `normal/menu_text.c'. + * po/ca.po: Add new translations. + * util/grub.d/00_header.in: Define locale_dir and lang. insmod + gettext module and defines locale_dir and lang in grub.cfg. + 2009-11-22 Robert Millan * util/i386/pc/grub-mkimage.c: Ungettextize grub_util_info() strings. diff --git a/ChangeLog.gettext b/ChangeLog.gettext deleted file mode 100644 index a62869861..000000000 --- a/ChangeLog.gettext +++ /dev/null @@ -1,18 +0,0 @@ -YYYY-MM-DD Carles Pina i Estany - - * conf/common.rmk: Add grub-gettext_lib target and updates - lib_DATA and CLEANFILES. Adds gettext.mod SOURCES, CFLAGS, - LDFLAGS. - * gettext/gettext.c: New file. (Reads mo files). - * include/grub/file.h (grub_file_pread): New prototype. - * include/grub/i18n.h (_): New prototype. - * include/grub/misc.h (grub_gettext_dummy, grub_gettext): New - prototypes. - * kern/misc.c (grub_gettext_dummy): New function. - * menu/menu_text.c: Include . - * menu/menu_text.c (print_timeout): Gettexttize string. - * menu/menu_text.c (print_message): Gettexttize string. - * po/POTFILES: Add `normal/menu_text.c'. - * po/ca.po: Add new translations. - * util/grub.d/00_header.in: Define locale_dir and lang. insmod - gettext module and defines locale_dir and lang in grub.cfg. From 4d1f668fd9be725d9a5cac6209505ca9b113e1f9 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 22:24:54 +0000 Subject: [PATCH 16/20] 2009-11-22 Carles Pina i Estany * normal/menu_text.c: Gettexttize but not print_timeout function. * normal/main.c: Gettexttize. * normal/menu_entry.c: Likewise. --- ChangeLog.gettext2 | 5 +++++ normal/main.c | 5 +++-- normal/menu_entry.c | 5 +++-- normal/menu_text.c | 20 ++++++++++---------- 4 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 ChangeLog.gettext2 diff --git a/ChangeLog.gettext2 b/ChangeLog.gettext2 new file mode 100644 index 000000000..0aee7e2e4 --- /dev/null +++ b/ChangeLog.gettext2 @@ -0,0 +1,5 @@ +2009-11-22 Carles Pina i Estany + + * normal/menu_text.c: Gettexttize but not print_timeout function. + * normal/main.c: Gettexttize. + * normal/menu_entry.c: Likewise. diff --git a/normal/main.c b/normal/main.c index 748eef805..afe3667f3 100644 --- a/normal/main.c +++ b/normal/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #define GRUB_DEFAULT_HISTORY_SIZE 50 @@ -508,10 +509,10 @@ grub_normal_reader_init (void) grub_normal_init_page (); grub_setcursor (1); - grub_printf ("\ + grub_printf (_("\ [ Minimal BASH-like line editing is supported. For the first word, TAB\n\ lists possible command completions. Anywhere else TAB lists possible\n\ - device/file completions.%s ]\n\n", + device/file completions.%s ]\n\n"), reader_nested ? " ESC at any time exits." : ""); return 0; diff --git a/normal/menu_entry.c b/normal/menu_entry.c index 75a63779f..7478c33ae 100644 --- a/normal/menu_entry.c +++ b/normal/menu_entry.c @@ -24,6 +24,7 @@ #include #include #include +#include enum update_mode { @@ -996,7 +997,7 @@ run (struct screen *screen) } grub_cls (); - grub_printf (" Booting a command list\n\n"); + grub_printf (_(" Booting a command list\n\n")); /* Execute the script, line for line. */ @@ -1176,6 +1177,6 @@ grub_menu_entry_run (grub_menu_entry_t entry) grub_cls (); grub_print_error (); grub_errno = GRUB_ERR_NONE; - grub_printf ("\nPress any key to continue..."); + grub_printf (_("\nPress any key to continue...")); (void) grub_getkey (); } diff --git a/normal/menu_text.c b/normal/menu_text.c index 4ff22e928..de28205de 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -39,7 +39,7 @@ static grub_uint8_t grub_color_menu_highlight; void grub_wait_after_message (void) { - grub_printf ("\nPress any key to continue..."); + grub_printf (_("\nPress any key to continue...")); (void) grub_getkey (); grub_putchar ('\n'); } @@ -87,22 +87,22 @@ print_message (int nested, int edit) if (edit) { - grub_printf ("\n\ + grub_printf (_("\n\ 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_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); - grub_printf ("\ + 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_printf (_("\n\ + ESC to return previous menu.")); } } @@ -517,7 +517,7 @@ 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\'\n\n"), entry->title); } /* Callback invoked when a default menu entry executed because of a timeout @@ -527,7 +527,7 @@ 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_printf (_("\n Falling back to \'%s\'\n\n"), entry->title); grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS); } @@ -541,7 +541,7 @@ notify_execution_failure (void *userdata __attribute__((unused))) grub_print_error (); grub_errno = GRUB_ERR_NONE; } - grub_printf ("\n Failed to boot default entries.\n"); + grub_printf (_("\n Failed to boot default entries.\n")); grub_wait_after_message (); } From 9874f057590a90c39fbafd6faae768157da70200 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Sun, 22 Nov 2009 23:41:06 +0000 Subject: [PATCH 17/20] 2009-11-22 Carles Pina i Estany * normal/menu_text.c (get_spaces): New function. (print_timeout): Gettextize, add spaces to the localized string. --- normal/menu_text.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/normal/menu_text.c b/normal/menu_text.c index de28205de..524b6a7e9 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -262,12 +262,34 @@ get_entry_number (const char *name) 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 Date: Mon, 23 Nov 2009 20:22:36 +0000 Subject: [PATCH 18/20] Uncommits the last commits (to make the new merge with trunk easier) --- ChangeLog | 19 ------------------ normal/main.c | 5 +++-- normal/menu_entry.c | 5 +++-- normal/menu_text.c | 48 +++++++++++++++++++++++++++++++++------------ 4 files changed, 41 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index d9f2cee2a..4a26413d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,22 +1,3 @@ -2009-11-22 Carles Pina i Estany - - * conf/common.rmk: Add grub-gettext_lib target and updates - lib_DATA and CLEANFILES. Adds gettext.mod SOURCES, CFLAGS, - LDFLAGS. - * gettext/gettext.c: New file. (Reads mo files). - * include/grub/file.h (grub_file_pread): New prototype. - * include/grub/i18n.h (_): New prototype. - * include/grub/misc.h (grub_gettext_dummy, grub_gettext): New - prototypes. - * kern/misc.c (grub_gettext_dummy): New function. - * menu/menu_text.c: Include . - * menu/menu_text.c (print_timeout): Gettexttize string. - * menu/menu_text.c (print_message): Gettexttize string. - * po/POTFILES: Add `normal/menu_text.c'. - * po/ca.po: Add new translations. - * util/grub.d/00_header.in: Define locale_dir and lang. insmod - gettext module and defines locale_dir and lang in grub.cfg. - 2009-11-22 Robert Millan * util/i386/pc/grub-mkimage.c: Ungettextize grub_util_info() strings. diff --git a/normal/main.c b/normal/main.c index 748eef805..afe3667f3 100644 --- a/normal/main.c +++ b/normal/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #define GRUB_DEFAULT_HISTORY_SIZE 50 @@ -508,10 +509,10 @@ grub_normal_reader_init (void) grub_normal_init_page (); grub_setcursor (1); - grub_printf ("\ + grub_printf (_("\ [ Minimal BASH-like line editing is supported. For the first word, TAB\n\ lists possible command completions. Anywhere else TAB lists possible\n\ - device/file completions.%s ]\n\n", + device/file completions.%s ]\n\n"), reader_nested ? " ESC at any time exits." : ""); return 0; diff --git a/normal/menu_entry.c b/normal/menu_entry.c index 75a63779f..7478c33ae 100644 --- a/normal/menu_entry.c +++ b/normal/menu_entry.c @@ -24,6 +24,7 @@ #include #include #include +#include enum update_mode { @@ -996,7 +997,7 @@ run (struct screen *screen) } grub_cls (); - grub_printf (" Booting a command list\n\n"); + grub_printf (_(" Booting a command list\n\n")); /* Execute the script, line for line. */ @@ -1176,6 +1177,6 @@ grub_menu_entry_run (grub_menu_entry_t entry) grub_cls (); grub_print_error (); grub_errno = GRUB_ERR_NONE; - grub_printf ("\nPress any key to continue..."); + grub_printf (_("\nPress any key to continue...")); (void) grub_getkey (); } diff --git a/normal/menu_text.c b/normal/menu_text.c index 4ff22e928..524b6a7e9 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -39,7 +39,7 @@ static grub_uint8_t grub_color_menu_highlight; void grub_wait_after_message (void) { - grub_printf ("\nPress any key to continue..."); + grub_printf (_("\nPress any key to continue...")); (void) grub_getkey (); grub_putchar ('\n'); } @@ -87,22 +87,22 @@ print_message (int nested, int edit) if (edit) { - grub_printf ("\n\ + grub_printf (_("\n\ 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_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); - grub_printf ("\ + 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_printf (_("\n\ + ESC to return previous menu.")); } } @@ -262,12 +262,34 @@ get_entry_number (const char *name) return entry; } +static char* +get_spaces (int number_spaces) +{ + char* spaces = grub_malloc(number_spaces + 1); + int i; + + spaces[0] = '\0'; + + for (i=0;ititle); + grub_printf (_(" Booting \'%s\'\n\n"), entry->title); } /* Callback invoked when a default menu entry executed because of a timeout @@ -527,7 +549,7 @@ 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_printf (_("\n Falling back to \'%s\'\n\n"), entry->title); grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS); } @@ -541,7 +563,7 @@ notify_execution_failure (void *userdata __attribute__((unused))) grub_print_error (); grub_errno = GRUB_ERR_NONE; } - grub_printf ("\n Failed to boot default entries.\n"); + grub_printf (_("\n Failed to boot default entries.\n")); grub_wait_after_message (); } From 3db5183c2caf9135bc623ae7ff1239fbb11f6df7 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Mon, 23 Nov 2009 20:47:25 +0000 Subject: [PATCH 19/20] Adds gettext note in NEWS. --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 7c29cc948..bf7492c6d 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ New in 1.97 - : +* Add support for gettext. + * Add support for loading XNU (MacOS X kernel). * ACPI override support. From c3ea6bd46624d1724bab4528330d5f27f4b692c4 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Mon, 23 Nov 2009 20:59:24 +0000 Subject: [PATCH 20/20] Final touches before merging --- ChangeLog | 20 +++++++++++++++++++ normal/menu_text.c | 48 +++++++++++++--------------------------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17b770968..da59ff5da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2009-11-22 Carles Pina i Estany + + * conf/common.rmk: Add grub-gettext_lib target and updates + lib_DATA and CLEANFILES. Adds gettext.mod SOURCES, CFLAGS, + LDFLAGS. + * gettext/gettext.c: New file. (Reads mo files). + * include/grub/file.h (grub_file_pread): New prototype. + * include/grub/i18n.h (_): New prototype. + * include/grub/misc.h (grub_gettext_dummy, grub_gettext): New + prototypes. + * kern/misc.c (grub_gettext_dummy): New function. + * normal/menu_text.c: Include . + * normal/menu_text.c (print_timeout): Gettexttize string. + * normal/menu_text.c (print_message): Gettexttize string. + * po/POTFILES: Add `normal/menu_text.c'. + * po/ca.po: Add new translations. + * util/grub.d/00_header.in: Define locale_dir and lang. insmod + gettext module and defines locale_dir and lang in grub.cfg. + * NEWS: Add gettext support. + 2009-11-23 Robert Millan * util/hostdisk.c: Include `'. diff --git a/normal/menu_text.c b/normal/menu_text.c index 524b6a7e9..4ff22e928 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -39,7 +39,7 @@ static grub_uint8_t grub_color_menu_highlight; void grub_wait_after_message (void) { - grub_printf (_("\nPress any key to continue...")); + grub_printf ("\nPress any key to continue..."); (void) grub_getkey (); grub_putchar ('\n'); } @@ -87,22 +87,22 @@ print_message (int nested, int edit) if (edit) { - grub_printf (_("\n\ + grub_printf ("\n\ 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_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); - grub_printf (_("\ + 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_printf ("\n\ + ESC to return previous menu."); } } @@ -262,34 +262,12 @@ get_entry_number (const char *name) return entry; } -static char* -get_spaces (int number_spaces) -{ - char* spaces = grub_malloc(number_spaces + 1); - int i; - - spaces[0] = '\0'; - - for (i=0;ititle); + grub_printf (" Booting \'%s\'\n\n", entry->title); } /* Callback invoked when a default menu entry executed because of a timeout @@ -549,7 +527,7 @@ 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_printf ("\n Falling back to \'%s\'\n\n", entry->title); grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS); } @@ -563,7 +541,7 @@ notify_execution_failure (void *userdata __attribute__((unused))) grub_print_error (); grub_errno = GRUB_ERR_NONE; } - grub_printf (_("\n Failed to boot default entries.\n")); + grub_printf ("\n Failed to boot default entries.\n"); grub_wait_after_message (); }