International Components for Unicode (ICU) use in Fuchsia

Fuchsia uses the ICU library for the commonly shared internationalization services such as date, time, timezone, locale and language handling.

The ICU library consists roughly of two different parts: the ICU library code which contains the ICU algorithms, and the ICU library data, which contains locale-specific information that is packaged for independent reuse.

Add ICU library dependencies

Include the necessary library dependencies in your file:


The ICU library is a single third-party dependency //third_party/icu:



The rust_icu library is subdivided into several crates that correspond to specific ICU4C headers:


Import ICU headers

Add the imports for the specific ICU library features your program requires:


The ICU documentation provides additional information about the APIs the library supports.

#include "third_party/icu/source/common/unicode/locid.h"
#include "third_party/icu/source/common/unicode/unistr.h"
#include "third_party/icu/source/i18n/unicode/calendar.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
#include "third_party/icu/source/i18n/unicode/tzfmt.h"


The rust_icu reference provides additional information about the APIs the library supports.

use {
    anyhow::Error, fidl_fuchsia_examples_intl_wisdom as fwisdom, fidl_fuchsia_intl as fintl,
    rust_icu_sys as usys, rust_icu_ucal as ucal, rust_icu_udat as udat, rust_icu_uloc as uloc,
    rust_icu_ustring as ustring, std::convert::TryFrom,

Initialize ICU data

In Fuchsia, the ICU data must be loaded by the program at runtime. Initialize the ICU data with the icu_data library:


ZX_ASSERT(icu_data::Initialize() == ZX_OK);


// Force the loading of ICU data at the beginning of the program.  Since
// Fuchsia's ICU does not have ``, we must load the data here
// so that locales could be used in the server.
let _loader = icu_data::Loader::new()?;

For more details instructions on loading ICU data from various sources, see ICU timezone data.

You are now ready to use the ICU library features in your Fuchsia program.