Different changes following Robert's email 20091121230904.GA29740@thorin
This commit is contained in:
parent
ee99edc809
commit
0648f857ea
8 changed files with 107 additions and 113 deletions
|
@ -25,6 +25,7 @@
|
|||
#include <grub/normal.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/gzio.h>
|
||||
|
||||
/*
|
||||
.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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
# include <libintl.h>
|
||||
# define _(str) gettext(str)
|
||||
#else
|
||||
# define _(str) str
|
||||
# define _(str) grub_gettext(str)
|
||||
#endif
|
||||
|
||||
#endif /* GRUB_I18N_H */
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_I18N_GRUB_H
|
||||
#define GRUB_I18N_GRUB_H 1
|
||||
|
||||
# define _(str) grub_gettext(str)
|
||||
|
||||
#endif /* GRUB_I18N_GRUB_H */
|
10
kern/file.c
10
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);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <grub/time.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/menu_viewer.h>
|
||||
#include <grub/i18n_grub.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
/* 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);
|
||||
|
|
7
po/ca.po
7
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 <rmh.grub@aybabtu.com>\n"
|
||||
"Language-Team: None <no-team-yet@li.org>\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 ""
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue