-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Simple app | ||
use icu_locale::{subtags, LanguageIdentifier}; | ||
|
||
const LANGIDS: &[&str] = &[ | ||
"de", | ||
"en-US", | ||
"zh-Hant", | ||
"sr-Cyrl", | ||
"fr-CA", | ||
"es-CL", | ||
"pl", | ||
"en-Latn-US", | ||
"ca-valencia", | ||
"und-Arab", | ||
]; | ||
|
||
fn main() { | ||
// 1. Parse input strings into LanguageIdentifiers | ||
let langids = LANGIDS | ||
.iter() | ||
.map(|s| s.parse()) | ||
.collect::<Result<Vec<LanguageIdentifier>, _>>() | ||
.expect("Failed to parse Language Identifier"); | ||
|
||
{ | ||
// 2. Filter list of identifiers that match a given Language Identifier. | ||
let reference: LanguageIdentifier = "en-US" | ||
.parse() | ||
.expect("Failed to parse Language Identifier"); | ||
|
||
let _matching = langids.iter().filter(|langid| *langid == &reference); | ||
} | ||
|
||
{ | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Likewise: use |
||
|
||
let _matching = langids.iter().filter(|langid| langid.language == reference); | ||
} | ||
|
||
// 4. Serialize Language Identifiers to a vector of strings. | ||
let _canonicalized: Vec<_> = langids.iter().map(|langid| langid.to_string()).collect(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.