MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / Translate

Function Translate

core/logic/sprintf.cpp:66–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66size_t Translate(char *buffer,
67 size_t maxlen,
68 IPluginContext *pCtx,
69 const char *key,
70 cell_t target,
71 const cell_t *params,
72 int *arg,
73 bool *error)
74{
75 unsigned int langid;
76 *error = false;
77 Translation pTrans;
78 IPlugin *pl = scripts->FindPluginByContext(pCtx);
79 unsigned int max_params = 0;
80 IPhraseCollection *pPhrases;
81
82 pPhrases = pl->GetPhrases();
83
84try_serverlang:
85 if (target == SOURCEMOD_SERVER_LANGUAGE)
86 {
87 langid = g_Translator.GetServerLanguage();
88 }
89 else if ((target >= 1) && (target <= bridge->MaxClients()))
90 {
91 langid = g_Translator.GetClientLanguage(target);
92 }
93 else
94 {
95 pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Translation failed: invalid client index %d (arg %d)", target, *arg);
96 goto error_out;
97 }
98
99 if (pPhrases->FindTranslation(key, langid, &pTrans) != Trans_Okay)
100 {
101 if (target != SOURCEMOD_SERVER_LANGUAGE && langid != g_Translator.GetServerLanguage())
102 {
103 target = SOURCEMOD_SERVER_LANGUAGE;
104 goto try_serverlang;
105 }
106 else if (langid != SOURCEMOD_LANGUAGE_ENGLISH)
107 {
108 if (pPhrases->FindTranslation(key, SOURCEMOD_LANGUAGE_ENGLISH, &pTrans) != Trans_Okay)
109 {
110 pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Language phrase \"%s\" not found (arg %d)", key, *arg);
111 goto error_out;
112 }
113 }
114 else
115 {
116 pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Language phrase \"%s\" not found (arg %d)", key, *arg);
117 goto error_out;
118 }
119 }
120
121 max_params = pTrans.fmt_count;
122
123 if (max_params)

Callers 1

atcprintfFunction · 0.70

Calls 8

ReorderTranslationParamsFunction · 0.85
atcprintfFunction · 0.85
GetPhrasesMethod · 0.80
GetServerLanguageMethod · 0.80
GetClientLanguageMethod · 0.80
FindTranslationMethod · 0.80
FindPluginByContextMethod · 0.45
MaxClientsMethod · 0.45

Tested by

no test coverage detected