]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/i18n.qh
Unnecessary newlines are unnecessary
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / i18n.qh
1 #pragma once
2
3 #include "log.qh"
4 #include "map.qh"
5 #include "unsafe.qh"
6
7 // translation helpers
8 string prvm_language;
9
10 /**
11  * @deprecated prefer _("translated")
12  */
13 string language_filename(string s)
14 {
15         string fn = prvm_language;
16         if (fn == "" || fn == "dump") return s;
17         fn = strcat(s, ".", fn);
18         int fh = fopen(fn, FILE_READ);
19         if (fh >= 0)
20         {
21                 fclose(fh);
22                 return fn;
23         }
24         return s;
25 }
26
27 #ifndef CTX_CACHE
28         #define CTX_CACHE 1
29 #endif
30
31 #if CTX_CACHE
32         HashMap CTX_cache;
33         STATIC_INIT(CTX_cache)
34         {
35                 HM_NEW(CTX_cache);
36         }
37         SHUTDOWN(CTX_cache)
38         {
39                 HM_DELETE(CTX_cache);
40         }
41 #endif
42
43 string CTX(string s)
44 {
45 #if CTX_CACHE
46                 string c = HM_gets(CTX_cache, s);
47                 if (c != "") return c;
48 #endif
49         int p = strstrofs(s, "^", 0);
50         string ret = (p < 0) ? s : substring(s, p + 1, -1);
51 #if CTX_CACHE
52         LOG_DEBUGF("CTX(\"%s\")", s);
53                 HM_sets(CTX_cache, s, ret);
54 #endif
55         return ret;
56 }
57
58 #define ZCTX(s) strzone(CTX(s))