[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] gettext ll_CC -> ll fallback
From: |
Colin Watson |
Subject: |
[PATCH] gettext ll_CC -> ll fallback |
Date: |
Thu, 9 Dec 2010 21:55:51 +0000 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
This patch brings GRUB's gettext module a bit closer to the normal
semantics of GNU gettext. For background, see:
https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/686788
https://code.launchpad.net/~superm1/ubuntu/natty/grub2/chinese-support/+merge/43023
In short, languages which have ll_CC.mo rather than ll.mo don't work
right now. Those languages are typically ones where the dialect or
writing system varies a lot between the regions where it's spoken:
zh_CN/zh_TW and pt/pt_BR are the most common cases I run into. In some
cases it's reasonable to have a base ll.mo (Portuguese) whereas in other
cases it isn't (Chinese). util/grub.d/00_header.in truncates $LANG at
the first '_', so it always loses the country part of the locale.
GNU gettext first tries ll_CC, then ll, which is the right way to deal
with this. (Actually, it's a bit more complicated than that, but most
of the additional complexity is irrelevant to GRUB.) I looked at
whether util/grub.d/00_header.in should do this, but I don't think this
should be decided at grub-mkconfig time; it would be better for GRUB's
gettext module to handle the fallback logic, just as it already looks
for compressed locale files.
2010-12-09 Colin Watson <address@hidden>
* grub-core/gettext/gettext.c (grub_gettext_init_ext): Factor out
.mo/.mo.gz opening sequence to ...
(grub_mofile_open_lang): ... here.
(grub_gettext_init_ext): If opening ll_CC fails, try ll.
* util/grub.d/00_header.in (grub_lang): Include country part of
locale.
=== modified file 'grub-core/gettext/gettext.c'
--- grub-core/gettext/gettext.c 2010-09-30 19:07:51 +0000
+++ grub-core/gettext/gettext.c 2010-12-09 21:35:56 +0000
@@ -261,24 +261,16 @@ grub_mofile_open (const char *filename)
return fd_mo;
}
+/* Returning grub_file_t would be more natural, but grub_mofile_open assigns
+ to fd_mo anyway ... */
static void
-grub_gettext_init_ext (const char *lang)
+grub_mofile_open_lang (const char *locale_dir, const char *locale)
{
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);
+ mo_file = grub_xasprintf ("%s/%s.mo", locale_dir, locale);
if (!mo_file)
return;
@@ -295,6 +287,38 @@ grub_gettext_init_ext (const char *lang)
return;
fd_mo = grub_mofile_open (mo_file);
}
+}
+
+static void
+grub_gettext_init_ext (const char *locale)
+{
+ 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;
+
+ grub_mofile_open_lang (locale_dir, locale);
+
+ /* ll_CC didn't work, so try ll. */
+ if (fd_mo == NULL)
+ {
+ char *lang = grub_strdup (locale);
+ char *underscore = grub_strchr (lang, '_');
+
+ if (underscore)
+ {
+ *underscore = '\0';
+ grub_mofile_open_lang (locale_dir, lang);
+ }
+
+ grub_free (lang);
+ }
if (fd_mo)
{
=== modified file 'util/grub.d/00_header.in'
--- util/grub.d/00_header.in 2010-09-18 23:15:44 +0000
+++ util/grub.d/00_header.in 2010-12-08 20:59:35 +0000
@@ -23,7 +23,7 @@ address@hidden@
address@hidden@
address@hidden@
locale_dir=`echo ${GRUB_PREFIX}/locale | sed ${transform}`
-grub_lang=`echo $LANG | cut -d _ -f 1`
+grub_lang=`echo $LANG | cut -d . -f 1`
. ${libdir}/grub/grub-mkconfig_lib
Thanks,
--
Colin Watson address@hidden
- [PATCH] gettext ll_CC -> ll fallback,
Colin Watson <=