1// This file is part of ICU4X. For terms of use, please see the file
2// called LICENSE at the top level of the ICU4X source tree
3// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5use super::*;
6use icu_locid::extensions::unicode::Key;
7use icu_locid::subtags::{region, script, Language, Region, Script};
8use icu_provider::prelude::*;
9use zerovec::ule::UnvalidatedStr;
10use zerovec::ZeroMap;
11use zerovec::ZeroMap2d;
12
13/// Locale fallback rules derived from likely subtags data.
14#[icu_provider::data_struct(marker(
15 LocaleFallbackLikelySubtagsV1Marker,
16 "fallback/likelysubtags@1",
17 singleton
18))]
19#[derive(Default, Clone, PartialEq, Debug)]
20#[cfg_attr(
21 feature = "datagen",
22 derive(serde::Serialize, databake::Bake),
23 databake(path = icu_locid_transform::provider),
24)]
25#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
26#[yoke(prove_covariance_manually)]
27pub struct LocaleFallbackLikelySubtagsV1<'data> {
28 /// Map from language to the default script in that language. Languages whose default script
29 /// is `Latn` are not included in the map for data size savings.
30 ///
31 /// Example: "zh" defaults to "Hans", which is in this map.
32 #[cfg_attr(feature = "serde", serde(borrow))]
33 pub l2s: ZeroMap<'data, UnvalidatedLanguage, Script>,
34 /// Map from language-region pairs to a script. Only populated if the script is different
35 /// from the one in `l2s` for that language.
36 ///
37 /// Example: "zh-TW" defaults to "Hant", which is in this map.
38 #[cfg_attr(feature = "serde", serde(borrow))]
39 pub lr2s: ZeroMap2d<'data, UnvalidatedLanguage, UnvalidatedRegion, Script>,
40 /// Map from language to the default region in that language. Languages whose default region
41 /// is `ZZ` are not included in the map for data size savings.
42 ///
43 /// Example: "zh" defaults to "CN".
44 #[cfg_attr(feature = "serde", serde(borrow))]
45 pub l2r: ZeroMap<'data, UnvalidatedLanguage, Region>,
46 /// Map from language-script pairs to a region. Only populated if the region is different
47 /// from the one in `l2r` for that language.
48 ///
49 /// Example: "zh-Hant" defaults to "TW".
50 #[cfg_attr(feature = "serde", serde(borrow))]
51 pub ls2r: ZeroMap2d<'data, UnvalidatedLanguage, UnvalidatedScript, Region>,
52}
53
54/// `Latn` is the most common script, so it is defaulted for data size savings.
55pub const DEFAULT_SCRIPT: Script = script!("Latn");
56
57/// `ZZ` is the most common region, so it is defaulted for data size savings.
58pub const DEFAULT_REGION: Region = region!("ZZ");
59
60/// Locale fallback rules derived from CLDR parent locales data.
61#[icu_provider::data_struct(marker(
62 LocaleFallbackParentsV1Marker,
63 "fallback/parents@1",
64 singleton
65))]
66#[derive(Default, Clone, PartialEq, Debug)]
67#[cfg_attr(
68 feature = "datagen",
69 derive(serde::Serialize, databake::Bake),
70 databake(path = icu_locid_transform::provider),
71)]
72#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
73#[yoke(prove_covariance_manually)]
74pub struct LocaleFallbackParentsV1<'data> {
75 /// Map from language identifier to language identifier, indicating that the language on the
76 /// left should inherit from the language on the right.
77 #[cfg_attr(feature = "serde", serde(borrow))]
78 pub parents: ZeroMap<'data, UnvalidatedStr, (Language, Option<Script>, Option<Region>)>,
79}
80
81/// Key-specific supplemental fallback data.
82#[icu_provider::data_struct(marker(
83 CollationFallbackSupplementV1Marker,
84 "fallback/supplement/co@1",
85 singleton,
86))]
87#[derive(Default, Clone, PartialEq, Debug)]
88#[cfg_attr(
89 feature = "datagen",
90 derive(serde::Serialize, databake::Bake),
91 databake(path = icu_locid_transform::provider),
92)]
93#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
94#[yoke(prove_covariance_manually)]
95pub struct LocaleFallbackSupplementV1<'data> {
96 /// Additional parent locales to supplement the common ones.
97 #[cfg_attr(feature = "serde", serde(borrow))]
98 pub parents: ZeroMap<'data, UnvalidatedStr, (Language, Option<Script>, Option<Region>)>,
99 /// Default values for Unicode extension keywords.
100 #[cfg_attr(feature = "serde", serde(borrow))]
101 pub unicode_extension_defaults: ZeroMap2d<'data, Key, UnvalidatedStr, UnvalidatedStr>,
102}
103