1.1 --- a/core/sm_stringutil.cpp Sun Oct 21 15:18:01 2007 +0000
1.2 +++ b/core/sm_stringutil.cpp Sun Oct 21 17:58:35 2007 +0000
1.3 @@ -87,23 +87,43 @@
1.4 return (err == Trans_Okay) ? true : false;
1.5 }
1.6
1.7 -size_t Translate(char *buffer, size_t maxlen, IPluginContext *pCtx, const char *key, cell_t target, const cell_t *params, int *arg, bool *error)
1.8 +inline void ReorderTranslationParams(const Translation *pTrans, cell_t *params)
1.9 +{
1.10 + cell_t new_params[MAX_TRANSLATE_PARAMS];
1.11 + for (unsigned int i = 0; i < pTrans->fmt_count; i++)
1.12 + {
1.13 + new_params[i] = params[pTrans->fmt_order[i]];
1.14 + }
1.15 + memcpy(params, new_params, pTrans->fmt_count * sizeof(cell_t));
1.16 +}
1.17 +
1.18 +size_t Translate(char *buffer,
1.19 + size_t maxlen,
1.20 + IPluginContext *pCtx,
1.21 + const char *key,
1.22 + cell_t target,
1.23 + const cell_t *params,
1.24 + int *arg,
1.25 + bool *error)
1.26 {
1.27 unsigned int langid;
1.28 *error = false;
1.29 Translation pTrans;
1.30 CPlugin *pl = (CPlugin *)g_PluginSys.FindPluginByContext(pCtx->GetContext());
1.31 size_t langcount = pl->GetLangFileCount();
1.32 - void *new_params[MAX_TRANSLATE_PARAMS];
1.33 unsigned int max_params = 0;
1.34
1.35 try_serverlang:
1.36 if (target == LANG_SERVER)
1.37 {
1.38 langid = g_Translator.GetServerLanguage();
1.39 - } else if ((target >= 1) && (target <= g_Players.GetMaxClients())) {
1.40 + }
1.41 + else if ((target >= 1) && (target <= g_Players.GetMaxClients()))
1.42 + {
1.43 langid = g_Translator.GetClientLanguage(target);
1.44 - } else {
1.45 + }
1.46 + else
1.47 + {
1.48 pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Translation failed: invalid client index %d", target);
1.49 goto error_out;
1.50 }
1.51 @@ -114,13 +134,17 @@
1.52 {
1.53 target = LANG_SERVER;
1.54 goto try_serverlang;
1.55 - } else if (langid != LANGUAGE_ENGLISH) {
1.56 + }
1.57 + else if (langid != LANGUAGE_ENGLISH)
1.58 + {
1.59 if (!TryTranslation(pl, key, LANGUAGE_ENGLISH, langcount, &pTrans))
1.60 {
1.61 pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Language phrase \"%s\" not found", key);
1.62 goto error_out;
1.63 }
1.64 - } else {
1.65 + }
1.66 + else
1.67 + {
1.68 pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Language phrase \"%s\" not found", key);
1.69 goto error_out;
1.70 }
1.71 @@ -140,22 +164,18 @@
1.72 goto error_out;
1.73 }
1.74
1.75 - /* Translate the parameters to raw pointers */
1.76 - for (size_t i=0; i<max_params; i++)
1.77 - {
1.78 - pCtx->LocalToPhysAddr(params[*arg], reinterpret_cast<cell_t **>(&new_params[i]));
1.79 - (*arg)++;
1.80 - }
1.81 + /* Re-order the parameters that this translation requires */
1.82 + ReorderTranslationParams(&pTrans, const_cast<cell_t *>(¶ms[*arg]));
1.83 }
1.84
1.85 - return g_Translator.Translate(buffer, maxlen, new_params, &pTrans);
1.86 + /* Now, call back into atcprintf() which is re-entrant */
1.87 + return atcprintf(buffer, maxlen, pTrans.szPhrase, pCtx, params, arg);
1.88 +
1.89 error_out:
1.90 *error = true;
1.91 return 0;
1.92 }
1.93
1.94 -//:TODO: review this code before we choose a license
1.95 -
1.96 void AddString(char **buf_p, size_t &maxlen, const char *string, int width, int prec)
1.97 {
1.98 int size = 0;