]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/i18n.qh
take3: format 903 files
[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                 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 ERASEABLE
44 string CTX(string s)
45 {
46 #if CTX_CACHE
47         string c = HM_gets(CTX_cache, s);
48         if (c != "") { return c; }
49 #endif
50         int p = strstrofs(s, "^", 0);
51         string ret = (p < 0) ? s : substring(s, p + 1, -1);
52 #if CTX_CACHE
53         LOG_DEBUGF("CTX(\"%s\")", s);
54         HM_sets(CTX_cache, s, ret);
55 #endif
56         return ret;
57 }
58
59 #define ZCTX(s) strzone(CTX(s))