Made language delimiter in the translate plugin configurable

This commit is contained in:
Kirottu
2023-05-15 13:51:04 +03:00
parent 5c0765fdba
commit de606380a2
3 changed files with 8 additions and 2 deletions

View File

@@ -4,7 +4,8 @@ Quickly translate text using the Google Translate API.
## Usage
Type in `[prefix][target lang] [text to translate]` or `[prefix][src lang]>[target lang] [text to translate]`, where prefix is the configured prefix (default is in [Configuration](#Configuration)) and the rest are pretty obvious.
Type in `<prefix><target lang> <text to translate>` or `<prefix><src lang><language_delimiter><target lang> <text to translate>`,
where the `prefix` and `language_delimiter` are config options (defaults are in [Configuration](#Configuration)) and the rest are pretty obvious.
## Configuration
@@ -12,6 +13,7 @@ Type in `[prefix][target lang] [text to translate]` or `[prefix][src lang]>[targ
// <Anyrun config dir>/translate.ron
Config(
prefix: ":",
language_delimiter: ">",
max_entries: 3,
)
```

View File

@@ -10,6 +10,7 @@ use tokio::runtime::Runtime;
#[derive(Deserialize)]
struct Config {
prefix: String,
language_delimiter: String,
max_entries: usize,
}
@@ -17,6 +18,7 @@ impl Default for Config {
fn default() -> Self {
Self {
prefix: ":".to_string(),
language_delimiter: ">".to_string(),
max_entries: 3,
}
}
@@ -169,7 +171,7 @@ fn get_matches(input: RString, state: &State) -> RVec<Match> {
None => return RVec::new(),
};
let (src, dest) = match lang_split.split_once('>') {
let (src, dest) = match lang_split.split_once(&state.config.language_delimiter) {
Some(split) => (Some(split.0), split.1),
None => (None, lang_split),
};