libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
Macros | Functions
intl.h File Reference
#include <stdint.h>
#include "types.h"
Include dependency graph for intl.h:

Go to the source code of this file.

Macros

#define _(str)   acfutils_xlate(str)
 

Functions

bool_t acfutils_xlate_init (const char *po_file)
 
void acfutils_xlate_fini (void)
 
const char * acfutils_xlate (const char *msgid)
 
const char * acfutils_xplang2code (int lang)
 

Detailed Description

Internationalization (i18n) support routines. Use acfutils_xlate_init() to initialize the i18n engine and acfutils_xlate_fini() to deinitialize it at shutdown (and free allocated resources).

To translate a string, you can either use the acfutils_xlate() function, or the shorthand _("string") macro.

See also
acfutils_xlate_init()
acfutils_xlate_fini()
acfutils_xlate()

Definition in file intl.h.

Macro Definition Documentation

◆ _

#define _ (   str)    acfutils_xlate(str)

This macro is a shorthand for invoking acfutils_xlate(). This provides a convenient in-line method to localize messages, e.g.:

// The message below will automatically be translated
logMsg(_("Hello World!"));
#define _(str)
Definition intl.h:61
#define logMsg(...)
Definition log.h:112

If acfutils_xlate_init() was called and a suitable translation exists, the translated text will be printed. Otherwise, "Hello World!" will be printed.

Definition at line 61 of file intl.h.

Function Documentation

◆ acfutils_xlate()

const char * acfutils_xlate ( const char *  msgid)

Translates a message given a message ID string. This performs a lookup in the PO file parsed in acfutils_xlate_init() for a matching msgid stanza and returns the corresponding msgstr value. If no matching msgid is found in the file (or acfutils_xlate_init() was never called), the input msgid string is returned instead.

Note
You can use the _() macro as a shorthand for a call to acfutils_xlate(). This provides a convenient in-line method to localize messages, e.g.:
// The message below will automatically be translated
logMsg(_("Hello World!"));
If acfutils_xlate_init() was called and a suitable translation exists, the translated text will be printed. Otherwise, "Hello World!" will be printed.

Definition at line 249 of file intl.c.

◆ acfutils_xlate_fini()

void acfutils_xlate_fini ( void  )

Deinitializes the internationalization support of libacfutils. This is always safe to call, even if you didn't call acfutils_xlate_init(), and it's safe to call multiple times.

Definition at line 213 of file intl.c.

◆ acfutils_xlate_init()

bool_t acfutils_xlate_init ( const char *  po_file)

Initializes the internationalization engine. You must call this before starting to use any translation routines contained in this subsystem.

Parameters
po_filePath to a PO file containing translations. The format of this file must conform to the PO file format used by the GNU gettext software. Please note that we only support the msgid and msgstr commands from the PO file format. The intl.h system in libacfutils isn't a full replacement or reimplementation of GNU gettext.
Returns
B_TRUE if the translation engine was initialized successfully, B_FALSE if not. Failures can happen only due to failure to read or parse the passed .po file. The exact error reason is dumped into the log file using logMsg().

Example PO File

# This is a comment
msgid "Can't start planner: pushback already in progress. Please "
"stop the pushback operation first."
msgstr "Não pode iniciar o planejador: pushback já em progresso. "
"Por favor primeiro pare a operação do pushback."

Definition at line 79 of file intl.c.

◆ acfutils_xplang2code()

const char * acfutils_xplang2code ( int  lang)

Translates an X-Plane language enum into a 2-letter ISO-639-1 code.

Parameters
langAn XPLMLanguageCode enum as obtained from XPLMGetLanguage().
Returns
The ISO-639-1 2-letter language code corresponding to the language enum. If the language enum is unknown, returns "xx" instead.

Definition at line 271 of file intl.c.