diff --git a/gettext.c b/gettext.c index 8d08a61f8487dc..27a3e68e0315eb 100644 --- a/gettext.c +++ b/gettext.c @@ -102,6 +102,21 @@ static void init_gettext_charset(const char *domain) setlocale(LC_CTYPE, "C"); } +static void git_setup_gettext_no_podir(void) +{ + setlocale(LC_TIME, ""); +} + +static void git_setup_gettext_podir(const char *podir) +{ + bindtextdomain("git", podir); + setlocale(LC_MESSAGES, ""); + init_gettext_charset("git"); + textdomain("git"); + + git_gettext_enabled = 1; +} + int git_gettext_enabled = 0; void git_setup_gettext(void) @@ -112,19 +127,12 @@ void git_setup_gettext(void) if (!podir) podir = p = system_path(GIT_LOCALE_PATH); - if (!is_directory(podir)) { - free(p); - return; - } - - bindtextdomain("git", podir); - setlocale(LC_MESSAGES, ""); - setlocale(LC_TIME, ""); - init_gettext_charset("git"); - textdomain("git"); - - git_gettext_enabled = 1; + if (!is_directory(podir)) + goto done; + git_setup_gettext_no_podir(); + git_setup_gettext_podir(podir); +done: free(p); } diff --git a/t/t0203-gettext-setlocale-sanity.sh b/t/t0203-gettext-setlocale-sanity.sh index 0ce1f22eff6628..4e54ca0badb5ec 100755 --- a/t/t0203-gettext-setlocale-sanity.sh +++ b/t/t0203-gettext-setlocale-sanity.sh @@ -23,4 +23,14 @@ test_expect_success GETTEXT_LOCALE 'git show a ISO-8859-1 commit under a UTF-8 l grep -q "iso-utf8-commit" out ' +test_expect_success GETTEXT_LOCALE 'the %c date format works even without a localedir (LC_TIME)' ' + LANGUAGE=is LC_ALL="$is_IS_locale" GIT_TEXTDOMAINDIR="$PWD/nonexisting" \ + git log --pretty=format:%ad --date=format:%c HEAD^1..HEAD >actual && + + # Avoid testing the raw format (it might differ?). But + # Thursday is Fimmtudagur in Icelandic, so grepping "fim" is + # pretty certain to test that the locale was used. + grep -iF fim actual +' + test_done