libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
|
#include <stdint.h>
#include "types.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) |
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.
Definition in file intl.h.
#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.:
If acfutils_xlate_init() was called and a suitable translation exists, the translated text will be printed. Otherwise, "Hello World!" will be printed.
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.
_()
macro as a shorthand for a call to acfutils_xlate(). This provides a convenient in-line method to localize messages, e.g.: If acfutils_xlate_init() was called and a suitable translation exists, the translated text will be printed. Otherwise, "Hello World!" will be printed. void acfutils_xlate_fini | ( | void | ) |
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.
po_file | Path 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. |
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(). const char * acfutils_xplang2code | ( | int | lang | ) |
Translates an X-Plane language enum into a 2-letter ISO-639-1 code.
lang | An XPLMLanguageCode enum as obtained from XPLMGetLanguage(). |