Add a --locale-directory option to grub-install and related tools.

* include/grub/util/install.h (GRUB_INSTALL_OPTIONS): Add
--locale-directory option.
(enum grub_install_options): Add
GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY.
* util/grub-install-common.c (grub_install_help_filter): Handle
GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY.
(grub_install_parse): Likewise.
(get_localedir): New function to check for a user-provided option
before trying grub_util_get_localedir.
(copy_locales): Use get_localedir rather than
grub_util_get_localedir.  Handle differing locale directory layouts.
(grub_install_copy_files): Likewise.
This commit is contained in:
Colin Watson 2013-11-25 18:04:50 +00:00
parent 61e1b9a49d
commit 07e3b04742
3 changed files with 56 additions and 5 deletions

View file

@ -1,3 +1,21 @@
2013-11-25 Colin Watson <cjwatson@ubuntu.com>
2013-11-25 Vladimir Serbinenko <phcoder@gmail.com>
Add a --locale-directory option to grub-install and related tools.
* include/grub/util/install.h (GRUB_INSTALL_OPTIONS): Add
--locale-directory option.
(enum grub_install_options): Add
GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY.
* util/grub-install-common.c (grub_install_help_filter): Handle
GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY.
(grub_install_parse): Likewise.
(get_localedir): New function to check for a user-provided option
before trying grub_util_get_localedir.
(copy_locales): Use get_localedir rather than
grub_util_get_localedir. Handle differing locale directory layouts.
(grub_install_copy_files): Likewise.
2013-11-25 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/osdep/unix/platform.c (get_ofpathname): Trim ending newline.

View file

@ -47,6 +47,9 @@
{ "override-directory", GRUB_INSTALL_OPTIONS_DIRECTORY2, \
N_("DIR"), OPTION_HIDDEN, \
N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
{ "locale-directory", GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY, \
N_("DIR"), 0, \
N_("use translations under DIR [default=%s]"), 1 }, \
{ "grub-mkimage", GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE, \
"FILE", OPTION_HIDDEN, 0, 1 }, \
/* TRANSLATORS: "embed" is a verb (command description). "*/ \
@ -102,6 +105,7 @@ enum grub_install_options {
GRUB_INSTALL_OPTIONS_INSTALL_LOCALES,
GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS,
GRUB_INSTALL_OPTIONS_DIRECTORY2,
GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY,
GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE
};

View file

@ -58,6 +58,8 @@ grub_install_help_filter (int key, const char *text,
case GRUB_INSTALL_OPTIONS_DIRECTORY:
case GRUB_INSTALL_OPTIONS_DIRECTORY2:
return xasprintf(text, grub_util_get_pkglibdir ());
case GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY:
return xasprintf(text, grub_util_get_localedir ());
default:
return (char *) text;
}
@ -217,6 +219,7 @@ struct install_list install_locales = { 1, 0, 0, 0 };
struct install_list install_fonts = { 1, 0, 0, 0 };
struct install_list install_themes = { 1, 0, 0, 0 };
char *grub_install_source_directory = NULL;
char *grub_install_locale_directory = NULL;
void
grub_install_push_module (const char *val)
@ -313,6 +316,10 @@ grub_install_parse (int key, char *arg)
free (grub_install_source_directory);
grub_install_source_directory = xstrdup (arg);
return 1;
case GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY:
free (grub_install_locale_directory);
grub_install_locale_directory = xstrdup (arg);
return 1;
case GRUB_INSTALL_OPTIONS_INSTALL_MODULES:
handle_install_list (&install_modules, arg, 0);
return 1;
@ -551,12 +558,21 @@ copy_all (const char *srcd,
grub_util_fd_closedir (d);
}
static const char *
get_localedir (void)
{
if (grub_install_locale_directory)
return grub_install_locale_directory;
else
return grub_util_get_localedir ();
}
static void
copy_locales (const char *dstd)
{
grub_util_fd_dir_t d;
grub_util_fd_dirent_t de;
const char *locale_dir = grub_util_get_localedir ();
const char *locale_dir = get_localedir ();
d = grub_util_fd_opendir (locale_dir);
if (!d)
@ -570,13 +586,26 @@ copy_locales (const char *dstd)
{
char *srcf;
char *dstf;
char *ext;
if (strcmp (de->d_name, ".") == 0)
continue;
if (strcmp (de->d_name, "..") == 0)
continue;
srcf = grub_util_path_concat_ext (4, locale_dir, de->d_name,
"LC_MESSAGES", PACKAGE, ".mo");
dstf = grub_util_path_concat_ext (2, dstd, de->d_name, ".mo");
ext = grub_strrchr (de->d_name, '.');
if (ext && (grub_strcmp (ext, ".mo") == 0
|| grub_strcmp (ext, ".gmo") == 0))
{
srcf = grub_util_path_concat (2, locale_dir, de->d_name);
dstf = grub_util_path_concat (2, dstd, de->d_name);
ext = grub_strrchr (dstf, '.');
grub_strcpy (ext, ".mo");
}
else
{
srcf = grub_util_path_concat_ext (4, locale_dir, de->d_name,
"LC_MESSAGES", PACKAGE, ".mo");
dstf = grub_util_path_concat_ext (2, dstd, de->d_name, ".mo");
}
grub_install_compress_file (srcf, dstf, 0);
free (srcf);
free (dstf);
@ -708,7 +737,7 @@ grub_install_copy_files (const char *src,
}
else
{
const char *locale_dir = grub_util_get_localedir ();
const char *locale_dir = get_localedir ();
for (i = 0; i < install_locales.n_entries; i++)
{