Skip to content

Commit

Permalink
Add ICU Meta Package for 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zbraniecki committed Oct 9, 2020
1 parent 98f89ff commit b6d0b78
Show file tree
Hide file tree
Showing 29 changed files with 183 additions and 1 deletion.
9 changes: 9 additions & 0 deletions components/icu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ include = [
"Cargo.toml",
"README.md"
]

[dependencies]
icu-datetime = { path = "../datetime" }
icu-locale = { path = "../locale" }
icu-pluralrules = { path = "../pluralrules" }
icu-unicodeset = { path = "../uniset" }

[dev-dependencies]
icu-fs-data-provider = { path = "../fs-data-provider" }
73 changes: 73 additions & 0 deletions components/icu/examples/tui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// An example program making use of a number of ICU components
// in a pseudo-real-world application of Textual User Interface.
use icu::datetime::{date::MockDateTime, DateTimeFormat, DateTimeFormatOptions};
use icu::locale::LanguageIdentifier;
use icu::plurals::{PluralCategory, PluralRuleType, PluralRules};
use icu::uniset::UnicodeSetBuilder;
use icu_fs_data_provider::FsDataProvider;
use std::env;

fn print<T: AsRef<str>>(_input: T) {
#[cfg(debug_assertions)]
println!("{}", _input.as_ref());
}

fn main() {
let provider = FsDataProvider::try_new("./tests/fixtures/data/icu4x")
.expect("Loading file from testdata directory");

let args: Vec<String> = env::args().collect();

let langid: LanguageIdentifier = args
.get(1)
.unwrap_or(&"en".to_string())
.parse()
.expect("Failed to parse language identifier.");

let user_name = args.get(2).cloned().unwrap_or_else(|| "John".to_string());

let email_count: usize = args
.get(3)
.unwrap_or(&"5".to_string())
.parse()
.expect("Could not parse unread email count as unsigned integer.");

print(format!("\nTextual User Interface Example ({})", langid));
print("===================================");
print(format!("User: {}", user_name));

{
let dtf = DateTimeFormat::try_new(langid, &provider, &DateTimeFormatOptions::default())
.expect("Failed to create DateTimeFormat.");
let today: MockDateTime = "2020-10-10T18:56:00".parse().expect("Failed to parse date");

let formatted_dt = dtf.format(&today);

print(format!("Today is: {}", formatted_dt));
}

{
let mut builder = UnicodeSetBuilder::new();
builder.add_range(&('\u{0000}'..='\u{007F}'));
let latin1_set = builder.build();

let only_latin1 = user_name.chars().all(|ch| latin1_set.contains(ch));

if only_latin1 {
print("User name latin1 only: true");
} else {
print("User name latin1 only: false");
}
}

{
let en: LanguageIdentifier = "en".parse().expect("Failed to parse Language Identifier.");
let pr = PluralRules::try_new(en, PluralRuleType::Cardinal, &provider)
.expect("Failed to create PluralRules.");

match pr.select(email_count) {
PluralCategory::One => print("Note: You have one unread email."),
_ => print(format!("Note: You have {} unread emails.", email_count)),
}
}
}
70 changes: 69 additions & 1 deletion components/icu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@

