-
Notifications
You must be signed in to change notification settings - Fork 183
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
b100859
commit a646e73
Showing
29 changed files
with
119 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::DummyDateTime, 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: DummyDateTime = "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,4 @@ | ||
|
||
pub use icu_datetime as datetime; | ||
pub use icu_locale as locale; | ||
pub use icu_pluralrules as plurals; | ||
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 @@ | ||
{} |