Fuchsia uses the [ICU library](http://site.icu-project.org/) 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.

> [!NOTE]
> **Note:** For a complete example of using the ICU library in Fuchsia, see [`//examples/intl/wisdom`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/examples/intl/wisdom/).

## Add ICU library dependencies

Include the necessary library dependencies in your `BUILD.gn` file:

### C++

The ICU library is a single third-party dependency, used as `${icu_root}:icu`

    third_party_icu_headers("icu_headers") {
      headers = [
        "third_party/icu/source/common/unicode/locid.h",
        "third_party/icu/source/common/unicode/ucnv.h",
        "third_party/icu/source/common/unicode/unistr.h",
        "third_party/icu/source/i18n/unicode/calendar.h",
        "third_party/icu/source/i18n/unicode/gregocal.h",
        "third_party/icu/source/i18n/unicode/smpdtfmt.h",
        "third_party/icu/source/i18n/unicode/timezone.h",
        "third_party/icu/source/i18n/unicode/tzfmt.h",
      ]
    }

    source_set("lib") {
      sources = [
        "intl_wisdom_client.cc",
        "intl_wisdom_client.h",
      ]

      public_deps = [
        ":icu_headers",
        "//examples/intl/wisdom/fidl:wisdom_hlcpp",
        "//sdk/lib/sys/cpp",
      ]
    }

### Rust

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

    deps += [
      "//third_party/rust_crates:rust_icu_sys",
      "//third_party/rust_crates:rust_icu_ucal",
      "//third_party/rust_crates:rust_icu_udat",
      "//third_party/rust_crates:rust_icu_uloc",
      "//third_party/rust_crates:rust_icu_ustring",
    ]
    non_rust_deps = [ "//src/lib/icu:lib" ]

## Import ICU headers

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

### C++

The [ICU documentation](https://unicode-org.github.io/icu/) provides additional
information about the APIs the library supports.

    #include "examples/intl/wisdom/cpp/client/icu_headers.h"

### Rust

The [rust_icu reference](https://docs.rs/crate/rust_icu/1.0.1) provides additional
information about the APIs the library supports.

    use anyhow::Error;
    use {
        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,
    };

## 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:

### C++

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

### Rust

    // Force the loading of ICU data at the beginning of the program.  Since
    // Fuchsia's ICU does not have `libicudata.so`, 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](https://fuchsia.dev/fuchsia-src/development/internationalization/icu_data).

You are now ready to use the ICU library features in your Fuchsia program.
[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/development/internationalization/icu.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/development/internationalization/icu.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/development/internationalization/icu.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/development/internationalization/icu.md "Edit the source code of this page")