Add Translation Natives (#669)
* Add Translation Natives See #626 * Fix vocab errors * Better description * Bump ITranslator Version * Implement KyleS' Review Requests * Improve documentation
This commit is contained in:
committed by
Kyle Sanderson
parent
43cdf20fd3
commit
d685f30847
@@ -89,6 +89,19 @@ IPhraseFile *CPhraseCollection::GetFile(unsigned int file)
|
||||
return m_Files[file];
|
||||
}
|
||||
|
||||
bool CPhraseCollection::TranslationPhraseExists(const char *key)
|
||||
{
|
||||
for (size_t i = 0; i < m_Files.size(); i++)
|
||||
{
|
||||
if (m_Files[i]->TranslationPhraseExists(key))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TransError CPhraseCollection::FindTranslation(const char *key, unsigned int langid, Translation *pTrans)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
unsigned int GetFileCount();
|
||||
IPhraseFile *GetFile(unsigned int file);
|
||||
void Destroy();
|
||||
bool TranslationPhraseExists(const char *key);
|
||||
TransError FindTranslation(const char *key, unsigned int langid, Translation *pTrans);
|
||||
bool FormatString(
|
||||
char *buffer,
|
||||
|
||||
@@ -672,6 +672,12 @@ TransError CPhraseFile::GetTranslation(const char *szPhrase, unsigned int lang_i
|
||||
return Trans_Okay;
|
||||
}
|
||||
|
||||
bool CPhraseFile::TranslationPhraseExists(const char *phrase)
|
||||
{
|
||||
int address;
|
||||
return m_PhraseLookup.retrieve(phrase, &address);
|
||||
}
|
||||
|
||||
const char *CPhraseFile::GetFilename()
|
||||
{
|
||||
return m_File.c_str();
|
||||
|
||||
@@ -71,6 +71,7 @@ public:
|
||||
void ReparseFile();
|
||||
const char *GetFilename();
|
||||
TransError GetTranslation(const char *szPhrase, unsigned int lang_id, Translation *pTrans);
|
||||
bool TranslationPhraseExists(const char *phrase);
|
||||
public: //ITextListener_SMC
|
||||
void ReadSMC_ParseStart();
|
||||
SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
|
||||
|
||||
@@ -36,6 +36,31 @@
|
||||
#include <ISourceMod.h>
|
||||
#include <am-string.h>
|
||||
|
||||
static cell_t sm_TranslationPhraseExists(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
IPlugin *pl = pluginsys->FindPluginByContext(pCtx->GetContext());
|
||||
IPhraseCollection *collection = pl->GetPhrases();
|
||||
|
||||
char *phrase;
|
||||
pCtx->LocalToString(params[1], &phrase);
|
||||
|
||||
return collection->TranslationPhraseExists(phrase);
|
||||
}
|
||||
|
||||
static cell_t sm_IsTranslatedForLanguage(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
IPlugin *pl = pluginsys->FindPluginByContext(pCtx->GetContext());
|
||||
IPhraseCollection *collection = pl->GetPhrases();
|
||||
|
||||
char *phrase;
|
||||
pCtx->LocalToString(params[1], &phrase);
|
||||
|
||||
int langid = params[2];
|
||||
|
||||
Translation trans;
|
||||
return (collection->FindTranslation(phrase, langid, &trans) == Trans_Okay);
|
||||
}
|
||||
|
||||
static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
char *filename, *ext;
|
||||
@@ -147,6 +172,8 @@ static cell_t sm_GetLanguageByName(IPluginContext *pContext, const cell_t *param
|
||||
|
||||
REGISTER_NATIVES(langNatives)
|
||||
{
|
||||
{"IsTranslatedForLanguage", sm_IsTranslatedForLanguage},
|
||||
{"TranslationPhraseExists", sm_TranslationPhraseExists},
|
||||
{"LoadTranslations", sm_LoadTranslations},
|
||||
{"SetGlobalTransTarget", sm_SetGlobalTransTarget},
|
||||
{"GetClientLanguage", sm_GetClientLanguage},
|
||||
|
||||
Reference in New Issue
Block a user