added request amb588 - language info embellishment
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401111
This commit is contained in:
parent
e8d5bf9521
commit
9c531423fb
@ -909,3 +909,28 @@ unsigned int Translator::GetServerLanguage()
|
||||
{
|
||||
return m_ServerLang;
|
||||
}
|
||||
|
||||
unsigned int Translator::GetClientLanguage(int client)
|
||||
{
|
||||
return GetServerLanguage();
|
||||
}
|
||||
|
||||
bool Translator::GetLanguageInfo(unsigned int number, const char **code, const char **name)
|
||||
{
|
||||
if (number >= GetLanguageCount())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Language *l = m_Languages[number];
|
||||
if (code)
|
||||
{
|
||||
*code = l->m_code2;
|
||||
}
|
||||
if (name)
|
||||
{
|
||||
*name = m_pStringTab->GetString(l->m_FullName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -120,6 +120,7 @@ public:
|
||||
unsigned int FindOrAddPhraseFile(const char *phrase_file);
|
||||
BaseStringTable *GetStringTable();
|
||||
unsigned int GetLanguageCount();
|
||||
bool GetLanguageInfo(unsigned int number, const char **code, const char **name);
|
||||
bool GetLanguageByCode(const char *code, unsigned int *index);
|
||||
size_t Translate(char *buffer, size_t maxlength, void **params, const Translation *pTrans);
|
||||
CPhraseFile *GetFileByIndex(unsigned int index);
|
||||
@ -130,6 +131,7 @@ public:
|
||||
void **params,
|
||||
size_t *outlen=NULL);
|
||||
unsigned int GetServerLanguage();
|
||||
unsigned int GetClientLanguage(int client);
|
||||
private:
|
||||
bool AddLanguage(const char *langcode, const char *description);
|
||||
private:
|
||||
|
@ -81,7 +81,7 @@ try_serverlang:
|
||||
{
|
||||
langid = g_Translator.GetServerLanguage();
|
||||
} else if ((target >= 1) && (target <= g_Players.GetMaxClients())) {
|
||||
langid = g_Translator.GetServerLanguage();
|
||||
langid = g_Translator.GetClientLanguage(target);
|
||||
} else {
|
||||
pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Translation failed: invalid client index %d", target);
|
||||
goto error_out;
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "Translator.h"
|
||||
#include "LibrarySys.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include "PlayerManager.h"
|
||||
|
||||
static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
@ -48,9 +49,50 @@ static cell_t sm_SetGlobalTransTarget(IPluginContext *pContext, const cell_t *pa
|
||||
return 1;
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(langNativeS)
|
||||
static cell_t sm_GetClientLanguage(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CPlayer *player = g_Players.GetPlayerByIndex(params[1]);
|
||||
if (!player || !player->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid client index %d", params[1]);
|
||||
}
|
||||
|
||||
return g_Translator.GetClientLanguage(params[1]);
|
||||
}
|
||||
|
||||
static cell_t sm_GetServerLanguage(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return g_Translator.GetServerLanguage();
|
||||
}
|
||||
|
||||
static cell_t sm_GetLanguageCount(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return g_Translator.GetLanguageCount();
|
||||
}
|
||||
|
||||
static cell_t sm_GetLanguageInfo(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
const char *code;
|
||||
const char *name;
|
||||
|
||||
if (!g_Translator.GetLanguageInfo(params[1], &code, &name))
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid language number %d", params[1]);
|
||||
}
|
||||
|
||||
pContext->StringToLocalUTF8(params[2], params[3], code, NULL);
|
||||
pContext->StringToLocalUTF8(params[4], params[5], name, NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(langNatives)
|
||||
{
|
||||
{"LoadTranslations", sm_LoadTranslations},
|
||||
{"SetGlobalTransTarget", sm_SetGlobalTransTarget},
|
||||
{"GetClientLanguage", sm_GetClientLanguage},
|
||||
{"GetServerLanguage", sm_GetServerLanguage},
|
||||
{"GetLanguageCount", sm_GetLanguageCount},
|
||||
{"GetLanguageInfo", sm_GetLanguageInfo},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
@ -39,3 +39,41 @@ native LoadTranslations(const String:file[]);
|
||||
* @noreturn
|
||||
*/
|
||||
native SetGlobalTransTarget(client);
|
||||
|
||||
/**
|
||||
* Retrieves the language number of a client.
|
||||
* Currently this simply returns the server language index.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @return Language number client is using.
|
||||
* @error Invalid client index or client not in game.
|
||||
*/
|
||||
native GetClientLanguage(client);
|
||||
|
||||
/**
|
||||
* Retrieves the server's language.
|
||||
*
|
||||
* @return Language number server is using.
|
||||
*/
|
||||
native GetServerLanguage(client);
|
||||
|
||||
/**
|
||||
* Returns the number of languages known in languages.cfg.
|
||||
*
|
||||
* @return Language count.
|
||||
*/
|
||||
native GetLanguageCount();
|
||||
|
||||
/**
|
||||
* Retrieves info about a given language number.
|
||||
*
|
||||
* @param language Language number.
|
||||
* @param code Language code buffer (2-3 characters usually).
|
||||
* @param codeLen Maximum length of the language code buffer.
|
||||
* @param name Language name buffer.
|
||||
* @param nameLen Maximum length of the language name buffer.
|
||||
* @noreturn
|
||||
* @error Invalid language number.
|
||||
*/
|
||||
native GetLanguageInfo(language, String:code[]="", codeLen=0, String:name[]="", nameLen=0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user