Esempio n. 1
0
static void
grub_gettext_init_ext (const char *lang)
{
  char *mo_file;
  char *locale_dir;

  locale_dir = grub_env_get ("locale_dir");
  if (locale_dir == NULL)
    {
      grub_dprintf ("gettext", "locale_dir variable is not set up.\n");
      return;
    }

  fd_mo = NULL;

  /* mo_file e.g.: /boot/grub/locale/ca.mo   */

  mo_file = grub_xasprintf ("%s/%s.mo", locale_dir, lang);
  if (!mo_file)
    return;

  fd_mo = grub_mofile_open (mo_file);

  /* Will try adding .gz as well.  */
  if (fd_mo == NULL)
    {
      grub_free (mo_file);
      mo_file = grub_xasprintf ("%s.gz", mo_file);
      if (!mo_file)
	return;
      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_original = grub_gettext;
      grub_gettext = grub_gettext_translate;
    }
}
Esempio n. 2
0
/* Returning grub_file_t would be more natural, but grub_mofile_open assigns
   to fd_mo anyway ...  */
static grub_err_t
grub_mofile_open_lang (struct grub_gettext_context *ctx,
		       const char *part1, const char *part2, const char *locale)
{
  char *mo_file;
  grub_err_t err;

  /* mo_file e.g.: /boot/grub/locale/ca.mo   */

  mo_file = grub_xasprintf ("%s%s/%s.mo", part1, part2, locale);
  if (!mo_file)
    return grub_errno;

  err = grub_mofile_open (ctx, mo_file);
  grub_free (mo_file);

  /* Will try adding .gz as well.  */
  if (err)
    {
      grub_errno = GRUB_ERR_NONE;
      mo_file = grub_xasprintf ("%s%s/%s.mo.gz", part1, part2, locale);
      if (!mo_file)
	return grub_errno;
      err = grub_mofile_open (ctx, mo_file);
      grub_free (mo_file);
    }

  /* Will try adding .gmo as well.  */
  if (err)
    {
      grub_errno = GRUB_ERR_NONE;
      mo_file = grub_xasprintf ("%s%s/%s.gmo", part1, part2, locale);
      if (!mo_file)
	return grub_errno;
      err = grub_mofile_open (ctx, mo_file);
      grub_free (mo_file);
    }

  return err;
}