OpenClonk
C4LangStringTable.h
Go to the documentation of this file.
1
/*
2
* OpenClonk, http://www.openclonk.org
3
*
4
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
6
*
7
* Distributed under the terms of the ISC license; see accompanying file
8
* "COPYING" for details.
9
*
10
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
11
* See accompanying file "TRADEMARK" for details.
12
*
13
* To redistribute this file separately, substitute the full license texts
14
* for the above references.
15
*/
16
// Loads StringTbl* and replaces $..$-strings by localized versions
17
18
#ifndef INC_C4LangStringTable
19
#define INC_C4LangStringTable
20
21
#include "
c4group/C4ComponentHost.h
"
22
23
class
C4LangStringTable
:
public
C4ComponentHost
24
{
25
// Contains the localization string->string mapping. Populated lazily from PopulateStringTable, thus mutable.
26
typedef
std::map<std::string, std::string> Table;
27
mutable
Table strings;
28
void
PopulateStringTable()
const
;
29
int32_t ref_count{1};
// ref counter initialized to 1 on ctor; delete when zero is reached
30
public
:
31
C4LangStringTable
() =
default
;
32
const
std::string &
Translate
(
const
std::string &
text
)
const
;
33
bool
HasTranslation
(
const
std::string &
text
)
const
;
34
// do replacement in buffer
35
// if any replacement is done, the buffer will be realloced
36
void
ReplaceStrings
(
StdStrBuf
&rBuf);
37
void
ReplaceStrings
(
const
StdStrBuf
&rBuf,
StdStrBuf
&rTarget);
38
39
void
AddRef
() { ++ref_count; }
40
void
DelRef
() {
if
(!--ref_count)
delete
this
; }
41
42
class
NoSuchTranslation
:
public
std::runtime_error
43
{
44
public
:
45
NoSuchTranslation
(
const
std::string &
text
) :
std
::runtime_error(R
"(No such translation: ")" +
text
+ R
"(")") {}
46
};
47
48
static
inline
C4LangStringTable
&
GetSystemStringTable
() {
return
system_string_table; }
49
protected
:
50
void
OnLoad
()
override
{ strings.clear(); }
// Make sure we re-populate when the string table is reloaded
51
52
private
:
53
static
C4LangStringTable
system_string_table;
54
};
55
56
#endif
// INC_C4LangStringTable
C4ComponentHost.h
C4ComponentHost
Definition:
C4ComponentHost.h:24
C4LangStringTable::NoSuchTranslation
Definition:
C4LangStringTable.h:43
C4LangStringTable::NoSuchTranslation::NoSuchTranslation
NoSuchTranslation(const std::string &text)
Definition:
C4LangStringTable.h:45
C4LangStringTable
Definition:
C4LangStringTable.h:24
C4LangStringTable::Translate
const std::string & Translate(const std::string &text) const
Definition:
C4LangStringTable.cpp:30
C4LangStringTable::HasTranslation
bool HasTranslation(const std::string &text) const
Definition:
C4LangStringTable.cpp:23
C4LangStringTable::C4LangStringTable
C4LangStringTable()=default
C4LangStringTable::ReplaceStrings
void ReplaceStrings(StdStrBuf &rBuf)
Definition:
C4LangStringTable.cpp:168
C4LangStringTable::AddRef
void AddRef()
Definition:
C4LangStringTable.h:39
C4LangStringTable::GetSystemStringTable
static C4LangStringTable & GetSystemStringTable()
Definition:
C4LangStringTable.h:48
C4LangStringTable::DelRef
void DelRef()
Definition:
C4LangStringTable.h:40
C4LangStringTable::OnLoad
void OnLoad() override
Definition:
C4LangStringTable.h:50
StdStrBuf
Definition:
StdBuf.h:385
C4ScriptGuiWindowPropertyName::text
@ text
Definition:
C4ScriptGuiWindow.h:53
std
Definition:
C4PuncherHash.h:52
openclonk
src
c4group
C4LangStringTable.h
Generated on Fri May 16 2025 04:33:13 for OpenClonk by
1.9.1