if (passed) { for (int i = 1; i < sizeof(contains); i++) { if (contains[i]) { char buffer[4]; Format(buffer, sizeof(buffer), "{%d}", i); if (StrContains(bufferphrase, buffer) == -1) { return false; } } } } } else { return false; } CloseHandle(kv);
return true; }
Call it like this:
PHP Code:
if (TranslationExists("Changing map", "common.phrases")) { PrintToChat(client, "%t", "Changing map", map) } else { PrintToChat(client, "Changing map to %s...", map) }
Version 2
The function checks if the folder exists, if the file exists and if the phrase contains the needed format indexes.
It's coded using SMC Parser, which will prevent any bugs related with multi-line comments in the file.
if (TranslationExists("Changing map", "common.phrases")) { PrintToChat(client, "%t", "Changing map", map); } else { PrintToChat(client, "Changing map to %s...", map); }
The code will cache the valid translations in an array. Then it will simply check if that translation is available in the array in the client language, server language or English.
It's coded using SMC Parser, which will prevent any bugs related with multi-line comments in the file.
This seems pretty broken and super slow (sorry). You absolutely need to use GetClientLanguage as you have this hard coded for English at the moment.
GetClientLanguage is not necessary since I tested and if a client have a language that isn't English and the phrase in his language is missing, sourcemod tries to get the English phrase, so I'm checking the English files directly.
What if there is no english phrase in the file but only spanish?
You'd need to search for the file in all language subfolders inside the translations folder too making this check even slower.
What if there is no english phrase in the file but only spanish?
idk if sourcemod just search for en phrases or if it searches for the translation file in the main folder, need tests, but I think it's the second option
Hey guys, I updated the code, now it will cache the valid translations in an array. And it will simply check in that array if the translation is available in the client language, server language or English. Do you think it's less slow and less broken right now? Give me your feed back.
For those who stumble upon this in the future, and those who don't know about it yet: Latest SourceMod 1.9 builds now support two new functions in order to detect if a translation phrase exists. Here's a snippet from the include.
PHP Code:
/** * Determines if the specified phrase exists within the plugin's * translation cache. * * @param phrase Phrase to look for. * @return True if phrase exists. */ native bool TranslationPhraseExists(const char[] phrase);
/** * Determines if a there is a translation for the speicifed language. * * @param phrase Phrase to check. * @param language Language number. * @return True if translation exists. */ native bool IsTranslatedForLanguage(const char[] phrase, int language);
For those who stumble upon this in the future, and those who don't know about it yet: Latest SourceMod 1.9 builds now support two new functions in order to detect if a translation phrase exists. Here's a snippet from the include.
PHP Code:
/**
* Determines if the specified phrase exists within the plugin's
* translation cache.
*
* @param phrase Phrase to look for.
* @return True if phrase exists.
*/
native bool TranslationPhraseExists(const char[] phrase);
/**
* Determines if a there is a translation for the speicifed language.
*
* @param phrase Phrase to check.
* @param language Language number.
* @return True if translation exists.
*/
native bool IsTranslatedForLanguage(const char[] phrase, int language);