# Building Foundation with only the locales an app ships

**URL:** <https://forums.swift.org/t/building-foundation-with-only-the-locales-an-app-ships/90753>\
**Category:** Foundation\
**Created:** [November 14, 2026, 2:05pm UTC](https://forums.swift.org/t/building-foundation-with-only-the-locales-an-app-ships/90753 "2026-11-14T14:05:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![niktishakov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/niktishakov/32/47115_2.png) [@niktishakov](https://forums.swift.org/u/niktishakov)\
**Post date:** [November 14, 2026, 2:05pm UTC](https://forums.swift.org/t/building-foundation-with-only-the-locales-an-app-ships/90753/1 "2026-11-14T14:05:38Z")

</div>

In @kateinoigakukun's thread on filtered ICU data, @tinaliu listed "a dynamic ICU build to support limited locales" and asked whether the challenge is packaging the data in a flexible way ([t/81581](https://forums.swift.org/t/81581/5)). In my ICU data thread, @xwu pointed out that per-locale subsetting in the ongoing Swift work would have a larger impact than another flavor of ICU ([t/90098](https://forums.swift.org/t/90098/2)). This doesn't replace that work: it applies the same locale list to the data that is still in ICU, as an opt-in, with the default unchanged. I measured what it saves and what breaks.

**What I built.** swift-foundation-icu's data with 10 languages (en, es, fr, de, it, pt, ru, ja, zh, ar and their regional locales), rebuilt with `genrb` and ICU's parent rules. Keeping every locale gives back the current data byte for byte. This rebuild was only for measuring; a maintainable version would use ICU's own `localeFilter` when the data is built from Apple ICU's sources.

**Results**

- Data: 34.0 → 17.6 MB. A minimal Android app with `import Foundation` (arm64): 65.7 → 49.4 MB installed, 24.0 → 18.9 MB gzipped. With only `en`, the data is 14.1 MB; each further language adds 0.15–0.3 MB, except `zh` (1.8 MB).
- The kept locales give the same output as with the full data: swift-foundation's tests on macOS, swift-corelibs-foundation's tests on Linux, and a probe of formatting, names, sorting and case mapping in 21 locales, and a smaller probe on an Android emulator.
- Every test that fails uses a dropped locale. A dropped locale doesn't crash: it formats like `en_US_POSIX` or root, with no error. `Locale.availableIdentifiers` lists only the kept locales (1034 → 316).

**Consistency.** On Apple platforms an app always has every locale, so an app with a list would format a dropped locale differently there. That's why it should be the app's choice, and why the fallback matters.

**One list for both kinds of data.** The generators for the Swift date and list tables already take `--locales` and `--fallback` ([swiftlang/swift-foundation#2330](https://github.com/swiftlang/swift-foundation/pull/2330)). The same list could select the ICU data, and a dropped locale could fall back by the rules in `utils/cldr-locale-fallback.swift`, so the ICU and Swift paths agree.

**Questions**

1. Is a locale list chosen when Foundation is built a direction you'd take now (a CMake option for the SDK, or the SwiftPM data build @icharleshu described in [t/78399](https://forums.swift.org/t/78399/4)), or should it wait for more of the Swift data work?
2. Who should choose the list: whoever builds the SDK, or the app? The app choosing needs the data outside the library, which @compnerd was wary of in [t/78399](https://forums.swift.org/t/78399/8).
3. What should a dropped locale fall back to: a locale the app picks (like `--fallback`), or root?

The rebuild script, logs and per-language sizes are here: [swift-foundation-icu/locale-subset at locale-subset · niktishakov/swift-foundation-icu · GitHub](https://github.com/niktishakov/swift-foundation-icu/tree/locale-subset/locale-subset). I can turn it into an ICUExport step if this is the way to go.

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [November 14, 2026, 3:12pm UTC](https://forums.swift.org/t/building-foundation-with-only-the-locales-an-app-ships/90753/2 "2026-11-14T15:12:34Z")

</div>

> [@niktishakov](#):
>
> - With only `en`, the data is 14.1 MB; each further language adds 0.15–0.3 MB, except `zh` (1.8 MB).

Really? `ja` adds at most 0.3 MB but `zh` adds 1.8 MB? This seems suspect to me.

> [@niktishakov](#):
>
> - it formats like `en_US_POSIX` or root, with no error.

It formats like _either_ of these—as in, some code paths hardcode `en_US_POSIX` and others look to the system locale—or do you mean something else?

---

<div class="post-metadata">

**Author:** ![niktishakov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/niktishakov/32/47115_2.png) [@niktishakov](https://forums.swift.org/u/niktishakov)\
**Post date:** [November 14, 2026, 3:34pm UTC](https://forums.swift.org/t/building-foundation-with-only-the-locales-an-app-ships/90753/3 "2026-11-14T15:34:38Z")

</div>

> Really? ja adds at most 0.3 MB but zh adds 1.8 MB? This seems suspect to me.

It's collation. `coll/zh.res` alone is 1,518,800 bytes: the pinyin, stroke and zhuyin orders list tens of thousands of Han characters, and unihan is there too. `coll/ja.res` is 146,160 bytes of ja's 259 KB. The rest of zh is 264 KB, about what each other language costs in total.

> It formats like either of these—as in, some code paths hardcode en\_US\_POSIX and others look to the system locale—or do you mean something else?

Neither swift-foundation nor corelibs sets ICU's default locale (no `uloc_setDefault`), and nothing in either repo picks `en_US_POSIX` as a fallback; the only hardcoded uses are fixed formats, like HTTP cookie dates, and lookup tables. A dropped locale goes down the same path as an id with no data, like `xx_YY` with the full data today: ICU falls back to its default locale, which it reads from the environment. `FormatStyle` and corelibs' `DateFormatter` behave the same on Linux:

- `LANG` unset: `en_US_POSIX` style, `January 15, 2027`. An Android app process gets this too: it has no `LANG`, and on the emulator `uloc_getDefault()` is `en_US_POSIX`.
- `LANG=de_DE.UTF-8`: German.
- `LANG` or `LC_ALL` set but empty: root, `2027 M01 15`. ICU takes the empty variable as the locale ID (`uprv_getPOSIXIDForCategory` in `putil.cpp`). That's where my "or root" came from: some of my runs had an empty variable.

Region data stays, so on Android a dropped `ko_KR` comes out as `en_US_POSIX` with ₩ and a 12-hour clock mixed in. That's why I think the fallback needs a rule, for example a fallback locale the app picks.
