class MessageFormatter

Defined at line 28 of file ../../src/ui/a11y/lib/screen_reader/i18n/message_formatter.h

A MessageFormatter provides an API for callers to provide a message ID along with optional

argument names and values, and receive a formatted message back. This class does not load the

messages itself. It queries the |lookup_| interface, which is received in the constructor. To

obtain messages localized in a specific locale, callers must first load the desired resources

through |lookup_|, and then access them through this class via their message IDs. For this

class, message IDs point to a valid icu::MessageFormat pattern in |lookup_|. The language

parameter in the constructor affects how certain icu::MessageFormat patterns are formatted,

matching what is expected in that language. More info can be found in the icu::MessageFormat

documentation.

Public Methods

void MessageFormatter (icu::Locale locale, std::unique_ptr<intl::Lookup> lookup)

|lookup_| must be initialized and holds the icu::MessageFormat patterns.

Defined at line 16 of file ../../src/ui/a11y/lib/screen_reader/i18n/message_formatter.cc

std::optional<std::string> FormatStringById (const uint64_t id, const std::vector<std::string> & arg_names, const std::vector<ArgValue> & arg_values)

Formats a icu::MessageFormat pattern pointed by |id|, optionally using |arg_names| which map to

|arg_values|. Returns the formatted string, in UTF-8 when successful. If it fails,

std::nullopt. The number or |arg_names| must match the number of |arg_values|. If one of

|arg_names| does not exist in the pattern, the formatting returns an error. For now, no complex

error codes are needed, so std::optional is used. If necessary, it is an easy change to

introduce custom error codes.

Defined at line 19 of file ../../src/ui/a11y/lib/screen_reader/i18n/message_formatter.cc

void ~MessageFormatter ()

Defined at line 34 of file ../../src/ui/a11y/lib/screen_reader/i18n/message_formatter.h

const icu::Locale & locale ()

Returns the icu locale used to format messages.

Defined at line 47 of file ../../src/ui/a11y/lib/screen_reader/i18n/message_formatter.h

Protected Methods

void MessageFormatter ()

For mocks.

Defined at line 51 of file ../../src/ui/a11y/lib/screen_reader/i18n/message_formatter.h