* [PATCH] gettext ll_CC -> ll fallback
@ 2010-12-09 21:55 Colin Watson
2010-12-10 13:45 ` Colin Watson
0 siblings, 1 reply; 2+ messages in thread
From: Colin Watson @ 2010-12-09 21:55 UTC (permalink / raw)
To: grub-devel
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 <cjwatson@ubuntu.com>
* 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 @@ prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
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 [cjwatson@ubuntu.com]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gettext ll_CC -> ll fallback
2010-12-09 21:55 [PATCH] gettext ll_CC -> ll fallback Colin Watson
@ 2010-12-10 13:45 ` Colin Watson
0 siblings, 0 replies; 2+ messages in thread
From: Colin Watson @ 2010-12-10 13:45 UTC (permalink / raw)
To: grub-devel
On Thu, Dec 09, 2010 at 09:55:51PM +0000, Colin Watson wrote:
> 2010-12-09 Colin Watson <cjwatson@ubuntu.com>
>
> * 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.
Committed following an ack on IRC from Vladimir.
--
Colin Watson [cjwatson@ubuntu.com]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-12-10 13:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-09 21:55 [PATCH] gettext ll_CC -> ll fallback Colin Watson
2010-12-10 13:45 ` Colin Watson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).