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

@@ -94,6 +94,8 @@ Anyrun requires plugins to function, as they provide the results for input. The
- Calculator & unit conversion. - Calculator & unit conversion.
- [Shell](plugins/shell/README.md) - [Shell](plugins/shell/README.md)
- Run shell commands. - Run shell commands.
- [Translate](plugins/translate/README.md)
- Quickly translate text.
- [Kidex](plugins/kidex/README.md) - [Kidex](plugins/kidex/README.md)
- File search provided by [Kidex](https://github.com/Kirottu/kidex). - File search provided by [Kidex](https://github.com/Kirottu/kidex).
- [Randr](plugins/randr/README.md) - [Randr](plugins/randr/README.md)

View File

@@ -4,7 +4,8 @@ Quickly translate text using the Google Translate API.
## Usage ## 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 ## Configuration
@@ -12,6 +13,7 @@ Type in `[prefix][target lang] [text to translate]` or `[prefix][src lang]>[targ
// <Anyrun config dir>/translate.ron // <Anyrun config dir>/translate.ron
Config( Config(
prefix: ":", prefix: ":",
language_delimiter: ">",
max_entries: 3, max_entries: 3,
) )
``` ```

View File

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