gettext ll_CC -> ll fallback
PATCH 1/1 gettext ll_CC -> ll fallback
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 <[email protected]>
* 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'
gettext/gettext.c +36 -12
@@ -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'
grub.d/00_header.in +1 -1
@@ -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,
Signature · 1 line
Colin Watson [[email protected]]
Quoted 8 lines · Colin Watson
2010-12-09 Colin Watson <[email protected]>
*
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 openingll_CCfails, try ll.
* util/grub.d/00_header.in (grub_lang): Include country part of locale.
Committed following an ack on IRC from Vladimir.
Signature · 1 line
Colin Watson [[email protected]]