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 
29 {
30  lhs += rhs;
31  return lhs;
32 }
33 
35 inline bilingual_str Untranslated(std::string original) { return {original, original}; }
36 
37 namespace tinyformat {
38 template <typename... Args>
39 bilingual_str format(const bilingual_str& fmt, const Args&... args)
40 {
41  return bilingual_str{format(fmt.original, args...), format(fmt.translated, args...)};
42 }
43 } // namespace tinyformat
44 
46 const extern std::function<std::string(const char*)> G_TRANSLATION_FUN;
47 
52 inline bilingual_str _(const char* psz)
53 {
54  return bilingual_str{psz, G_TRANSLATION_FUN ? (G_TRANSLATION_FUN)(psz) : psz};
55 }
56 
57 #endif // BITCOIN_UTIL_TRANSLATION_H
bilingual_str & operator+=(const bilingual_str &rhs)
Definition: translation.h:20
Bilingual messages:
Definition: translation.h:16
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:35
bilingual_str format(const bilingual_str &fmt, const Args &... args)
Definition: translation.h:39
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
std::string translated
Definition: translation.h:18
bilingual_str operator+(bilingual_str lhs, const bilingual_str &rhs)
Definition: translation.h:28
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:52
std::string original
Definition: translation.h:17