Skip to content

Commit

Permalink
Add CLDR JSON data to testdata and remove from provider_cldr (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Mar 2, 2021
1 parent 3f9e74b commit c308b40
Show file tree
Hide file tree
Showing 41 changed files with 10,972 additions and 135 deletions.
107 changes: 92 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/locale_canonicalizer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is part of ICU4X. For terms of use, please see the file
# called LICENSE at the top level of the ICU4X source tree
# (online at: https://github.com/unicode-org/icu4x/blob/master/LICENSE ).

[package]
name = "icu_locale_canonicalizer"
version = "0.1.0"
Expand Down
1 change: 1 addition & 0 deletions components/provider_cldr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ log = { version = "0.4", optional = true }
[dev-dependencies]
mktemp = "0.4"
icu_locid_macros = { version = "0.1", path = "../locid/macros" }
icu_testdata = { version = "0.1", path = "../../resources/testdata" }

[features]
# Serialize None values when exporting. Required for Bincode.
Expand Down
63 changes: 62 additions & 1 deletion components/provider_cldr/src/cldr_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ pub trait CldrPaths: std::fmt::Debug {
/// Path to checkout of cldr-dates:
/// <https://github.com/unicode-cldr/cldr-dates-full>
fn cldr_dates(&self) -> Result<PathBuf, Error>;

/// Path to checkout of cldr-numbers:
/// <https://github.com/unicode-cldr/cldr-numbers-full>
fn cldr_numbers(&self) -> Result<PathBuf, Error>;
}

/// Implementation of `CldrPaths` for data directories already downloaded.
/// Implementation of `CldrPaths` for multiple separate local CLDR JSON directories per component.
///
/// # Example
///
Expand All @@ -37,6 +41,7 @@ pub trait CldrPaths: std::fmt::Debug {
pub struct CldrPathsLocal {
pub cldr_core: Result<PathBuf, MissingSourceError>,
pub cldr_dates: Result<PathBuf, MissingSourceError>,
pub cldr_numbers: Result<PathBuf, MissingSourceError>,
}

impl CldrPaths for CldrPathsLocal {
Expand All @@ -46,13 +51,69 @@ impl CldrPaths for CldrPathsLocal {
fn cldr_dates(&self) -> Result<PathBuf, Error> {
self.cldr_dates.clone().map_err(|e| e.into())
}
fn cldr_numbers(&self) -> Result<PathBuf, Error> {
self.cldr_numbers.clone().map_err(|e| e.into())
}
}

impl Default for CldrPathsLocal {
fn default() -> Self {
Self {
cldr_core: Err(MissingSourceError { src: "cldr-core" }),
cldr_dates: Err(MissingSourceError { src: "cldr-dates" }),
cldr_numbers: Err(MissingSourceError {
src: "cldr-numbers",
}),
}
}
}

/// Implementation of `CldrPaths` for one combined local CLDR JSON directory.
///
/// # Example
///
/// ```
/// use icu_provider_cldr::CldrPathsAllInOne;
/// use icu_provider_cldr::CldrJsonDataProvider;
/// use std::path::PathBuf;
///
/// let paths = CldrPathsAllInOne {
/// cldr_json_root: PathBuf::from("/path/to/cldr-json"),
/// suffix: "full",
/// };
///
/// let data_provider = CldrJsonDataProvider::new(&paths);
/// ```
#[derive(Debug, PartialEq)]
pub struct CldrPathsAllInOne {
/// Path to the CLDR JSON root directory
pub cldr_json_root: PathBuf,
/// CLDR JSON directory suffix: probably either "modern" or "full"
pub suffix: &'static str,
}

impl CldrPaths for CldrPathsAllInOne {
fn cldr_core(&self) -> Result<PathBuf, Error> {
Ok(self.cldr_json_root.clone().join("cldr-core"))
}
fn cldr_dates(&self) -> Result<PathBuf, Error> {
Ok(self
.cldr_json_root
.clone()
.join(format!("cldr-dates-{}", self.suffix)))
}
fn cldr_numbers(&self) -> Result<PathBuf, Error> {
Ok(self
.cldr_json_root
.clone()
.join(format!("cldr-numbers-{}", self.suffix)))
}
}

#[cfg(test)]
pub(crate) fn for_test() -> CldrPathsAllInOne {
CldrPathsAllInOne {
cldr_json_root: icu_testdata::paths::cldr_json_root(),
suffix: "full",
}
}
Loading

0 comments on commit c308b40

Please sign in to comment.