Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore using icu4 #1227

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ std = []
clock = ["std", "winapi", "iana-time-zone", "android-tzdata"]
oldtime = ["time"]
wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales", "alloc"]
unstable-locales = [
"alloc",
"icu_calendar",
"icu_datagen",
"icu_datetime",
"icu_decimal",
"icu_locid_transform",
"icu_locid",
"icu_provider",
"pure-rust-locales",
"zerovec",
]
__internal_bench = ["criterion"]
__doctest = []

Expand All @@ -33,7 +44,14 @@ time = { version = "0.1.43", optional = true }
num-traits = { version = "0.2", default-features = false }
rustc-serialize = { version = "0.3.20", optional = true }
serde = { version = "1.0.99", default-features = false, optional = true }
icu_calendar = {version = "1.2.0", optional = true}
icu_datetime = { version = "1.2.0", optional = true }
icu_decimal = { version = "1.2.0", optional = true }
icu_locid = { version = "1.2.0", optional = true }
icu_locid_transform = { version = "1.2.0", optional = true }
icu_provider = { version = "1.2.0", optional = true }
pure-rust-locales = { version = "0.6", optional = true }
zerovec = { version = "0.9", optional = true }
criterion = { version = "0.4.0", optional = true }
rkyv = { version = "0.7", optional = true }
arbitrary = { version = "1.0.0", features = ["derive"], optional = true }
Expand Down Expand Up @@ -61,6 +79,15 @@ doc-comment = { version = "0.3" }
[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dev-dependencies]
wasm-bindgen-test = "0.3"

[build-dependencies]
icu_calendar = {version = "1.2.0", optional = true}
icu_datetime = { version = "1.2.0", optional = true }
icu_decimal = { version = "1.2.0", optional = true }
icu_locid = { version = "1.2.0", optional = true }
icu_locid_transform = { version = "1.2.0", optional = true }
icu_provider = { version = "1.2.0", optional = true }
icu_datagen = { version = "1.2.0", optional = true }

[package.metadata.docs.rs]
features = ["serde"]
rustdoc-args = ["--cfg", "docsrs"]
Expand Down
38 changes: 38 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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/main/LICENSE ).

#[cfg(feature = "unstable-locales")]
fn main() {
use icu_datagen::prelude::*;
use std::path::PathBuf;
println!("cargo:rerun-if-changed=build.rs");

let out_dir = std::env::var_os("OUT_DIR").unwrap();
let mod_directory = PathBuf::from(out_dir).join("baked_data");

let mut options = BakedOptions::default();
// Whether to overwrite existing data. By default, errors if it is present.
options.overwrite = true;
// Whether to use separate crates to name types instead of the `icu` metacrate
options.use_separate_crates = true;

icu_datagen::datagen(
None,
// Note: These are the keys required by `PluralRules::try_new_cardinal_unstable`
&[
icu_decimal::provider::DecimalSymbolsV1Marker::KEY,
icu_datetime::provider::calendar::TimeSymbolsV1Marker::KEY,
icu_datetime::provider::calendar::GregorianDateSymbolsV1Marker::KEY,
icu_locid_transform::provider::LikelySubtagsForLanguageV1Marker::KEY,
icu_locid_transform::provider::LikelySubtagsForScriptRegionV1Marker::KEY,
],
&SourceData::default()
.with_cldr_for_tag(SourceData::LATEST_TESTED_CLDR_TAG, CldrLocaleSubset::Modern)
.expect("Infallible"),
vec![icu_datagen::Out::Baked { mod_directory, options }],
)
.expect("Datagen should be successful");
}
#[cfg(not(feature = "unstable-locales"))]
fn main() {}
8 changes: 4 additions & 4 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,8 +1477,8 @@ fn locale_decimal_point() {
assert_eq!(dt.format_localized("%T%.6f", nl_NL).to_string(), "18:58:00,123456");
assert_eq!(dt.format_localized("%T%.9f", nl_NL).to_string(), "18:58:00,123456780");

assert_eq!(dt.format_localized("%T%.f", ar_SY).to_string(), "18:58:00.123456780");
assert_eq!(dt.format_localized("%T%.3f", ar_SY).to_string(), "18:58:00.123");
assert_eq!(dt.format_localized("%T%.6f", ar_SY).to_string(), "18:58:00.123456");
assert_eq!(dt.format_localized("%T%.9f", ar_SY).to_string(), "18:58:00.123456780");
assert_eq!(dt.format_localized("%T%.f", ar_SY).to_string(), "18:58:00٫123456780");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An Arabic comma (or what is it called) in roman numerals doesn't seem right.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, some locales have outdigits defined as part of LC_CTYPE, but pure-rust-locales doesn't support these. I did check though and there's nothing defined for ar_SY. I beleive that ICU has the numbers, though I'm still researching.

assert_eq!(dt.format_localized("%T%.3f", ar_SY).to_string(), "18:58:00٫123");
assert_eq!(dt.format_localized("%T%.6f", ar_SY).to_string(), "18:58:00٫123456");
assert_eq!(dt.format_localized("%T%.9f", ar_SY).to_string(), "18:58:00٫123456780");
}