X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fi18n.qh;h=137e78204ac60416629468180861c51ea72e1ba2;hb=17e9fbaa18a08e3a84f67955da54527dbf2acee3;hp=3773e16d1d2fdde2c904f6ac37812aab2d5a08a2;hpb=349aeb508e5a3d577df60bef8a552da2db7d928d;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/i18n.qh b/qcsrc/lib/i18n.qh index 3773e16d1..137e78204 100644 --- a/qcsrc/lib/i18n.qh +++ b/qcsrc/lib/i18n.qh @@ -2,6 +2,7 @@ #define I18N_H #include "log.qh" +#include "unsafe.qh" // translation helpers string prvm_language; @@ -20,11 +21,36 @@ string language_filename(string s) return s; } +#ifndef CTX_CACHE + #define CTX_CACHE 1 +#endif + +#if CTX_CACHE + AL_declare(CTX_cache); + STATIC_INIT(CTX_cache) + { + AL_init(CTX_cache, 0, string_null, s); + } + SHUTDOWN(CTX_cache) + { + AL_delete(CTX_cache); + } +#endif + string CTX(string s) { +#if CTX_CACHE + int i = strid(s); + string c = AL_gets(CTX_cache, i); + if (c) return c; +#endif int p = strstrofs(s, "^", 0); - if (p < 0) return s; - return substring(s, p + 1, -1); + string ret = (p < 0) ? s : substring(s, p + 1, -1); +#if CTX_CACHE + LOG_DEBUGF("CTX(\"%s\")\n", s); + AL_sets(CTX_cache, i, ret); +#endif + return ret; } #define ZCTX(s) strzone(CTX(s))