-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d6bcea
commit d4717bc
Showing
29 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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("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.clone(), &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(format!("User name latin1 only: true")); | ||
} else { | ||
print(format!("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)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/dates/gregory@1/en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"}}} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/dates/gregory@1/pl.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"aliasing": "NoAliases", | ||
"syntax": "Json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"aliasing": "NoAliases", | ||
"syntax": "Json" | ||
} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/ar.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/cs.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/de.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"one":"i = 1 and v = 0"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"one":"i = 1 and v = 0"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/es.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"one":"n = 1"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/fr.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"one":"i = 0,1"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/it.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"one":"i = 1 and v = 0"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/pl.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/sk.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/uk.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/cardinal@1/zh.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/ar.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/cs.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/de.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/es.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/fr.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"one":"n = 1"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/it.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"many":"n = 11,8,80,800"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/pl.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/sk.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/uk.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"few":"n % 10 = 3 and n % 100 != 13"} |
1 change: 1 addition & 0 deletions
1
components/icu/tests/fixtures/data/icu4x/plurals/ordinal@1/zh.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |