diff --git a/NEWS b/NEWS index f19b186..0365763 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 66bd069..9d5ed44 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 4e4969b..2fd36c7 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 b664403..8482c90 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);