]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/i18n.qh
Merge branch 'master' into Lyberta/TeamplayOverhaul
[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 ERASEABLE
14 string language_filename(string s)
15 {
16         string fn = prvm_language;
17         if (fn == "" || fn == "dump") return s;
18         fn = strcat(s, ".", fn);
19         int fh = fopen(fn, FILE_READ);
20         if (fh >= 0)
21         {
22                 fclose(fh);
23                 return fn;
24         }
25         return s;
26 }
27
28 #ifndef CTX_CACHE
29         #define CTX_CACHE 1
30 #endif
31
32 #if CTX_CACHE
33         HashMap CTX_cache;
34         STATIC_INIT(CTX_cache)
35         {
36                 HM_NEW(CTX_cache);
37         }
38         SHUTDOWN(CTX_cache)
39         {
40                 HM_DELETE(CTX_cache);
41         }
42 #endif
43
44 ERASEABLE
45 string CTX(string s)
46 {
47 #if CTX_CACHE
48         string c = HM_gets(CTX_cache, s);
49         if (c != "") return c;
50 #endif
51         int p = strstrofs(s, "^", 0);
52         string ret = (p < 0) ? s : substring(s, p + 1, -1);
53 #if CTX_CACHE
54         LOG_DEBUGF("CTX(\"%s\")", s);
55         HM_sets(CTX_cache, s, ret);
56 #endif
57         return ret;
58 }
59
60 #define ZCTX(s) strzone(CTX(s))