Skip to content

Commit

Permalink
Personal Fork Testing PR to update GH Pages demo site for User Guide …
Browse files Browse the repository at this point in the history
…changes (#70)

* ICU-22921 Add howto guide to try MF 2.0 final candidate draft impls

* ICU-22921 Update C++ Windows instructions

* Apply suggestions from code review

Co-authored-by: Mihai Nita <[email protected]>

* ICU-22921 Adjust indentation spaces

* ICU-22921 Apply review feedback

* ICU-22921 New lines for readability

* ICU-22921 Add C++ file of demo code that users can download

* ICU-22921 Move quick start Visual Studio example before harder cases

---------

Co-authored-by: Mihai Nita <[email protected]>
  • Loading branch information
echeran and mihnita authored Jan 15, 2025
1 parent 13a5e29 commit 45b7e45
Show file tree
Hide file tree
Showing 3 changed files with 400 additions and 0 deletions.
Binary file added docs/userguide/format_parse/messages/HelloMF2.zip
Binary file not shown.
34 changes: 34 additions & 0 deletions docs/userguide/format_parse/messages/hello_mf2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#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;
}
Loading

0 comments on commit 45b7e45

Please sign in to comment.