mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Extend bilingual_str support for tinyformat
Previous bilingual_str tinyformat::format accepted bilingual format strings,
but not bilingual arguments. Extend it to accept both. This is useful when
embedding one translated string inside another translated string, for example:
`strprintf(_("Error: %s"), message)` which would fail previously if `message`
was a bilingual_str.
This commit is contained in:
21
src/test/translation_tests.cpp
Normal file
21
src/test/translation_tests.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2023 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <tinyformat.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(translation_tests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(translation_namedparams)
|
||||
{
|
||||
bilingual_str arg{"original", "translated"};
|
||||
bilingual_str format{"original [%s]", "translated [%s]"};
|
||||
bilingual_str result{strprintf(format, arg)};
|
||||
BOOST_CHECK_EQUAL(result.original, "original [original]");
|
||||
BOOST_CHECK_EQUAL(result.translated, "translated [translated]");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
Reference in New Issue
Block a user