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.
if (TranslationExists(client, "Changing map")) { PrintToChat(client, "%t", "Changing map", "de_dust2"); } else { PrintToChat(client, "Changing map to %s...", "de_dust2"); }
KyleS
06-25-2017 12:33
Re: Function to check if translation exists
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.
joao7yt
06-25-2017 13:05
Re: Function to check if translation exists
Quote:
Originally Posted by KyleS
(Post 2531634)
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.
Peace-Maker
06-26-2017 21:22
Re: Function to check if translation exists
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.
joao7yt
06-26-2017 21:31
Re: Function to check if translation exists
Quote:
Originally Posted by Peace-Maker
(Post 2531932)
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
Fyren
06-26-2017 22:36
Re: Function to check if translation exists
It tries the target's language (assuming %T), then it tries the server language, then it tries English.
joao7yt
06-27-2017 16:34
Re: Function to check if translation exists
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.
headline
11-21-2017 22:46
Re: Function to check if translation exists
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);
joao7yt
11-22-2017 03:31
Re: Function to check if translation exists
Quote:
Originally Posted by Headline
(Post 2562086)
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);