Bitcoin Core 28.99.0
P2P Digital Currency
translation_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 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#include <tinyformat.h>
6#include <util/translation.h>
7
8#include <boost/test/unit_test.hpp>
9
10BOOST_AUTO_TEST_SUITE(translation_tests)
11
12static TranslateFn translate{[](const char * str) { return strprintf("t(%s)", str); }};
13
14// Custom translation function _t(), similar to _() but internal to this test.
15consteval auto _t(util::TranslatedLiteral str)
16{
18 return str;
19}
20
21BOOST_AUTO_TEST_CASE(translation_namedparams)
22{
23 bilingual_str arg{"original", "translated"};
24 bilingual_str result{strprintf(_t("original [%s]"), arg)};
25 BOOST_CHECK_EQUAL(result.original, "original [original]");
26 BOOST_CHECK_EQUAL(result.translated, "t(original [translated])");
27
28 util::TranslatedLiteral arg2{"original", &translate};
29 bilingual_str result2{strprintf(_t("original [%s]"), arg2)};
30 BOOST_CHECK_EQUAL(result2.original, "original [original]");
31 BOOST_CHECK_EQUAL(result2.translated, "t(original [t(original)])");
32}
33
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
Bilingual messages:
Definition: translation.h:24
Compile-time literal string that can be translated with an optional translation function.
Definition: translation.h:55
const TranslateFn * translate_fn
Definition: translation.h:57
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172
std::function< std::string(const char *)> TranslateFn
Translate a message to the native language of the user.
Definition: translation.h:16
consteval auto _t(util::TranslatedLiteral str)
BOOST_AUTO_TEST_CASE(translation_namedparams)
static TranslateFn translate