Skip to content

Commit

Permalink
Add workaround for variants table
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Oct 13, 2023
1 parent a887449 commit 6d6378a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@
use serde::Deserialize;
use std::collections::HashMap;

#[derive(PartialEq, Debug, Deserialize)]
#[serde(untagged)]
pub enum StringOrEmptyMap {
String(String),
// CLDR-JSON 44 contains some empty maps in place of strings in the
// variants table. This might be a bug. Track progress:
// <https://unicode-org.atlassian.net/browse/CLDR-17171>
Empty {},
}

#[derive(PartialEq, Debug, Deserialize)]
pub struct Variants {
pub variants: HashMap<String, String>,
pub variants: HashMap<String, StringOrEmptyMap>,
}

#[derive(PartialEq, Debug, Deserialize)]
Expand Down
8 changes: 5 additions & 3 deletions provider/datagen/src/transform/cldr/displaynames/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ impl TryFrom<&cldr_serde::displaynames::variant::Resource> for VariantDisplayNam
fn try_from(other: &cldr_serde::displaynames::variant::Resource) -> Result<Self, Self::Error> {
let mut names = BTreeMap::new();
for entry in other.main.value.localedisplaynames.variants.iter() {
// TODO: Support alt variants for variant display names.
if !entry.0.contains(ALT_SUBSTRING) {
names.insert(Variant::from_str(entry.0)?.into_tinystr(), entry.1.as_str());
if let cldr_serde::displaynames::variant::StringOrEmptyMap::String(variant) = entry.1 {
// TODO: Support alt variants for variant display names.
if !entry.0.contains(ALT_SUBSTRING) {
names.insert(Variant::from_str(entry.0)?.into_tinystr(), variant.as_str());
}
}
}
Ok(Self {
Expand Down

0 comments on commit 6d6378a

Please sign in to comment.