class Lookup
Defined at line 54 of file ../../src/lib/intl/lookup/cpp/lookup.h
The C++ API used to look up localized messages by their unique message ID.
See the top of this header file for use examples.
Public Methods
void ~Lookup ()
Defined at line 63 of file ../../src/lib/intl/lookup/cpp/lookup.cc
fpromise::result<std::unique_ptr<Lookup>, Lookup::Status> New (const std::vector<std::string> & locale_ids)
Makes a new lookup object, which contains information about the passed-in
locales. At present, if any one of the locales is not present verbatim,
an error is returned.
Errors:
- UNAVAILABLE: one of the requested locale IDs is not avalable for use.
- ARGUMENT_ERROR: the locales ids are malfomed, e.g. nonexistent, or
not a valid UTF8 encoding of the locale ID.
Defined at line 51 of file ../../src/lib/intl/lookup/cpp/lookup.cc
fpromise::result<std::string_view, Lookup::Status> String (uint64_t message_id)
Looks up the message by its unique `message_id`.
Errors:
- UNAVAILABLE: the requested message ID is not present in the loaded
resource bundle.
Defined at line 68 of file ../../src/lib/intl/lookup/cpp/lookup.cc
fpromise::result<std::unique_ptr<Lookup>, Lookup::Status> NewForTest (const std::vector<std::string> & locale_ids)
Instantiates a fake Lookup instance, which is useful for tests that don't
want to make a full end-to-end localization setup.
The fake is simplistic and it is the intention that it provides you with
some default fake behaviors. The behaviors are as follows at the moment,
and more could be added if needed.
- If `locale_ids` contains the string `en-US`, the constructor will
return UNAVAILABLE.
- If the message ID pased to `Lookup::String()` is exactly 1, the fake
returns `Hello, {person}!`, so that you can test 1-parameter formatting.
- Otherwise, for an even mesage ID it returns "Hello world!", or for
an odd message ID returns UNAVAILABLE.
The implementation of the fake itself is done in rust behind a FFI ABI,
see the package //src/lib/intl/lookup/rust for details.
Defined at line 28 of file ../../src/lib/intl/lookup/cpp/lookup.cc
fpromise::result<std::unique_ptr<Lookup>, Lookup::Status> NewForTest (const std::vector<std::string> & locale_ids, const intl_lookup_ops_t ops)
Same as above, except allows you to pass in custom behavior operations
for the fake and affect its behavior. As a user of this library you should
normally never need to use this particular constructor. If you need
special behavior, consider filing a feature request instead to component
"I18N>Localization" at https://fxbug.dev.
Defined at line 37 of file ../../src/lib/intl/lookup/cpp/lookup.cc
Enumerations
enum Status
| Name | Value |
|---|---|
| OK | 0 |
| UNAVAILABLE | 1 |
| ARGUMENT_ERROR | 2 |
| INTERNAL | 111 |
Error codes reported by New() and Lookup() methods.
Defined at line 59 of file ../../src/lib/intl/lookup/cpp/lookup.h
Friends
class Intl_LookupReturnValues_Test
class Intl_CreateError_Test