//! `ICU` is the main meta-package of the `ICU4X` project.
//!
//! It provides a comperhensive selection of Unicode Internationalization Components
//! in their canonical configurations intended to enable software
//! internationalization capabilities.
//!
//! The package is provided for convenience and users are encouraged
//! to fine-tune components with the features they need.
//!
//! The package does not bring any unique functionality. Users
//! can achieve the exact same by manually including the dependent
//! components with pre-selected features.
//!
//! # Data Provider
//!
//! Most of Unicode functionality relies on data which has to be provided
//! to the APIs.
//!
//! `ICU4X` project uses a concept of [`DataProvider`] - a service used to
//! handle data management.
//!
//! There can be many different heuristics for handling data management and
//! this meta-package does not supply any default `DataProvider`.
//!
//! When using `ICU4X` users are expected to decide which provider they want to use
//! and instrument it to point at the correct location where the data files are stored.
//!
//! In the following examples the [`FsDataProvider`] is used, which is a local file-system
//! service using synchronous I/O to fetch data stored on the hard drive.
//!
//! # Examples
//!
//! ```
//! use icu::locale::LanguageIdentifier;
//! use icu::datetime::{DateTimeFormat, date::MockDateTime, options::style};
//! use icu_fs_data_provider::FsDataProvider;
//!
//! let provider = FsDataProvider::try_new("./tests/fixtures/data/icu4x")
//! .expect("Loading file from testdata directory");
//!
//! let langid: LanguageIdentifier = "en".parse()
//! .expect("Failed to parse a Language Identifier.");
//!
//! let options = style::Bag {
//! date: Some(style::Date::Long),
//! time: Some(style::Time::Medium),
//! ..Default::default()
//! };
//!
//! let dtf = DateTimeFormat::try_new(langid, &provider, &options.into())
//! .expect("Failed to create DateTimeFormat instance.");
//!
//! let date: MockDateTime = "2020-09-12T12:35:00".parse()
//! .expect("Failed to parse date.");
//!
//! let formatted_date = dtf.format(&date);
//! assert_eq!(formatted_date.to_string(), "September 12, 2020 \'at\' 12:35:00 PM");
//! ```
//!
//! [`DataProvider`]: ../icu_data_provider/prelude/trait.DataProvider.html
//! [`FsDataProvider`]: ../icu_fs_data_provider/struct.FsDataProvider.html
#[doc(inline)]
pub use icu_datetime as datetime;
#[doc(inline)]
pub use icu_locale as locale;
#[doc(inline)]
pub use icu_pluralrules as plurals;
#[doc(inline)]
pub use icu_unicodeset as uniset;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"symbols":{"months":{"format":{"abbreviated":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"narrow":["J","F","M","A","M","J","J","A","S","O","N","D"],"wide":["January","February","March","April","May","June","July","August","September","October","November","December"]}},"weekdays":{"format":{"abbreviated":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"narrow":["S","M","T","W","T","F","S"],"short":["Su","Mo","Tu","We","Th","Fr","Sa"],"wide":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]}},"day_periods":{"format":{"abbreviated":{"am":"AM","pm":"PM"},"narrow":{"am":"a","pm":"p"},"wide":{"am":"AM","pm":"PM"}},"stand_alone":{"narrow":{"am":"AM","pm":"PM"}}}},"patterns":{"date":{"full":"EEEE, MMMM d, y","long":"MMMM d, y","medium":"MMM d, y","short":"M/d/yy"},"time":{"full":"h:mm:ss a zzzz","long":"h:mm:ss a z","medium":"h:mm:ss a","short":"h:mm a"},"date_time":{"full":"{1} 'at' {0}","long":"{1} 'at' {0}","medium":"{1}, {0}","short":"{1}, {0}"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"symbols":{"months":{"format":{"abbreviated":["sty","lut","mar","kwi","maj","cze","lip","sie","wrz","paź","lis","gru"],"narrow":["s","l","m","k","m","c","l","s","w","p","l","g"],"wide":["stycznia","lutego","marca","kwietnia","maja","czerwca","lipca","sierpnia","września","października","listopada","grudnia"]},"stand_alone":{"narrow":["S","L","M","K","M","C","L","S","W","P","L","G"],"wide":["styczeń","luty","marzec","kwiecień","maj","czerwiec","lipiec","sierpień","wrzesień","październik","listopad","grudzień"]}},"weekdays":{"format":{"abbreviated":["niedz.","pon.","wt.","śr.","czw.","pt.","sob."],"narrow":["n","p","w","ś","c","p","s"],"short":["nie","pon","wto","śro","czw","pią","sob"],"wide":["niedziela","poniedziałek","wtorek","środa","czwartek","piątek","sobota"]},"stand_alone":{"narrow":["N","P","W","Ś","C","P","S"]}},"day_periods":{"format":{"abbreviated":{"am":"AM","pm":"PM"},"narrow":{"am":"a","pm":"p"},"wide":{"am":"AM","pm":"PM"}}}},"patterns":{"date":{"full":"EEEE, d MMMM y","long":"d MMMM y","medium":"d MMM y","short":"dd.MM.y"},"time":{"full":"HH:mm:ss zzzz","long":"HH:mm:ss z","medium":"HH:mm:ss","short":"HH:mm"},"date_time":{"full":"{1} {0}","long":"{1} {0}","medium":"{1}, {0}","short":"{1}, {0}"}}}
4 changes: 4 additions & 0 deletions components/icu/tests/fixtures/data/icu4x/dates/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"aliasing": "NoAliases",
"syntax": "Json"
}
4 changes: 4 additions & 0 deletions components/icu/tests/fixtures/data/icu4x/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"aliasing": "NoAliases",
"syntax": "Json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zero":"n = 0","one":"n = 1","two":"n = 2","few":"n % 100 = 3..10","many":"n % 100 = 11..99"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"i = 1 and v = 0","few":"i = 2..4 and v = 0","many":"v != 0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"i = 1 and v = 0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"i = 1 and v = 0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"n = 1"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"i = 0,1"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"i = 1 and v = 0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"i = 1 and v = 0","few":"v = 0 and i % 10 = 2..4 and i % 100 != 12..14","many":"v = 0 and i != 1 and i % 10 = 0..1 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 12..14"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"i = 1 and v = 0","few":"i = 2..4 and v = 0","many":"v != 0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"v = 0 and i % 10 = 1 and i % 100 != 11","few":"v = 0 and i % 10 = 2..4 and i % 100 != 12..14","many":"v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"n % 10 = 1 and n % 100 != 11","two":"n % 10 = 2 and n % 100 != 12","few":"n % 10 = 3 and n % 100 != 13"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"one":"n = 1"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"many":"n = 11,8,80,800"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"few":"n % 10 = 3 and n % 100 != 13"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit b6d0b78

Please sign in to comment.