first attempt on lang error logging
This commit is contained in:
parent
8edf4d674f
commit
4040410c97
@ -358,15 +358,13 @@ void CLangMngr::CLang::MergeDefinitions(CQueue<sKeyDef*> &vec)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * CLangMngr::CLang::GetDef(const char *key)
|
const char * CLangMngr::CLang::GetDef(const char *key, int &status)
|
||||||
{
|
{
|
||||||
static char nfind[1024] = "ML_NOTFOUND(KEY)";
|
|
||||||
int ikey = m_LMan->GetKeyEntry(key);
|
int ikey = m_LMan->GetKeyEntry(key);
|
||||||
|
|
||||||
if (ikey == -1)
|
if (ikey == -1)
|
||||||
{
|
{
|
||||||
sprintf(nfind, "ML_NOTFOUND: %s", key);
|
return NULL;
|
||||||
return nfind;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
|
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
|
||||||
@ -375,6 +373,7 @@ const char * CLangMngr::CLang::GetDef(const char *key)
|
|||||||
return m_LookUpTable[i]->GetDef();
|
return m_LookUpTable[i]->GetDef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status = LANG_STATUS_KLNOTFOUND;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,6 +528,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
|||||||
{
|
{
|
||||||
// number of parameters ( for NEXT_PARAM macro )
|
// number of parameters ( for NEXT_PARAM macro )
|
||||||
int paramCount = *params / sizeof(cell);
|
int paramCount = *params / sizeof(cell);
|
||||||
|
int status;
|
||||||
|
|
||||||
// the output buffer
|
// the output buffer
|
||||||
static char outbuf[4096];
|
static char outbuf[4096];
|
||||||
@ -580,24 +580,40 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
|||||||
int tmplen = 0;
|
int tmplen = 0;
|
||||||
NEXT_PARAM();
|
NEXT_PARAM();
|
||||||
char *key = get_amxstring(amx, params[parm++], 1, tmplen);
|
char *key = get_amxstring(amx, params[parm++], 1, tmplen);
|
||||||
const char *def = GetDef(cpLangName, key);
|
const char *def = GetDef(cpLangName, key, status);
|
||||||
|
|
||||||
if (def == NULL)
|
if (def == NULL)
|
||||||
{
|
{
|
||||||
|
bool a = true;
|
||||||
|
if (status == LANG_STATUS_LNOTFOUND)
|
||||||
|
{
|
||||||
|
AMXXLOG_Log("[AMXX] Language \"%s\" not found", cpLangName);
|
||||||
|
}
|
||||||
|
else if (status == LANG_STATUS_KLNOTFOUND)
|
||||||
|
{
|
||||||
|
a = false;
|
||||||
|
AMXXLOG_Log("[AMXX] Language key \"%s\" not found for language \"%s\"", key, cpLangName);
|
||||||
|
}
|
||||||
|
|
||||||
if (*pAmxLangName != LANG_SERVER)
|
if (*pAmxLangName != LANG_SERVER)
|
||||||
{
|
{
|
||||||
def = GetDef(g_vault.get("server_language"), key);
|
def = GetDef(g_vault.get("server_language"), key, status);
|
||||||
}
|
}
|
||||||
if (strcmp(cpLangName, "en") != 0 && strcmp(g_vault.get("server_language"), "en") != 0)
|
|
||||||
|
if (!def && (strcmp(cpLangName, "en") != 0 && strcmp(g_vault.get("server_language"), "en") != 0))
|
||||||
{
|
{
|
||||||
def = GetDef("en", key);
|
def = GetDef("en", key, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!def)
|
if (!def)
|
||||||
{
|
{
|
||||||
static char buf[512];
|
static char buf[512];
|
||||||
CHECK_PTR((char*)(buf + 17 + strlen(key)), buf, sizeof(buf));
|
CHECK_PTR((char*)(buf + 17 + strlen(key)), buf, sizeof(buf));
|
||||||
sprintf(buf, "ML_LNOTFOUND: %s", key);
|
sprintf(buf, "ML_LNOTFOUND: %s", key);
|
||||||
def = buf;
|
def = buf;
|
||||||
|
|
||||||
|
if (a)
|
||||||
|
AMXXLOG_Log("[AMXX] Language key \"%s\" not found, check \"%s\"", key, GetFileName(amx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -795,6 +811,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
|||||||
static char outbuf[4096];
|
static char outbuf[4096];
|
||||||
char *outptr = outbuf;
|
char *outptr = outbuf;
|
||||||
const char *src = fmt;
|
const char *src = fmt;
|
||||||
|
int status;
|
||||||
|
|
||||||
while (*src)
|
while (*src)
|
||||||
{
|
{
|
||||||
@ -839,18 +856,20 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
|||||||
|
|
||||||
int tmplen = 0;
|
int tmplen = 0;
|
||||||
const char *key = va_arg(ap, const char *);
|
const char *key = va_arg(ap, const char *);
|
||||||
const char *def = GetDef(cpLangName, key);
|
const char *def = GetDef(cpLangName, key, status);
|
||||||
|
|
||||||
if (def == NULL)
|
if (def == NULL)
|
||||||
{
|
{
|
||||||
if (pAmxLangName != LANG_SERVER)
|
if (pAmxLangName != LANG_SERVER)
|
||||||
{
|
{
|
||||||
def = GetDef(g_vault.get("server_language"), key);
|
def = GetDef(g_vault.get("server_language"), key, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(cpLangName, "en") != 0 && strcmp(g_vault.get("server_language"), "en") != 0)
|
if (strcmp(cpLangName, "en") != 0 && strcmp(g_vault.get("server_language"), "en") != 0)
|
||||||
{
|
{
|
||||||
def = GetDef("en", key);
|
def = GetDef("en", key, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!def)
|
if (!def)
|
||||||
{
|
{
|
||||||
static char buf[512];
|
static char buf[512];
|
||||||
@ -1172,13 +1191,17 @@ CLangMngr::CLang * CLangMngr::GetLangR(const char *name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CLangMngr::GetDef(const char *langName, const char *key)
|
const char *CLangMngr::GetDef(const char *langName, const char *key, int &status)
|
||||||
{
|
{
|
||||||
CLang *lang = GetLangR(langName);
|
CLang *lang = GetLangR(langName);
|
||||||
if (lang)
|
if (lang)
|
||||||
return lang->GetDef(key);
|
{
|
||||||
|
//status = LANG_STATUS_OK;
|
||||||
return "ML_NOTFOUND(LANG)";
|
return lang->GetDef(key, status);
|
||||||
|
} else {
|
||||||
|
status = LANG_STATUS_LNOTFOUND;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CLangMngr::Save(const char *filename)
|
bool CLangMngr::Save(const char *filename)
|
||||||
|
@ -35,6 +35,10 @@
|
|||||||
#define LANG_SERVER 0
|
#define LANG_SERVER 0
|
||||||
#define LANG_PLAYER -1
|
#define LANG_PLAYER -1
|
||||||
|
|
||||||
|
#define LANG_STATUS_OK 0 // OK
|
||||||
|
#define LANG_STATUS_KLNOTFOUND 1 // Lang key not found in the lang.txt
|
||||||
|
#define LANG_STATUS_LNOTFOUND 3 // Invalid lang
|
||||||
|
|
||||||
struct md5Pair
|
struct md5Pair
|
||||||
{
|
{
|
||||||
String file;
|
String file;
|
||||||
@ -69,7 +73,7 @@ class CLangMngr
|
|||||||
~CLang();
|
~CLang();
|
||||||
|
|
||||||
// Get the definition
|
// Get the definition
|
||||||
const char *GetDef(const char *key);
|
const char *GetDef(const char *key, int &status);
|
||||||
// Add definitions to this language
|
// Add definitions to this language
|
||||||
void MergeDefinitions(CQueue <sKeyDef*> & vec);
|
void MergeDefinitions(CQueue <sKeyDef*> & vec);
|
||||||
// Reset this language
|
// Reset this language
|
||||||
@ -167,8 +171,8 @@ class CLangMngr
|
|||||||
public:
|
public:
|
||||||
// Merge a definitions file
|
// Merge a definitions file
|
||||||
int MergeDefinitionFile(const char *file);
|
int MergeDefinitionFile(const char *file);
|
||||||
// Get a definition from a lang name and a kyer
|
// Get a definition from a lang name and a key
|
||||||
const char *GetDef(const char *langName, const char *key);
|
const char *GetDef(const char *langName, const char *key, int &status);
|
||||||
// Format a string
|
// Format a string
|
||||||
const char *Format(const char *src, ...);
|
const char *Format(const char *src, ...);
|
||||||
// Format a string for an AMX plugin
|
// Format a string for an AMX plugin
|
||||||
|
Loading…
Reference in New Issue
Block a user