Web-Lang
Match a languages from the http Accept-Language
header, urls, or other sources.
Language tags (eg: "en-au"
) are never validated,
this crate simply tries to make sense of whatever value it is given,
ignoring any input that it cannot understand, and find the best match
based on a few simple rules.
This crate is inspired by Django's translation handling.
Features
- No unsafe code (
#[forbid(unsafe_code)]
) - No panics
- Tested; code coverage: 100% (morally)
- No dependencies
Example
Simply pass an iterable of language tags and the Accept-Language
header
to find the best match.
assert_eq!;
Complete example with a custom language enum.
use ;
const LANGUAGES: & = &;
// Use your own language enum.
assert_eq!;
Documentation
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.