-
-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ICU-22921 Add howto guide to try MF 2.0 final candidate draft impls
See #3334
- Loading branch information
Showing
3 changed files
with
403 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// © 2025 and later: Unicode, Inc. and others. | ||
// License & terms of use: http://www.unicode.org/copyright.html | ||
|
||
#include <iostream> | ||
|
||
#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<UnicodeString, message2::Formattable> 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; | ||
} |
Oops, something went wrong.