chromium/base/i18n/message_formatter.h

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_I18N_MESSAGE_FORMATTER_H_
#define BASE_I18N_MESSAGE_FORMATTER_H_

#include <stdint.h>

#include <memory>
#include <string>
#include <string_view>

#include "base/i18n/base_i18n_export.h"
#include "third_party/icu/source/common/unicode/uversion.h"

U_NAMESPACE_BEGIN
class Formattable;
U_NAMESPACE_END

namespace base {

class Time;

namespace i18n {

class MessageFormatter;

namespace internal {

class BASE_I18N_EXPORT MessageArg {};

}  // namespace internal

// Message Formatter with the ICU message format syntax support.
// It can format strings (UTF-8 and UTF-16), numbers and base::Time with
// plural, gender and other 'selectors' support. This is handy if you
// have multiple parameters of differnt types and some of them require
// plural or gender/selector support.
//
// To use this API for locale-sensitive formatting, retrieve a 'message
// template' in the ICU message format from a message bundle (e.g. with
// l10n_util::GetStringUTF16()) and pass it to FormatWith{Named,Numbered}Args.
//
// MessageFormat specs:
//   http://icu-project.org/apiref/icu4j/com/ibm/icu/text/MessageFormat.html
//   http://icu-project.org/apiref/icu4c/classicu_1_1DecimalFormat.html#details
// Examples:
//   http://userguide.icu-project.org/formatparse/messages
//   message_formatter_unittest.cc
//   go/plurals inside Google.
//   TODO(jshin): Document this API in md format docs.
// Caveat:
//   When plural/select/gender is used along with other format specifiers such
//   as date or number, plural/select/gender should be at the top level. It's
//   not an ICU restriction but a constraint imposed by Google's translation
//   infrastructure. Message A does not work. It must be revised to Message B.
//
//     A.
//       Rated <ph name="RATING">{0, number,0.0}<ex>3.2</ex></ph>
//       by {1, plural, =1{a user} other{# users}}
//
//     B.
//       {1, plural,
//         =1{Rated <ph name="RATING">{0, number,0.0}<ex>3.2</ex></ph>
//             by a user.}
//         other{Rated <ph name="RATING">{0, number,0.0}<ex>3.2</ex></ph>
//               by # users.}}

class BASE_I18N_EXPORT MessageFormatter {};

}  // namespace i18n
}  // namespace base

#endif  // BASE_I18N_MESSAGE_FORMATTER_H_