28 #include "../shared/parse.h"
29 #include "../ports/system.h"
38 #define MAX_MSGIDS 512
51 #define MAX_MSGIDHASH 256
54 #define MSGIDSIZE 65536
61 if (!*text || *token !=
'{') {
62 Com_Printf(
"CL_ParseMessageID: msgid \"%s\" without body ignored\n", name);
69 if (
Q_streq(token, msgIDs[i].
id))
73 msgid_t* msgid = &msgIDs[numMsgIDs++];
76 Sys_Error(
"CL_ParseMessageID: MAX_MSGIDS exceeded");
84 const char* errhead =
"CL_ParseMessageID: unexpected end of file (msgid ";
98 msgid->
text =
_(token);
101 if (msgid->
text == token) {
108 Com_Printf(
"CL_ParseMessageID: msgid \"%s\" with same already exists - ignore the second one\n", name);
116 for (
msgid_t** anchor = &msgIDHash[hash]; *anchor; anchor = &(*anchor)->
hash_next) {
117 if (
Q_streq(
id, (*anchor)->id))
118 return (*anchor)->text;
130 if (msgid !=
nullptr)
144 if (cl_msgidPool !=
nullptr) {
151 Com_Printf(
"\n----------- parse msgids -----------\n");
154 const char*
text =
nullptr;
199 mapping = mapping->
next;
201 language = language->
next;
204 "Add it to the languages script file and send a patch please.\n", fullLocale);
213 const char* errhead =
"CL_ParseLanguages: unexpected end of file (language ";
216 Com_Printf(
"CL_ParseLanguages: language without body ignored (%s)\n", name);
220 const char* token =
Com_EParse(text, errhead, name);
221 if (!*text || *token !=
'{') {
222 Com_Printf(
"CL_ParseLanguages: language without body ignored (%s)\n", name);
235 if (!*text || *token ==
'}')
241 Com_Error(
ERR_DROP,
"CL_ParseLanguages: error while reading language codes \"%s\"", name);
243 for (
linkedList_t* element = list; element !=
nullptr; element = element->
next) {
251 }
else if (
Q_streq(token,
"name")) {
253 if (!*text || *token ==
'}')
254 Com_Error(
ERR_FATAL,
"CL_ParseLanguages: Name expected for language \"%s\".\n", name);
256 Com_Printf(
"CL_ParseLanguages: language: '%s' - not marked translatable (%s)\n", name, token);
259 }
else if (
Q_streq(token,
"native")) {
261 if (!*text || *token ==
'}')
262 Com_Error(
ERR_FATAL,
"CL_ParseLanguages: Native expected for language \"%s\".\n", name);
268 languageList = language;
288 if (fs_i18ndir->
string[0] !=
'\0')
292 Com_sprintf(languagePath,
sizeof(languagePath), LOCALEDIR);
297 Q_strcat(languagePath,
sizeof(languagePath),
"%s/LC_MESSAGES/ufoai.mo", localeID);
306 if (
Sys_Setenv(
"LANGUAGE=%s", localeID) == 0) {
311 for (i = 0, language = languageList; i <
languageCount; language = language->
next, i++) {
315 if (i == languageCount) {
333 mapping = mapping->
next;
344 languageList =
nullptr;
346 cl_msgidPool =
nullptr;
360 language = language->
next;
378 fs_i18ndir =
Cvar_Get(
"fs_i18ndir",
"", 0,
"System path to language files");
380 char systemLanguage[
MAX_VAR] =
"";
389 Q_strncpyz(systemLanguage, localeID,
sizeof(systemLanguage));
423 for (i = 0, language = languageList; i <
languageCount; language = language->
next, i++) {
428 if (i == languageCount) {
429 Com_Printf(
"Could not find locale with id '%s'\n", localeID);
435 Com_Printf(
"No locale mappings for locale with id '%s'\n", localeID);
439 Cvar_Set(
"s_language",
"%s", localeID);
448 mapping = mapping->
next;
static cvar_t * fs_i18ndir
static language_t * languageList
void Sys_Error(const char *error,...)
QGL_EXTERN GLint GLenum type
static void CL_ParseMessageID(const char *name, const char **text)
void UI_SortOptions(uiNode_t **first)
Sort options by alphabet.
int Sys_Setenv(const char *name, const char *value)
set/unset environment variables (empty value removes it)
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
void CL_ParseMessageIDs(void)
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
bool FS_FileExists(const char *filename,...)
Checks whether a file exists (not in virtual filesystem)
struct localeMapping_s localeMapping_t
List of all mappings for a locale.
void CL_LanguageInit(void)
Fills the options language menu node with the parsed language mappings.
void CL_LanguageShutdown(void)
const char * Sys_SetLocale(const char *localeID)
void R_FontSetTruncationMarker(const char *marker)
static bool CL_LanguageTest(const char *localeID)
Test given language by trying to set locale.
Struct that reflects parsed language definitions from our script files.
void Com_Printf(const char *const fmt,...)
static const char * CL_GetMessageID(const char *id)
int FS_BuildFileList(const char *fileList)
Build a filelist.
void LIST_Delete(linkedList_t **list)
struct msgid_s * hash_next
memPool_t * cl_genericPool
static memPool_t * cl_msgidPool
#define Q_strvalid(string)
void Com_Error(int code, const char *fmt,...)
static const char * CL_GetLocaleID(const char *fullLocale)
Searches the locale script id with the given locale string.
void CL_LanguageInitMenu(void)
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
static msgid_t msgIDs[MAX_MSGIDS]
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
List of all mappings for a locale.
static wrapCache_t * hash[MAX_WRAP_HASH]
const char * Com_EParse(const char **text, const char *errhead, const char *errinfo, char *target, size_t size)
Parsing function that prints an error message when there is no text in the buffer.
#define Mem_CreatePool(name)
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
#define Mem_DeletePool(pool)
const char * FS_GetCwd(void)
Return current working dir.
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
static msgid_t * msgIDHash[MAX_MSGIDHASH]
const char * nativeString
void R_FontShutdown(void)
frees the SDL_ttf fonts
#define HASH_Add(hash, elem, index)
Atomic structure used to define most of the UI.
#define Mem_FreePool(pool)
const char * Sys_GetLocale(void)
#define Mem_PoolAllocTypeN(type, n, pool)
const char * Com_Parse(const char *data_p[], char *target, size_t size, bool replaceWhitespaces)
Parse a token out of a string.
struct localeMapping_s * next
void CL_ParseLanguages(const char *name, const char **text)
Parse all language definitions from the script files.
bool Com_ParseList(const char **text, linkedList_t **list)
const char * CL_Translate(const char *t)
struct language_s language_t
Struct that reflects parsed language definitions from our script files.
localeMapping_t * localeMapping
char * FS_NextScriptHeader(const char *files, const char **name, const char **text)
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
void UI_RegisterOption(int dataId, uiNode_t *option)
unsigned int Com_HashKey(const char *name, int hashsize)
returns hash key for a string
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
bool CL_LanguageTryToSet(const char *localeID)
Cycle through all parsed locale mappings and try to set one after another.
uiNode_t * UI_AddOption(uiNode_t **tree, const char *name, const char *label, const char *value)
Append an option to an option list.
const char * localeString
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Primary header for client.
#define Mem_PoolStrDup(in, pool, tagNum)
#define Mem_PoolAllocType(type, pool)
static void CL_NewLanguage(void)
Adjust game for new language: reregister fonts, etc.
void Com_SkipBlock(const char **text)
Skips a block of {} in our script files.
void UI_InitFonts(void)
after a video restart we have to reinitialize the fonts