X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fi18n.qh;h=8ebedb76f65f66110d3fd26ffaa46277e1b24021;hb=c58f64ef151dab8679008c4afa1737f69b948ba0;hp=87c41cda5dc209f228c1dc15481340acc817fab7;hpb=a4594d94df1eb60aca616cccd45df07e561ffa01;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/i18n.qh b/qcsrc/lib/i18n.qh index 87c41cda5..8ebedb76f 100644 --- a/qcsrc/lib/i18n.qh +++ b/qcsrc/lib/i18n.qh @@ -1,34 +1,58 @@ -#ifndef I18N_H -#define I18N_H +#pragma once #include "log.qh" +#include "map.qh" +#include "unsafe.qh" // translation helpers string prvm_language; +/** + * @deprecated prefer _("translated") + */ string language_filename(string s) { - string fn = prvm_language; - if (fn == "" || fn == "dump") - return s; - fn = strcat(s, ".", fn); - int fh = fopen(fn, FILE_READ); - if (fh >= 0) - { - fclose(fh); - return fn; - } - return s; + string fn = prvm_language; + if (fn == "" || fn == "dump") return s; + fn = strcat(s, ".", fn); + int fh = fopen(fn, FILE_READ); + if (fh >= 0) + { + fclose(fh); + return fn; + } + return s; } +#ifndef CTX_CACHE + #define CTX_CACHE 1 +#endif + +#if CTX_CACHE + HashMap CTX_cache; + STATIC_INIT(CTX_cache) + { + HM_NEW(CTX_cache); + } + SHUTDOWN(CTX_cache) + { + HM_DELETE(CTX_cache); + } +#endif + string CTX(string s) { - int p = strstrofs(s, "^", 0); - if (p < 0) - return s; - return substring(s, p + 1, -1); +#if CTX_CACHE + string c = HM_gets(CTX_cache, s); + if (c != "") return c; +#endif + int p = strstrofs(s, "^", 0); + string ret = (p < 0) ? s : substring(s, p + 1, -1); +#if CTX_CACHE + LOG_DEBUGF("CTX(\"%s\")", s); + HM_sets(CTX_cache, s, ret); +#endif + return ret; } #define ZCTX(s) strzone(CTX(s)) - -#endif