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