-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add example for icu_locale #250
Conversation
Without icu_locale: 321464 bytes The crate adds 6392 bytes. |
Pull Request Test Coverage Report for Build e169eecbd546ca58e8630512584881326239a090-PR-250
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example seems a little synthetic. Can you make it "do" something? For example, given a list of locale strings, find all the ones with language subtag "en", and then canonicalize that filtered list. You end up with a program that calculates all forms of English your app supports.
components/locale/examples/langid.rs
Outdated
|
||
{ | ||
// 2. Filter list of identifiers that match a given Language Identifier. | ||
let reference: LanguageIdentifier = "en-US" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use your macro here instead? There should no longer be any reason to hard-code a "...".parse().expect("...")
pattern for LanguageIdentifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we merge the macros! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to use the macros in this example. Hopefully the macros will be checked in soon.
components/locale/examples/langid.rs
Outdated
|
||
{ | ||
// 3. Filter list of identifiers that match a given language subtag. | ||
let reference: subtags::Language = "en".parse().expect("Failed to parse Language"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise: use language!
(or icu_language!
)
Good idea! I'll improve the example tmrw. |
Refactored the example according to @sffc's suggestion. |
d353960
to
8fb0ef7
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
8fb0ef7
to
f7acdae
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
f7acdae
to
74857ea
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
.collect(); | ||
|
||
// 2. Filter for LanguageIdentifiers with Language subtag `en`. | ||
let en_lang: subtags::Language = "en".parse().expect("Failed to parse language subtag."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a good place to demo the macros?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once we land them, I'll switch to them in examples :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Had a minor Rust question, but it is unrelated to the example code.
fn main() { | ||
let args: Vec<String> = env::args().collect(); | ||
|
||
let (_input, _output) = if let Some(input) = args.get(1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional/minor Rust question: Would it have been possible for this to be written as:
let _input = if let Some(input) = args.get(1) {
input.as_str()
} else {
DEFAULT_INPUT
};
let _ouptut = filter_input(&input);
...
println!("...", &_input, &_output);
I forgot if println!
complains on &String
or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! Applied! thank you!
a4b6b00
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Note somewhere that this is not the best way to do locale matching - use LanguageMatcher (TBD) instead.
#187 for Locale.