Bitcoin ABC  0.24.7
P2P Digital Currency
translation.h
Go to the documentation of this file.
1 // Copyright (c) 2019 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 
10 #include <functional>
11 
17 struct bilingual_str {
18  std::string original;
19  std::string translated;
20 
22  original += rhs.original;
23  translated += rhs.translated;
24  return *this;
25  }
26 
27  bool empty() const { return original.empty(); }
28 };
29 
31  lhs += rhs;
32  return lhs;
33 }
34 
36 inline bilingual_str Untranslated(std::string original) {
37  return {original, original};
38 }
39 
40 namespace tinyformat {
41 template <typename... Args>
42 bilingual_str format(const bilingual_str &fmt, const Args &... args) {
43  return bilingual_str{format(fmt.original, args...),
44  format(fmt.translated, args...)};
45 }
46 } // namespace tinyformat
47 
49 const extern std::function<std::string(const char *)> G_TRANSLATION_FUN;
50 
55 inline bilingual_str _(const char *psz) {
56  return bilingual_str{psz,
57  G_TRANSLATION_FUN ? (G_TRANSLATION_FUN)(psz) : psz};
58 }
59 
60 #endif // BITCOIN_UTIL_TRANSLATION_H
tinyformat
Definition: tinyformat.h:128
_
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:55
tinyformat::format
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:1111
bilingual_str
Bilingual messages:
Definition: translation.h:17
G_TRANSLATION_FUN
const std::function< std::string(const char *)> G_TRANSLATION_FUN
Translate a message to the native language of the user.
Definition: bitcoin-cli.cpp:34
bilingual_str::empty
bool empty() const
Definition: translation.h:27
tinyformat.h
Untranslated
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:36
operator+
bilingual_str operator+(bilingual_str lhs, const bilingual_str &rhs)
Definition: translation.h:30
bilingual_str::translated
std::string translated
Definition: translation.h:19
bilingual_str::original
std::string original
Definition: translation.h:18
bilingual_str::operator+=
bilingual_str & operator+=(const bilingual_str &rhs)
Definition: translation.h:21