added request
amb588 - language info embellishment
1.1 --- a/core/Translator.cpp Sat Jul 14 00:47:30 2007 +0000
1.2 +++ b/core/Translator.cpp Sat Jul 14 01:04:15 2007 +0000
1.3 @@ -909,3 +909,28 @@
1.4 {
1.5 return m_ServerLang;
1.6 }
1.7 +
1.8 +unsigned int Translator::GetClientLanguage(int client)
1.9 +{
1.10 + return GetServerLanguage();
1.11 +}
1.12 +
1.13 +bool Translator::GetLanguageInfo(unsigned int number, const char **code, const char **name)
1.14 +{
1.15 + if (number >= GetLanguageCount())
1.16 + {
1.17 + return false;
1.18 + }
1.19 +
1.20 + Language *l = m_Languages[number];
1.21 + if (code)
1.22 + {
1.23 + *code = l->m_code2;
1.24 + }
1.25 + if (name)
1.26 + {
1.27 + *name = m_pStringTab->GetString(l->m_FullName);
1.28 + }
1.29 +
1.30 + return true;
1.31 +}
2.1 --- a/core/Translator.h Sat Jul 14 00:47:30 2007 +0000
2.2 +++ b/core/Translator.h Sat Jul 14 01:04:15 2007 +0000
2.3 @@ -120,6 +120,7 @@
2.4 unsigned int FindOrAddPhraseFile(const char *phrase_file);
2.5 BaseStringTable *GetStringTable();
2.6 unsigned int GetLanguageCount();
2.7 + bool GetLanguageInfo(unsigned int number, const char **code, const char **name);
2.8 bool GetLanguageByCode(const char *code, unsigned int *index);
2.9 size_t Translate(char *buffer, size_t maxlength, void **params, const Translation *pTrans);
2.10 CPhraseFile *GetFileByIndex(unsigned int index);
2.11 @@ -130,6 +131,7 @@
2.12 void **params,
2.13 size_t *outlen=NULL);
2.14 unsigned int GetServerLanguage();
2.15 + unsigned int GetClientLanguage(int client);
2.16 private:
2.17 bool AddLanguage(const char *langcode, const char *description);
2.18 private:
3.1 --- a/core/sm_stringutil.cpp Sat Jul 14 00:47:30 2007 +0000
3.2 +++ b/core/sm_stringutil.cpp Sat Jul 14 01:04:15 2007 +0000
3.3 @@ -81,7 +81,7 @@
3.4 {
3.5 langid = g_Translator.GetServerLanguage();
3.6 } else if ((target >= 1) && (target <= g_Players.GetMaxClients())) {
3.7 - langid = g_Translator.GetServerLanguage();
3.8 + langid = g_Translator.GetClientLanguage(target);
3.9 } else {
3.10 pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Translation failed: invalid client index %d", target);
3.11 goto error_out;
4.1 --- a/core/smn_lang.cpp Sat Jul 14 00:47:30 2007 +0000
4.2 +++ b/core/smn_lang.cpp Sat Jul 14 01:04:15 2007 +0000
4.3 @@ -16,6 +16,7 @@
4.4 #include "Translator.h"
4.5 #include "LibrarySys.h"
4.6 #include "sm_stringutil.h"
4.7 +#include "PlayerManager.h"
4.8
4.9 static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params)
4.10 {
4.11 @@ -48,9 +49,50 @@
4.12 return 1;
4.13 }
4.14
4.15 -REGISTER_NATIVES(langNativeS)
4.16 +static cell_t sm_GetClientLanguage(IPluginContext *pContext, const cell_t *params)
4.17 +{
4.18 + CPlayer *player = g_Players.GetPlayerByIndex(params[1]);
4.19 + if (!player || !player->IsConnected())
4.20 + {
4.21 + return pContext->ThrowNativeError("Invalid client index %d", params[1]);
4.22 + }
4.23 +
4.24 + return g_Translator.GetClientLanguage(params[1]);
4.25 +}
4.26 +
4.27 +static cell_t sm_GetServerLanguage(IPluginContext *pContext, const cell_t *params)
4.28 +{
4.29 + return g_Translator.GetServerLanguage();
4.30 +}
4.31 +
4.32 +static cell_t sm_GetLanguageCount(IPluginContext *pContext, const cell_t *params)
4.33 +{
4.34 + return g_Translator.GetLanguageCount();
4.35 +}
4.36 +
4.37 +static cell_t sm_GetLanguageInfo(IPluginContext *pContext, const cell_t *params)
4.38 +{
4.39 + const char *code;
4.40 + const char *name;
4.41 +
4.42 + if (!g_Translator.GetLanguageInfo(params[1], &code, &name))
4.43 + {
4.44 + return pContext->ThrowNativeError("Invalid language number %d", params[1]);
4.45 + }
4.46 +
4.47 + pContext->StringToLocalUTF8(params[2], params[3], code, NULL);
4.48 + pContext->StringToLocalUTF8(params[4], params[5], name, NULL);
4.49 +
4.50 + return 1;
4.51 +}
4.52 +
4.53 +REGISTER_NATIVES(langNatives)
4.54 {
4.55 {"LoadTranslations", sm_LoadTranslations},
4.56 {"SetGlobalTransTarget", sm_SetGlobalTransTarget},
4.57 + {"GetClientLanguage", sm_GetClientLanguage},
4.58 + {"GetServerLanguage", sm_GetServerLanguage},
4.59 + {"GetLanguageCount", sm_GetLanguageCount},
4.60 + {"GetLanguageInfo", sm_GetLanguageInfo},
4.61 {NULL, NULL},
4.62 };
5.1 --- a/plugins/include/lang.inc Sat Jul 14 00:47:30 2007 +0000
5.2 +++ b/plugins/include/lang.inc Sat Jul 14 01:04:15 2007 +0000
5.3 @@ -39,3 +39,41 @@
5.4 * @noreturn
5.5 */
5.6 native SetGlobalTransTarget(client);
5.7 +
5.8 +/**
5.9 + * Retrieves the language number of a client.
5.10 + * Currently this simply returns the server language index.
5.11 + *
5.12 + * @param client Client index.
5.13 + * @return Language number client is using.
5.14 + * @error Invalid client index or client not in game.
5.15 + */
5.16 +native GetClientLanguage(client);
5.17 +
5.18 +/**
5.19 + * Retrieves the server's language.
5.20 + *
5.21 + * @return Language number server is using.
5.22 + */
5.23 +native GetServerLanguage(client);
5.24 +
5.25 +/**
5.26 + * Returns the number of languages known in languages.cfg.
5.27 + *
5.28 + * @return Language count.
5.29 + */
5.30 +native GetLanguageCount();
5.31 +
5.32 +/**
5.33 + * Retrieves info about a given language number.
5.34 + *
5.35 + * @param language Language number.
5.36 + * @param code Language code buffer (2-3 characters usually).
5.37 + * @param codeLen Maximum length of the language code buffer.
5.38 + * @param name Language name buffer.
5.39 + * @param nameLen Maximum length of the language name buffer.
5.40 + * @noreturn
5.41 + * @error Invalid language number.
5.42 + */
5.43 +native GetLanguageInfo(language, String:code[]="", codeLen=0, String:name[]="", nameLen=0);
5.44 +