Skip to content

Commit

Permalink
Merge branch 'main' into duration-formatter-clamp-fractional-digits
Browse files Browse the repository at this point in the history
  • Loading branch information
kartva committed Aug 22, 2024
2 parents 7be8c24 + bb91fb3 commit e2bd84a
Show file tree
Hide file tree
Showing 741 changed files with 215,193 additions and 436,966 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/artifacts-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,16 @@ jobs:
- name: Init packages
run: |
npm -C ffi/npm ci
npm -C tutorials/npm ci
npm -C tutorials/web-demo ci
env:
PINNED_CI_NIGHTLY: nightly-2024-07-23

- name: Run Webpack
run: npm -C tutorials/npm run build

- name: Put index.html in dist for temp URL
run: |
cp tutorials/npm/index.html tutorials/npm/dist/index.html
printf "const gcs=document.createElement('script');gcs.setAttribute('src','./bundle.js');document.body.appendChild(gcs);" > tutorials/npm/dist/index.js
run: npm -C tutorials/web-demo run build

- name: Upload wasm-demo bundle to Google Cloud Storage
run: |
gsutil -m cp -r tutorials/npm/dist/* gs://${{ env.GCP_MAIN_BUCKET_ID }}/gha/wasm-demo
gsutil -m cp -r tutorials/web-demo/public/* gs://${{ env.GCP_MAIN_BUCKET_ID }}/gha/wasm-demo
- name: "⭐⭐⭐ Links to Uploaded Artifacts ⭐⭐⭐"
run: |
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ icu_benchmark_macros = { path = "tools/benchmark/macros" }

# The version here can either be a `version = ".."` spec or `git = "https://github.com/rust-diplomat/diplomat", rev = ".."`
# Diplomat must be published preceding a new ICU4X release but may use git versions in between
diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "291371b020d9c3cd5abbd1f96f6dfe4f8fac3b5c" }
diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "291371b020d9c3cd5abbd1f96f6dfe4f8fac3b5c" }
diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "291371b020d9c3cd5abbd1f96f6dfe4f8fac3b5c" }
diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "291371b020d9c3cd5abbd1f96f6dfe4f8fac3b5c" }
diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "3041875ca43571d5e866adb6c1fc313b406c9278" }
diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "3041875ca43571d5e866adb6c1fc313b406c9278" }
diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "3041875ca43571d5e866adb6c1fc313b406c9278" }
diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "3041875ca43571d5e866adb6c1fc313b406c9278" }

# EXTERNAL DEPENDENCIES
#
Expand Down
31 changes: 0 additions & 31 deletions components/experimental/src/dimension/provider/count.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 ).

// Provider structs must be stable
#![allow(clippy::exhaustive_structs, clippy::exhaustive_enums)]

//! Data provider struct definitions for this ICU4X component.
//!
//! Read more about data providers: [`icu_provider`]
use alloc::borrow::Cow;
use icu_provider::prelude::*;

#[cfg(feature = "compiled_data")]
/// Baked data
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. In particular, the `DataProvider` implementations are only
/// guaranteed to match with this version's `*_unstable` providers. Use with caution.
/// </div>
pub use crate::provider::Baked;

/// Currency Extended V1 data struct.
#[icu_provider::data_struct(marker(
CurrencyDisplaynameV1Marker,
"currency/displayname@1",
attributes_domain = "currency",
))]
#[derive(Debug, Clone, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_experimental::dimension::provider::currency_displayname)
)]
#[yoke(prove_covariance_manually)]
pub struct CurrencyDisplaynameV1<'data> {
/// The display name for the currency.
#[cfg_attr(feature = "serde", serde(borrow))]
pub display_name: Cow<'data, str>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//!
//! Read more about data providers: [`icu_provider`]
use crate::relativetime::provider::PluralPattern;
use icu_pattern::DoublePlaceholder;
use crate::relativetime::provider::PluralElements;
use icu_pattern::DoublePlaceholderPattern;
use icu_provider::prelude::*;

/// Currency Extended V1 data struct.
Expand All @@ -26,5 +26,5 @@ use icu_provider::prelude::*;
pub struct CurrencyPatternsDataV1<'data> {
/// Contains the unit patterns for a currency based on plural rules.
#[cfg_attr(feature = "serde", serde(borrow))]
pub patterns: PluralPattern<'data, DoublePlaceholder>,
pub patterns: PluralElements<'data, DoublePlaceholderPattern<str>>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//!
//! Read more about data providers: [`icu_provider`]
use crate::relativetime::provider::PluralElements;
use icu_provider::prelude::*;
use zerovec::ZeroMap;

#[cfg(feature = "compiled_data")]
/// Baked data
Expand All @@ -28,7 +28,7 @@ pub use crate::provider::Baked;
"currency/extended@1",
attributes_domain = "currency",
))]
#[derive(Debug, Clone, Default, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(
feature = "datagen",
Expand All @@ -46,46 +46,5 @@ pub struct CurrencyExtendedDataV1<'data> {
/// Regards to the [Unicode Report TR35](https://unicode.org/reports/tr35/tr35-numbers.html#Currencies),
/// If no matching for specific count, the `other` count will be used.
#[cfg_attr(feature = "serde", serde(borrow))]
pub display_names: ZeroMap<'data, Count, str>,
}

/// A CLDR plural keyword, or the explicit value 1.
/// See <https://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules>.
#[zerovec::make_ule(CountULE)]
#[zerovec::derive(Debug)]
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_experimental::dimension::provider::extended_currency)
)]
#[repr(u8)]
pub enum Count {
/// The CLDR keyword `zero`.
Zero = 0,
/// The CLDR keyword `one`.
One = 1,
/// The CLDR keyword `two`.
Two = 2,
/// The CLDR keyword `few`.
Few = 3,
/// The CLDR keyword `many`.
Many = 4,
/// The CLDR keyword `other`.
Other = 5,
// TODO(younies): revise this for currency
/// The explicit 1 case, see <https://www.unicode.org/reports/tr35/tr35-numbers.html#Explicit_0_1_rules>.
Explicit1 = 6,
// NOTE(egg): No explicit 0, because the compact decimal pattern selection
// algorithm does not allow such a thing to arise.
// TODO(younies): implment this case.
/// The default case.
/// NOTE:
/// Used as the default when there is no match.
/// This is also used to replace the most frequently occurring case in all plural rules.
Default = 7,

/// The display name for the currency.
DisplayName = 8,
pub display_names: PluralElements<'data, str>,
}
2 changes: 1 addition & 1 deletion components/experimental/src/dimension/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

pub mod compact_count_ule;
pub mod count;
pub mod currency;
pub mod currency_compact;
pub mod currency_displayname;
pub mod currency_patterns;
pub mod extended_currency;
pub mod pattern_key;
Expand Down
54 changes: 3 additions & 51 deletions components/experimental/src/dimension/provider/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
//!
//! Read more about data providers: [`icu_provider`]
use icu_plurals::PluralCategory;
use crate::relativetime::provider::PluralElements;
use icu_pattern::SinglePlaceholderPattern;
use icu_provider::prelude::*;
use zerovec::ZeroMap;

#[icu_provider::data_struct(marker(
UnitsDisplayNameV1Marker,
Expand All @@ -31,53 +31,5 @@ pub struct UnitsDisplayNameV1<'data> {
// TODO: use `MeasureUnit` for the units key instead of strings.
/// Contains the long width patterns for the units.
#[cfg_attr(feature = "serde", serde(borrow))]
pub patterns: ZeroMap<'data, Count, str>,
}

// TODO: revise this.
// TODO(younies): add a field to store the most commonly used unit pattern as the default.
/// Represents either a CLDR plural keyword or the explicit value 1.
/// See <https://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules>.
#[zerovec::make_ule(CountULE)]
#[zerovec::derive(Debug)]
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_experimental::compactdecimal::provider)
)]
#[repr(u8)]
pub enum Count {
/// The CLDR keyword `zero`.
Zero = 0,
/// The CLDR keyword `one`.
One = 1,
/// The CLDR keyword `two`.
Two = 2,
/// The CLDR keyword `few`.
Few = 3,
/// The CLDR keyword `many`.
Many = 4,
/// The CLDR keyword `other`.
Other = 5,
/// The explicit 1 case, see <https://www.unicode.org/reports/tr35/tr35-numbers.html#Explicit_0_1_rules>.
Explicit1 = 6,
// TODO: revise this
// NOTE(egg): No explicit 0, because the compact decimal pattern selection
// algorithm does not allow such a thing to arise.
}

impl From<PluralCategory> for Count {
fn from(other: PluralCategory) -> Self {
use PluralCategory::*;
match other {
Zero => Count::Zero,
One => Count::One,
Two => Count::Two,
Few => Count::Few,
Many => Count::Many,
Other => Count::Other,
}
}
pub patterns: PluralElements<'data, SinglePlaceholderPattern<str>>,
}
41 changes: 5 additions & 36 deletions components/experimental/src/dimension/units/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@

//! Experimental.
use core::str::FromStr;

use crate::dimension::provider::units::UnitsDisplayNameV1;
use fixed_decimal::FixedDecimal;

use icu_decimal::FixedDecimalFormatter;
use icu_pattern::SinglePlaceholderPattern;
use icu_plurals::PluralRules;
use writeable::{impl_display_with_writeable, Writeable};

use crate::alloc::borrow::ToOwned;
use crate::dimension::provider::units::{Count, UnitsDisplayNameV1};

pub struct FormattedUnit<'l> {
pub(crate) value: &'l FixedDecimal,
pub(crate) unit: &'l str,
// TODO: review using options and essentials.
// pub(crate) _options: &'l UnitsFormatterOptions,
// pub(crate) essential: &'l UnitsEssentialsV1<'l>,
Expand All @@ -32,35 +25,11 @@ impl<'l> Writeable for FormattedUnit<'l> {
where
W: core::fmt::Write + ?Sized,
{
let plural_category = self.plural_rules.category_for(self.value);
let count = Count::from(plural_category);
let mut unit_pattern = None;
let display_name = self
.display_name
self.display_name
.patterns
.get(&count)
// TODO(younies): Try to find a test case for testing the following case.
// As per Unicode TR 35:
// https://www.unicode.org/reports/tr35/tr35-55/tr35.html#Multiple_Inheritance
// If the pattern is not found for the associated `Count`, fall back to the `Count::Other` pattern.
.or_else(|| {
if count != Count::Other {
self.display_name.patterns.get(&Count::Other)
} else {
None
}
})
.unwrap_or_else(|| unit_pattern.insert("{0} ".to_owned() + self.unit));

// TODO: once the patterns are implemented to be used in the data side, we do not need this.
let pattern =
SinglePlaceholderPattern::from_str(display_name).map_err(|_| core::fmt::Error)?;

pattern
.get_pattern(self.plural_rules.category_for(self.value))
.interpolate((self.fixed_decimal_formatter.format(self.value),))
.write_to(sink)?;

Ok(())
.write_to(sink)
}
}

Expand Down Expand Up @@ -124,6 +93,6 @@ fn test_basic() {
for (locale, unit, value, options, expected) in test_cases {
let fmt = UnitsFormatter::try_new(&locale.into(), unit, options).unwrap();
let value = value.parse().unwrap();
assert_writeable_eq!(fmt.format_fixed_decimal(&value, unit), expected);
assert_writeable_eq!(fmt.format_fixed_decimal(&value), expected);
}
}
Loading

0 comments on commit e2bd84a

Please sign in to comment.