From 2cc2dfffd5b0fed22c602cefdc3c128feaabf8a5 Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Thu, 14 Jan 2021 13:06:31 +1100 Subject: [PATCH] Allow TEXTDOMAINDIR to specify the message catalog path --- NEWS | 4 ++++ doc/trader.6 | 8 +++++++- src/utils.c | 7 ++++++- src/utils.h | 9 +++++---- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index f19b186b..0365763e 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,10 @@ __ https://www.zap.org.au/ Version 7.16 (not yet released) ------------------------------- +Added code to allow the ``TEXTDOMAINDIR`` environment variable to specify +where compiled translations are located. Updated the documentation to +mention this new feature. + Added an application metadata file that conforms to the AppStream 0.12 specification. Updated all translations to suit, using parts of existing strings. diff --git a/doc/trader.6 b/doc/trader.6 index 66bd069e..9d5ed445 100644 --- a/doc/trader.6 +++ b/doc/trader.6 @@ -41,7 +41,7 @@ .if \n[.g] .mso www.tmac .\" .\" ********************************************************************* -.TH TRADER 6 "12th January, 2021" "Unix-like systems" +.TH TRADER 6 "14th January, 2021" "Unix-like systems" .SH NAME trader \- a game of interstellar trading .\" ********************************************************************* @@ -183,6 +183,12 @@ using \fBLC_NUMERIC\fP and monetary quantities will use or .BR setlocale (3) manual pages for more details on locale settings. +.TP +.B TEXTDOMAINDIR +If set, Star Traders will use this path as the base with which to locate +its message catalogs instead of the compiled-in path; the relevant +\fItrader.mo\fP files should be located in language-code subdirectories +(such as \fIen_AU\fP), in \fILC_MESSAGES\fP sub-subdirectories. .\" ********************************************************************* .SH FILES .TP diff --git a/src/utils.c b/src/utils.c index 4e4969b7..2fd36c7e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -586,6 +586,9 @@ extern int randi (int limit) extern void init_locale (void) { + const char *podir = getenv("TEXTDOMAINDIR"); + + // Initialise the current locale if (setlocale(LC_ALL, "") == NULL) { err_exit("could not set locale " @@ -593,7 +596,9 @@ extern void init_locale (void) } // Use correct message catalogs for the locale - bindtextdomain(PACKAGE, LOCALEDIR); + bindtextdomain( + PACKAGE, + (podir != NULL && *podir != '\0') ? podir : LOCALEDIR); textdomain(PACKAGE); } diff --git a/src/utils.h b/src/utils.h index b664403c..8482c90b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -235,10 +235,11 @@ extern int randi (int limit); Returns: (nothing) This function initialises the locale and message catalog used by this - program. The message catalog must reside in the location specified - during "./configure" via the "--localedir" option; this location is - passed to this source code file as PREFIXDIR. This function must be - called before using any locale or Gettext functions. + program. If the TEXTDOMAINDIR environment variable is set, the message + catalog must reside in that location, otherwise it must be in the + location specified during "./configure" via the "--localedir" option. + This function must be called before using any locale or Gettext + functions. */ extern void init_locale (void);