Crates.io | languagetool-rust |
lib.rs | languagetool-rust |
version | 3.0.0 |
created_at | 2022-05-16 14:51:56.438129+00 |
updated_at | 2025-09-17 07:43:38.269849+00 |
description | LanguageTool API bindings in Rust. |
homepage | |
repository | https://github.com/jeertmans/languagetool-rust |
max_upload_size | |
id | 587677 |
size | 237,567 |
Rust bindings to connect with LanguageTool server API.
LanguageTool is an open source grammar style checker. It can correct 30+ languages and is free to use, more on that on languagetool.org. There is a public API (with a free tier), but you can also host your own server locally. LanguageTool-Rust helps you communicate with those servers very easily via Rust code!
LanguageTool-Rust (LTRS) is both an executable and a Rust library that strives to provide correct and safe bindings for the LanguageTool API.
Disclaimer: the current work relies on an approximation of the LanguageTool API. We try to avoid breaking changes as much as possible, but we still highly depend on the future evolutions of LanguageTool.
You can install the latest version with cargo
.
cargo install languagetool-rust --features full
If you are on Arch Linux, you call also install with your AUR helper:
paru -S languagetool-rust
The command line interface of LTRS allows to very quickly use any LanguageTool server to check for grammar and style errors.
The reference for the CLI can be accessed via ltrs --help
.
By default, LTRS uses the LanguageTool public API.
> ltrs ping # to check if the server is alive
PONG! Delay: 110 ms
> ltrs languages # to list all languages
[
{
"name": "Arabic",
"code": "ar",
"longCode": "ar"
},
{
"name": "Asturian",
"code": "ast",
"longCode": "ast-ES"
},
# ...
]
> ltrs check --text "Some phrase with a smal mistake" # codespell:ignore smal
{
"language": {
"code": "en-US",
"detectedLanguage": {
"code": "en-US",
"confidence": 0.99,
"name": "English (US)",
"source": "ngram"
},
"name": "English (US)"
},
"matches": [
{
"context": {
"length": 4,
"offset": 19,
"text": "Some phrase with a smal mistake" # codespell:ignore smal
},
"contextForSureMatch": 0,
"ignoreForIncompleteSentence": false,
"length": 4,
"message": "Possible spelling mistake found.",
"offset": 19,
"replacements": [
{
"value": "small"
},
{
"value": "seal"
},
# ...
}
# ...
]
# ...
}
> ltrs --help # for more details
Since LanguageTool's installation might not be straightforward,
we provide a basic Docker integration that allows to pull
, start
, and stop
LanguageTool Docker containers in a few lines:
ltrs docker pull # only once
ltrs docker start # start the LT server
ltrs --hostname http://localhost -p 8010 check -t "Some tex"
# Other commands...
ltrs docker stop # stop the LT server
Note: Docker is a tool that facilitates running applications without worrying about local dependencies, platform-related issues, and so on. Installation guidelines can be found online. On Linux platforms, you might need to circumvent the sudo privilege issue by doing this.
If you would like to integrate LTRS within a Rust application or crate, then we recommend reading the documentation.
To use LanguageTool-Rust in your Rust project, add to your Cargo.toml
:
[dependencies]
languagetool-rust = "^2.1"
use languagetool_rust::api::{check, server::ServerClient};
use std::borrow::Cow;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ServerClient::from_env_or_default();
let req = check::Request::default()
.with_text("Some phrase with a smal mistake"); // # codespell:ignore smal
println!(
"{}",
serde_json::to_string_pretty(&client.check(&req).await?)?
);
Ok(())
}
Below are listed the various feature flags you can enable when compiling LTRS.
native-tls
.ltrs completions --help
to get help with installing completion files.--color=<WHEN>
option will be available.cli-complete
, docker
, and undoc
).vendored
feature of native-tls
. This or native-tls
should be activated if you are planning to use HTTPS servers.Here are listed some projects that use LTRS.
null-ls
:
Neovim plugin with LTRS builtin (see PR)languagetool-code-comments
:
uses LTRS to check for grammar errors within code commentsDo you use LTRS in your project? Contact me so I can add it to the list!
Contributions are more than welcome!
First, check out the CHANGELOG guide for detailed information about how to contribute to this project.
Should you have any question, feel free to reach out via: Issues for bugs, Pull requests for code contributions or Discussions for anything else.