Macros | Enumerations | Functions | Variables
NLS: National Language Support

This implementation of NLS does not use GNU gettext. The reasons are: More...

Macros

#define NLS_COMMENT(comment)
 Always remove NLS comments from code.
 
#define MAIN_ERR_PREFIX   "NLS: "
 Message prefix for NLS module.
 
#define NLS_MAX_MESSAGE   384
 Maximum number of messages loaded from NLS catalog. More...
 

Enumerations

enum  nls_locale { NLS_LOCALE_VALID, NLS_LOCALE_DEFAULT, NLS_LOCALE_INVALID }
 

Functions

int nls_init (void)
 Init NLS subsystem. More...
 
void nls_exit (void)
 Shutdown NLS subsystem. More...
 
const char * nls_getstring (int n, const char *s)
 Get NLS string. More...
 

Variables

char nls_loc [6] = ""
 Current NLS locale.
 

Detailed Description

This implementation of NLS does not use GNU gettext. The reasons are:

This should waste minimum ressources and give best runtime performance. All the expensive work is done only once at build time.

Macro Definition Documentation

◆ NLS_MAX_MESSAGE

#define NLS_MAX_MESSAGE   384

Maximum number of messages loaded from NLS catalog.

This value must at least match the number of messages in the NLS catalogs used by the program. The limit of this implementation is INT_MAX. If the system has a lower limit than the configured value, the value is clamped to the system limit.

Warning
Making this value much higher than required will waste memory and slow down startup.

Definition at line 69 of file nls.c.

Function Documentation

◆ nls_exit()

void nls_exit ( void  )

Shutdown NLS subsystem.

It is allowed to call this function even if nls_init() have failed. In this case it simply does nothing.

Definition at line 447 of file nls.c.

◆ nls_getstring()

const char* nls_getstring ( int  n,
const char *  s 
)

Get NLS string.

Parameters
[in]nNLS string number
[in]sReplacement string if translation for string n was not found

It is allowed to call this function even if nls_init() have failed or after nls_exit() . In this case always s is returned.

Returns
This functions returns the message string number n (or the default s if no corresponding message is found in the catalog)

Definition at line 480 of file nls.c.

◆ nls_init()

int nls_init ( void  )

Init NLS subsystem.

First the locale of the program is set. If this fails the locale POSIX is used. The locale C is also mapped to POSIX and no NLS catalog is used for the locale POSIX. Then we try to extract the language code xx and the country code YY of the message locale name from LC_MESSAGES. If the locale has no country code (old 2 digit style), XX is used. If a valid locale was found, a catalog with the name xx_YY.cat is searched in the location CFG_NLS_PATH that was compiled into the program.

Attention
The environment variable NLSPATH is ignored for security reasons. The administrator who installed the program should have control over the NLS strings that are processed by the program. Think twice before changing this because we use Unicode NLS catalogs and the validity of the encoding must be verfied at runtime otherwise.
Returns
  • 0 on success
  • Negative value on error

Definition at line 173 of file nls.c.


Generated at 2024-04-27 using  doxygen