ConfigBoolToSetting now translates a bool into the client's/server's native language.

This commit is contained in:
Greyscale 2009-08-03 14:55:50 -07:00
parent 940463491b
commit 1757ec97fa
5 changed files with 23 additions and 13 deletions

View File

@ -878,7 +878,7 @@ public Action:ConfigReloadAllCommand(client, argc)
} }
/** /**
* Converts string of "yes/on" or "no/off" to a boolean value. * Converts string of "yes/on" or "no/off" to a boolean value. Always uses english as yes/no/on/off language.
* *
* @param option "yes/on" or "no/off" string to be converted. * @param option "yes/on" or "no/off" string to be converted.
* @return True if string is "yes", false otherwise. * @return True if string is "yes", false otherwise.
@ -891,7 +891,7 @@ stock bool:ConfigSettingToBool(const String:option[])
return true; return true;
} }
// Option isn't "yes." // Option isn't yes.
return false; return false;
} }
@ -901,19 +901,29 @@ stock bool:ConfigSettingToBool(const String:option[])
* @param bOption True/false value to be converted to "yes/on"/"no/off", respectively. * @param bOption True/false value to be converted to "yes/on"/"no/off", respectively.
* @param option Destination string buffer to store "yes/on" or "no/off" in. * @param option Destination string buffer to store "yes/on" or "no/off" in.
* @param maxlen Length of destination string buffer (wont't be more than 4). * @param maxlen Length of destination string buffer (wont't be more than 4).
* @param yesno When true, returns "yes/no", false returns "on/off." * @param yesno When true, returns "yes/no", false returns "on/off."
* @param target The target to use as translation language.
*/ */
stock ConfigBoolToSetting(bool:bOption, String:option[], maxlen, bool:yesno = true) stock ConfigBoolToSetting(bool:bOption, String:option[], maxlen, bool:yesno = true, target = LANG_SERVER)
{ {
decl String:t_yes[16], String:t_on[16];
decl String:t_no[16], String:t_off[16];
SetGlobalTransTarget(target);
// Get the yes/no translations for the target.
Format(t_yes, sizeof(t_yes), "%t", "Yes"); Format(t_on, sizeof(t_on), "%t", "On");
Format(t_no, sizeof(t_no), "%t", "No"); Format(t_off, sizeof(t_off), "%t", "Off");
// If option is true, then copy "yes" to return string. // If option is true, then copy "yes" to return string.
if (bOption) if (bOption)
{ {
yesno ? strcopy(option, maxlen, "Yes") : strcopy(option, maxlen, "On"); yesno ? strcopy(option, maxlen, t_yes) : strcopy(option, maxlen, t_on);
} }
// If option is false, then copy "no" to return string. // If option is false, then copy "no" to return string.
else else
{ {
yesno ? strcopy(option, maxlen, "No") : strcopy(option, maxlen, "Off"); yesno ? strcopy(option, maxlen, t_no) : strcopy(option, maxlen, t_off);
} }
} }

View File

@ -397,7 +397,7 @@ bool:HitgroupsMenuHitgroups(client)
IntToString(x, hitgroupid, sizeof(hitgroupid)); IntToString(x, hitgroupid, sizeof(hitgroupid));
// Convert bool to "On/Off" // Convert bool to "On/Off"
ConfigBoolToSetting(HitgroupsCanDamage(x), hitgroupcandamage, sizeof(hitgroupcandamage), false); ConfigBoolToSetting(HitgroupsCanDamage(x), hitgroupcandamage, sizeof(hitgroupcandamage), false, client);
// Format "on/off" to the option. // Format "on/off" to the option.
Format(hitgroupoption, sizeof(hitgroupoption), "%s: %s", hitgroupoption, hitgroupcandamage); Format(hitgroupoption, sizeof(hitgroupoption), "%s: %s", hitgroupoption, hitgroupcandamage);

View File

@ -360,7 +360,7 @@ WeaponsMenuZMarket(client)
// Get "yes" or "no" settings from respective cvar. // Get "yes" or "no" settings from respective cvar.
decl String:buyzonesetting[8]; decl String:buyzonesetting[8];
ConfigBoolToSetting(GetConVarBool(g_hCvarsList[CVAR_WEAPONS_ZMARKET_BUYZONE]), buyzonesetting, sizeof(buyzonesetting)); ConfigBoolToSetting(GetConVarBool(g_hCvarsList[CVAR_WEAPONS_ZMARKET_BUYZONE]), buyzonesetting, sizeof(buyzonesetting), true, client);
SetGlobalTransTarget(client); SetGlobalTransTarget(client);

View File

@ -264,7 +264,7 @@ bool:ZMarketMenuMain(client)
// Get auto-rebuy setting. // Get auto-rebuy setting.
decl String:rebuyautosetting[8]; decl String:rebuyautosetting[8];
ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie), rebuyautosetting, sizeof(rebuyautosetting)); ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie), rebuyautosetting, sizeof(rebuyautosetting), true, client);
// Format menu options. // Format menu options.
Format(title, sizeof(title), "%t\n ", "Weapons menu zmarket main title"); Format(title, sizeof(title), "%t\n ", "Weapons menu zmarket main title");
@ -422,7 +422,7 @@ bool:ZMarketMenuLoadout(client)
// Copy "Yes/No" to NVGs string. // Copy "Yes/No" to NVGs string.
decl String:nvgsbool[8]; decl String:nvgsbool[8];
ConfigBoolToSetting(bool:nvgsweapon[0], nvgsbool, sizeof(nvgsbool)); ConfigBoolToSetting(bool:nvgsweapon[0], nvgsbool, sizeof(nvgsbool), true, client);
decl String:title[MENU_LINE_TITLE_LENGTH]; decl String:title[MENU_LINE_TITLE_LENGTH];
decl String:primary[MENU_LINE_REG_LENGTH]; decl String:primary[MENU_LINE_REG_LENGTH];

View File

@ -52,9 +52,9 @@ ZCookiesMenuMain(client)
decl String:overlayenabled[4]; decl String:overlayenabled[4];
// Get the current toggle state of the cookies. // Get the current toggle state of the cookies.
ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie), autorebuyenabled, sizeof(autorebuyenabled), false); ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie), autorebuyenabled, sizeof(autorebuyenabled), false, client);
ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZHPEnabledCookie), zhpenabled, sizeof(zhpenabled), false); ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZHPEnabledCookie), zhpenabled, sizeof(zhpenabled), false, client);
ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hOverlayEnabledCookie), overlayenabled, sizeof(overlayenabled), false); ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hOverlayEnabledCookie), overlayenabled, sizeof(overlayenabled), false, client);
decl String:title[MENU_LINE_TITLE_LENGTH]; decl String:title[MENU_LINE_TITLE_LENGTH];
decl String:autorebuy[MENU_LINE_REG_LENGTH]; decl String:autorebuy[MENU_LINE_REG_LENGTH];