Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions gettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down
10 changes: 10 additions & 0 deletions t/t0203-gettext-setlocale-sanity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading