Xonotic
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
8
string
prvm_language
;
9
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
caret_ofs =
strstrofs
(s,
"^"
, 0);
52
string
ret = s;
53
// empty (caret_ofs == 0) and one char (caret_ofs == 1) prefixes are invalid
54
if
(caret_ofs > 1)
55
{
56
int
space_ofs =
strstrofs
(
substring
(s, 0, caret_ofs),
" "
, 0);
57
// prefixes containing a space are invalid (likely the caret is part of a color code)
58
if
(space_ofs < 0 || space_ofs > caret_ofs)
59
ret =
substring
(s, caret_ofs + 1, -1);
60
}
61
#if CTX_CACHE
62
LOG_DEBUGF
(
"CTX(\"%s\")"
, s);
63
HM_sets
(
CTX_cache
, s, ret);
64
#endif
65
return
ret;
66
}
67
68
#define ZCTX(s) strzone(CTX(s))
HM_NEW
#define HM_NEW(this)
Definition:
map.qh:29
fopen
float fopen(string filename, float mode)
FILE_READ
const float FILE_READ
Definition:
csprogsdefs.qc:231
HM_gets
#define HM_gets(this, k)
Definition:
map.qh:96
ERASEABLE
#define ERASEABLE
Definition:
_all.inc:35
HM_sets
#define HM_sets(this, key, val)
Definition:
map.qh:106
SHUTDOWN
SHUTDOWN(CTX_cache)
Definition:
i18n.qh:38
fclose
void fclose(float fhandle)
strcat
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
strstrofs
#define strstrofs
Definition:
dpextensions.qh:42
substring
string substring(string s, float start, float length)
language_filename
ERASEABLE string language_filename(string s)
Definition:
i18n.qh:14
prvm_language
string prvm_language
Definition:
i18n.qh:8
unsafe.qh
STATIC_INIT
STATIC_INIT(CTX_cache)
Definition:
i18n.qh:34
log.qh
map.qh
CTX
ERASEABLE string CTX(string s)
Definition:
i18n.qh:45
CTX_cache
HashMap CTX_cache
Definition:
i18n.qh:33
HM_DELETE
#define HM_DELETE(this)
Definition:
map.qh:88
HashMap
int HashMap
Definition:
map.qh:22
LOG_DEBUGF
#define LOG_DEBUGF(...)
Definition:
log.qh:86
lib
i18n.qh
Generated on Thu Mar 17 2022 17:26:29 for Xonotic by
1.8.13