Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
i18n.qh
Go to the documentation of this file.
1#pragma once
2
3#include "log.qh"
4#include "map.qh"
5#include "unsafe.qh"
6
7// translation helpers
9
14string language_filename(string s)
15{
16 string fn = prvm_language;
17 if (fn == "" || fn == "en" || fn == "dump")
18 return s;
19 fn = strcat(s, ".", fn);
20 int fh = fopen(fn, FILE_READ);
21 if (fh >= 0)
22 {
23 fclose(fh);
24 return fn;
25 }
26 return s;
27}
28
29#ifndef CTX_CACHE
30 #define CTX_CACHE 1
31#endif
32
33#if CTX_CACHE
34 HashMap CTX_cache;
35 STATIC_INIT(CTX_cache)
36 {
37 HM_NEW(CTX_cache);
38 }
39 SHUTDOWN(CTX_cache)
40 {
41 HM_DELETE(CTX_cache);
42 }
43#endif
44
46string CTX(string s)
47{
48#if CTX_CACHE
49 string c = HM_gets(CTX_cache, s);
50 if (c != "")
51 return c;
52#endif
53 int caret_ofs = strstrofs(s, "^", 0);
54 string ret = s;
55 // empty (caret_ofs == 0) and one char (caret_ofs == 1) prefixes are invalid
56 if (caret_ofs > 1)
57 {
58 int space_ofs = strstrofs(substring(s, 0, caret_ofs), " ", 0);
59 // prefixes containing a space are invalid (likely the caret is part of a color code)
60 if (space_ofs < 0 || space_ofs > caret_ofs)
61 ret = substring(s, caret_ofs + 1, -1);
62 }
63#if CTX_CACHE
64 LOG_DEBUGF("CTX(\"%s\")", s);
65 HM_sets(CTX_cache, s, ret);
66#endif
67 return ret;
68}
69
70#define ZCTX(s) strzone(CTX(s))
const float FILE_READ
#define strstrofs
ERASEABLE string CTX(string s)
Definition i18n.qh:46
string prvm_language
Definition i18n.qh:8
ERASEABLE string language_filename(string s)
Definition i18n.qh:14
#define ERASEABLE
Definition _all.inc:37
#define LOG_DEBUGF(...)
Definition log.qh:79
#define HM_NEW(this)
Definition map.qh:29
#define HM_DELETE(this)
Definition map.qh:90
#define HM_sets(this, key, val)
Definition map.qh:108
#define HM_gets(this, k)
Definition map.qh:98
int HashMap
Definition map.qh:22
void fclose(float fhandle)
string substring(string s, float start, float length)
float fopen(string filename, float mode)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define SHUTDOWN(func)
before shutdown
Definition static.qh:50
#define STATIC_INIT(func)
during worldspawn
Definition static.qh:33