10 releases (3 stable)
Uses old Rust 2015
1.0.2 | Nov 28, 2017 |
---|---|
1.0.1 | Mar 18, 2017 |
1.0.0 | Nov 6, 2016 |
0.1.0 | Nov 19, 2015 |
0.0.2 | Nov 22, 2014 |
#15 in #format-text
Used in lingua
21MB
401K
SLoC
DEPRECATED in favor of whatlang, which is native Rust and smaller. If you have a compelling use-case for this code, please open an issue. Simple PRs, especially for bug fixes, will still be read and possibly merged.
This Rust library detects the language of a string using the cld2 library from the Chromium project.
To use it, add the following lines to your Cargo.toml
file and run cargo update
:
[dependencies.cld2]
git = "git://github.com/emk/rust-cld2"
Then you can invoke it as follows:
// Put these two lines the top of the file.
extern crate cld2;
use cld2::{detect_language, Format, Reliable, Lang};
let text = "It is an ancient Mariner,
And he stoppeth one of three.
'By thy long grey beard and glittering eye,
Now wherefore stopp'st thou me?";
assert_eq!((Some(Lang("en")), Reliable),
detect_language(text, Format::Text));
You can also pass in language detection hints and request more detailed output. For details, please see the API documentation.
Contributing
As always, pull requests are welcome! Please keep any patches as simple as possible and include unit tests; that makes it much easier for me to merge them.
If you want to get the C/C++ code building on another platform, please see
cld2-sys/build.rb
and this build script guide. You'll
probably need to adjust some compiler options. Please don't hesitate to
ask questions; I'd love for this library to be cross platform.
In your first commit message, please include the following statement:
I dedicate any and all copyright interest in my contributions to this project to the public domain. I make this dedication for the benefit of the public at large and to the detriment of my heirs and successors. I intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
This allows us to keep the library legally unencumbered, and free for everyone to use.
License
The original cld2 library is distributed under the Apache License Version
2.0. This also covers much of the code in cld2-sys/src/wrapper.h
. All
of the new code is released into the public domain as described by the
Unlicense.