diff --git a/core/smn_lang.cpp b/core/smn_lang.cpp index da31706a..29aa2038 100644 --- a/core/smn_lang.cpp +++ b/core/smn_lang.cpp @@ -104,6 +104,46 @@ static cell_t sm_GetLanguageInfo(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t sm_SetClientLanguage(IPluginContext *pContext, const cell_t *params) +{ + CPlayer *player = g_Players.GetPlayerByIndex(params[1]); + + if (!player || !player->IsInGame()) + { + return pContext->ThrowNativeError("Invalid client index %d", params[1]); + } + + player->m_LangId = params[2]; + + return 1; +} + +static cell_t sm_GetLanguageByCode(IPluginContext *pContext, const cell_t *params) +{ + char *code; + unsigned int langid; + + pContext->LocalToString(params[1], &code); + + if (g_Translator.GetLanguageByCode(code, &langid)) + return langid; + + return -1; +} + +static cell_t sm_GetLanguageByName(IPluginContext *pContext, const cell_t *params) +{ + char *name; + unsigned int langid; + + pContext->LocalToString(params[1], &name); + + if (g_Translator.GetLanguageByName(name, &langid)) + return langid; + + return -1; +} + REGISTER_NATIVES(langNatives) { {"LoadTranslations", sm_LoadTranslations}, @@ -112,5 +152,8 @@ REGISTER_NATIVES(langNatives) {"GetServerLanguage", sm_GetServerLanguage}, {"GetLanguageCount", sm_GetLanguageCount}, {"GetLanguageInfo", sm_GetLanguageInfo}, + {"SetClientLanguage", sm_SetClientLanguage}, + {"GetLanguageByCode", sm_GetLanguageByCode}, + {"GetLanguageByName", sm_GetLanguageByName}, {NULL, NULL}, }; diff --git a/plugins/include/lang.inc b/plugins/include/lang.inc index 1301b8a1..61b98ada 100644 --- a/plugins/include/lang.inc +++ b/plugins/include/lang.inc @@ -94,3 +94,28 @@ native GetLanguageCount(); */ native GetLanguageInfo(language, String:code[]="", codeLen=0, String:name[]="", nameLen=0); +/** + * Sets the language number of a client. + * + * @param client Client index. + * @param language Language number. + * @noreturn + * @error Invalid client index or client not in game. + */ +native SetClientLanguage(client, language); + +/** + * Retrieves the language number from a language code. + * + * @param code Language code (2-3 characters usually). + * @return Language number. -1 if not found. + */ +native GetLanguageByCode(const String:code[]); + +/** + * Retrieves the language number from a language name. + * + * @param name Language name (case insensitive). + * @return Language number. -1 if not found. + */ +native GetLanguageByName(const String:name[]);