]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/i18n.qh
language_filename: deprecate
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / i18n.qh
index 87c41cda5dc209f228c1dc15481340acc817fab7..fd8ec83066ec7438fc3c9f8302c8efbcc034d90b 100644 (file)
@@ -2,31 +2,58 @@
 #define I18N_H
 
 #include "log.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
+       ArrayList CTX_cache;
+       STATIC_INIT(CTX_cache)
+       {
+               AL_NEW(CTX_cache, 0, string_null, s);
+       }
+       SHUTDOWN(CTX_cache)
+       {
+               AL_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
+               int i = strid(s);
+               string c = AL_gets(CTX_cache, i);
+               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\")\n", s);
+               AL_sets(CTX_cache, i, ret);
+#endif
+       return ret;
 }
 
 #define ZCTX(s) strzone(CTX(s))