-
Notifications
You must be signed in to change notification settings - Fork 6
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
Suggestion: select language from set of available languages #13
Comments
Hi @atezet, thanks for the suggestion! I'm curious how you think this would work. Would it be random? Just the first in a list? If you could design the API, what would it look like? |
Thanks for your reply! I'll try to write it up somewhere next week if that's okay |
So, I think neither of my suggestions should be random, but either quality-based or order-based. The pub fn select(raw_languages: &str, supported_languages: &[&str]) -> Option<String> {
let user_languages = parse(raw_languages);
user_languages
.into_iter()
.find(|l| supported_languages.contains(&l.as_str()))
} I'll submit it as a PR later, if this is okay. The /// `supported_languages` is an array of languages without region
pub fn select_lossy(raw_languages: &str, supported_languages: &[&str]) -> Option<String> {
let user_languages = parse(raw_languages);
user_languages
.into_iter()
.find(|l| supported_languages.contains(&ls.split('-').next().unwrap()).as_str())
} While writing this, I realised it's type-wise probably nicer to have the region split off and put it in its own field. That's a pretty major change, but I'd be willing to help if you're up for it. I always like it if crates provide nice types to interface with the functionality they provide. Disclaimer: I wrote both of these in the comment field of Github. The |
Similar to
intersection
it would be useful to be able to just select one from a list of available languages. Also, I think it would be useful if it would be possible to matchen-US
anden-GB
withen
in the available languages, for projects that don't support regional versions of languages. Some sort of "lossy" select.The text was updated successfully, but these errors were encountered: