Showing content from https://unicode-org.github.io/icu/userguide/format_parse/messages/hello_mf2.cpp below:
// © 2025 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html #include #include "unicode/utypes.h" #include "unicode/calendar.h" #include "unicode/errorcode.h" #include "unicode/locid.h" #include "unicode/messageformat2.h" using namespace icu; int main() { ErrorCode errorCode; UParseError parseError; icu::Calendar* cal(Calendar::createInstance(errorCode)); cal->set(2025, Calendar::JANUARY, 28); UDate date = cal->getTime(errorCode); message2::MessageFormatter::Builder builder(errorCode); message2::MessageFormatter mf = builder .setPattern("Hello {$user}, today is {$now :date style=long}!", parseError, errorCode) .setLocale(Locale("en_US")) .build(errorCode); std::map argsBuilder; argsBuilder["user"] = message2::Formattable("John"); argsBuilder["now"] = message2::Formattable::forDate(date); message2::MessageArguments arguments(argsBuilder, errorCode); icu::UnicodeString result = mf.formatToString(arguments, errorCode); std::string strResult; result.toUTF8String(strResult); std::cout << strResult << std::endl; }
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4