PhysicsFS-aware gettext implementation.
More...
#include "gettext.h"
#include "array.h"
#include "log.h"
#include "msgcat.h"
#include "ndata.h"
Go to the source code of this file.
|
| static void | gettext_readStats (void) |
| | Read the GETTEXT_STATS_PATH data and compute gettext_nstrings. (Common case: just a "naev.txt" file with one number. But mods pulled in via PhysicsFS can have their own string counts.)
|
| static const char * | gettext_matchLanguage (const char *lang, size_t lang_len, char *const *available) |
| | Pick the best match from "available" (a physfs listing) for the string-slice with address lang, length lang_len.
|
| void | gettext_init (void) |
| | Initialize the translation system. There's no presumption that PhysicsFS is available, so this doesn't actually load translations. We loosely follow: https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html.
|
| void | gettext_exit (void) |
| | Free resources associated with the translation system. This invalidates previously returned pointers to translated strings; be sure to actually exit after calling!
|
| const char * | gettext_getSystemLanguage (void) |
| | Gets the current system language as detected by Naev.
|
| const char * | gettext_getLanguage (void) |
| | Gets the active (primary) translation language. Even in case of a complex locale, this will be the name of the first message catalog to be checked (or the "en" language code for untranslated English). The purpose is to provide a simple answer to things like libunibreak which ask which language we're using.
|
| void | gettext_setLanguage (const char *lang) |
| | Set the translation language.
|
| const char * | gettext_ngettext (const char *msgid, const char *msgid_plural, uint64_t n) |
| | Return a translated version of the input, using the current language catalogs.
|
| const char * | gettext_pgettext_impl (const char *lookup, const char *msgid) |
| | Helper function for p_(): Return _(lookup) with a fallback of msgid rather than lookup.
|
| LanguageOption * | gettext_languageOptions (void) |
| | List the available languages, with completeness statistics.
|
| double | gettext_languageCoverage (const char *lang) |
| | Return the fraction of strings which have a translation into the given language.
|
| const char * | pgettext_var (const char *msgctxt, const char *msgid) |
PhysicsFS-aware gettext implementation.
Definition in file gettext.c.
◆ gettext_exit()
| void gettext_exit |
( |
void | | ) |
|
Free resources associated with the translation system. This invalidates previously returned pointers to translated strings; be sure to actually exit after calling!
Definition at line 89 of file gettext.c.
◆ gettext_getLanguage()
| const char * gettext_getLanguage |
( |
void | | ) |
|
Gets the active (primary) translation language. Even in case of a complex locale, this will be the name of the first message catalog to be checked (or the "en" language code for untranslated English). The purpose is to provide a simple answer to things like libunibreak which ask which language we're using.
Definition at line 122 of file gettext.c.
◆ gettext_getSystemLanguage()
| const char * gettext_getSystemLanguage |
( |
void | | ) |
|
Gets the current system language as detected by Naev.
Definition at line 110 of file gettext.c.
◆ gettext_init()
| void gettext_init |
( |
void | | ) |
|
◆ gettext_languageCoverage()
| double gettext_languageCoverage |
( |
const char * | lang | ) |
|
Return the fraction of strings which have a translation into the given language.
- Parameters
-
| lang | A single language code. |
Definition at line 312 of file gettext.c.
◆ gettext_languageOptions()
List the available languages, with completeness statistics.
- Returns
- Array (array.h) of LanguageOptions.
Definition at line 289 of file gettext.c.
◆ gettext_matchLanguage()
| const char * gettext_matchLanguage |
( |
const char * | lang, |
|
|
size_t | lang_len, |
|
|
char *const * | available ) |
|
static |
Pick the best match from "available" (a physfs listing) for the string-slice with address lang, length lang_len.
- Returns
- The best match, if any, else NULL.
Definition at line 204 of file gettext.c.
◆ gettext_ngettext()
| const char * gettext_ngettext |
( |
const char * | msgid, |
|
|
const char * | msgid_plural, |
|
|
uint64_t | n ) |
Return a translated version of the input, using the current language catalogs.
- Parameters
-
| msgid | The English singular form. |
| msgid_plural | The English plural form. (Pass NULL if simply translating msgid1.) |
| n | The number determining the plural form to use. (Pass 1 if simply translating msgid1.) |
- Returns
- The translation in the message catalog, if it exists, else whichever of msgid1 or msgid2 is appropriate in English. The returned string must not be modified or freed.
Definition at line 238 of file gettext.c.
◆ gettext_pgettext_impl()
| const char * gettext_pgettext_impl |
( |
const char * | lookup, |
|
|
const char * | msgid ) |
Helper function for p_(): Return _(lookup) with a fallback of msgid rather than lookup.
Definition at line 259 of file gettext.c.
◆ gettext_readStats()
| void gettext_readStats |
( |
void | | ) |
|
|
static |
Read the GETTEXT_STATS_PATH data and compute gettext_nstrings. (Common case: just a "naev.txt" file with one number. But mods pulled in via PhysicsFS can have their own string counts.)
Definition at line 270 of file gettext.c.
◆ gettext_setLanguage()
| void gettext_setLanguage |
( |
const char * | lang | ) |
|
Set the translation language.
- Parameters
-
| lang | Language code to use. If NULL, use the system default. |
Definition at line 135 of file gettext.c.
◆ pgettext_var()
| const char * pgettext_var |
( |
const char * | msgctxt, |
|
|
const char * | msgid ) |
The function is almost the same as p_() but msgctxt and msgid can be string variables.
Definition at line 346 of file gettext.c.
◆ gettext_activeTranslation
Initial value:Active language's code.
Definition at line 38 of file gettext.c.
◆ gettext_nstrings
| uint32_t gettext_nstrings |
|
static |
Initial value:Number of translatable strings in the game.
Definition at line 40 of file gettext.c.
◆ gettext_systemLanguage
| char* gettext_systemLanguage |
|
static |
Initial value:Language, or :-delimited list of them, from the system at startup.
Definition at line 33 of file gettext.c.
◆ gettext_translations
Initial value:Linked list of loaded translation chains.
Definition at line 36 of file gettext.c.