gettext: handle GIT_TEXTDOMAINDIR relative to $(prefix)

On Windows, there is no single root directory. And what Git thinks is a
root directory is not a root directory at all: everything is relative to
the location where Git is installed.

To handle this situation better, let's just allow for GIT_TEXTDOMAINDIR
to be a path relative to the (runtime) prefix.

To that end, we have to switch the order in which common-main handles
argv0 and sets up gettext: in order to have access to the runtime
prefix, we need it to be inferred from argv0 already.

This patch also prepares for GIT_LOCALE_PATH to be relative to prefix,
which is the even more important fix.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2017-03-14 12:25:48 +01:00
parent 74d8ecfd37
commit 5ff388f6f2
2 changed files with 10 additions and 2 deletions

View File

@@ -32,12 +32,12 @@ int main(int argc, const char **argv)
*/
sanitize_stdfds();
git_extract_argv0_path(argv[0]);
git_setup_gettext();
attr_start();
git_extract_argv0_path(argv[0]);
restore_sigpipe_to_default();
return cmd_main(argc, argv);

View File

@@ -6,6 +6,8 @@
#include "gettext.h"
#include "strbuf.h"
#include "utf8.h"
#include "cache.h"
#include "exec_cmd.h"
#ifndef NO_GETTEXT
# include <locale.h>
@@ -158,14 +160,20 @@ static void init_gettext_charset(const char *domain)
void git_setup_gettext(void)
{
const char *podir = getenv("GIT_TEXTDOMAINDIR");
char *p = NULL;
if (!podir)
podir = GIT_LOCALE_PATH;
if (!is_absolute_path(podir))
podir = p = system_path(podir);
bindtextdomain("git", podir);
setlocale(LC_MESSAGES, "");
setlocale(LC_TIME, "");
init_gettext_charset("git");
textdomain("git");
free(p);
}
/* return the number of columns of string 's' in current locale */