Bitcoin Core 22.99.0
P2P Digital Currency
translation.h
Go to the documentation of this file.
1// Copyright (c) 2019-2020 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_UTIL_TRANSLATION_H
6#define BITCOIN_UTIL_TRANSLATION_H
7
8#include <tinyformat.h>
9#include <functional>
10
17 std::string original;
18 std::string translated;
19
21 {
22 original += rhs.original;
24 return *this;
25 }
26
27 bool empty() const
28 {
29 return original.empty();
30 }
31
32 void clear()
33 {
34 original.clear();
35 translated.clear();
36 }
37};
38
40{
41 lhs += rhs;
42 return lhs;
43}
44
46inline bilingual_str Untranslated(std::string original) { return {original, original}; }
47
48namespace tinyformat {
49template <typename... Args>
50bilingual_str format(const bilingual_str& fmt, const Args&... args)
51{
52 return bilingual_str{format(fmt.original, args...), format(fmt.translated, args...)};
53}
54} // namespace tinyformat
55
57const extern std::function<std::string(const char*)> G_TRANSLATION_FUN;
58
63inline bilingual_str _(const char* psz)
64{
65 return bilingual_str{psz, G_TRANSLATION_FUN ? (G_TRANSLATION_FUN)(psz) : psz};
66}
67
68#endif // BITCOIN_UTIL_TRANSLATION_H
Definition: fs.h:231
void format(std::ostream &out, const char *fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1062
Bilingual messages:
Definition: translation.h:16
void clear()
Definition: translation.h:32
bool empty() const
Definition: translation.h:27
std::string translated
Definition: translation.h:18
std::string original
Definition: translation.h:17
bilingual_str & operator+=(const bilingual_str &rhs)
Definition: translation.h:20
const std::function< std::string(const char *)> G_TRANSLATION_FUN
Translate a message to the native language of the user.
Definition: bitcoin-cli.cpp:43
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:63
bilingual_str operator+(bilingual_str lhs, const bilingual_str &rhs)
Definition: translation.h:39
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:46