From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1PQoT5-0004Y2-Uw for mharc-grub-devel@gnu.org; Thu, 09 Dec 2010 16:56:04 -0500 Received: from [140.186.70.92] (port=41917 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQoT1-0004WQ-3W for grub-devel@gnu.org; Thu, 09 Dec 2010 16:56:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PQoSz-0002QO-Jx for grub-devel@gnu.org; Thu, 09 Dec 2010 16:55:58 -0500 Received: from smarthost01.mail.zen.net.uk ([212.23.3.140]:56174) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PQoSz-0002Py-CV for grub-devel@gnu.org; Thu, 09 Dec 2010 16:55:57 -0500 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost01.mail.zen.net.uk with esmtp (Exim 4.63) (envelope-from ) id 1PQoSv-00013m-4S for grub-devel@gnu.org; Thu, 09 Dec 2010 21:55:55 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 3.36 #1 (Debian)) for grub-devel@gnu.org id 1PQoSt-0002ZE-00; Thu, 09 Dec 2010 21:55:51 +0000 Date: Thu, 9 Dec 2010 21:55:51 +0000 From: Colin Watson To: grub-devel@gnu.org Message-ID: <20101209215549.GW21862@riva.ucam.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost01-IP: [82.69.40.219] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [PATCH] gettext ll_CC -> ll fallback X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Dec 2010 21:56:00 -0000 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 * 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]