Crates.io | text_manipulation_rs |
lib.rs | text_manipulation_rs |
version | 0.1.3 |
source | src |
created_at | 2023-03-19 15:08:23.045549 |
updated_at | 2023-05-02 14:25:46.509893 |
description | A crate for generating random placeholder text in different languages. |
homepage | https://github.com/BasantaChaulagain/text-manipulation-rs.git |
repository | https://github.com/BasantaChaulagain/text-manipulation-rs.git |
max_upload_size | |
id | 814458 |
size | 443,408 |
A crate for generating random placeholder text and translation in multiple languages.
There are four modules in this crate with the following features:
generate_text_for_language
are language: i32 which takes integers from 0 to 12 (see below for mapping) and write_to_file: bool which writes to a file if true.use text_manipulation_rs::text_generator;
text_generator::generate_text_for_language(language: i32, write_to_file: bool);
0 => english
1 => french
2 => spanish
3 => hindi
4 => russian
5 => arabic
6 => japanese
7 => german
8 => latin
9 => czech
10 => Irish
11 => Swedish
use text_manipulation_rs::my_memory;
my_memory::translate_q_langpair(q: String, langpair: String);
This module uses an API from Merriam-Webster developer center. User need to generate their own API key to be able to use this module.
get_meaning
is word:&str, and it returns a vector of all the definitions of the word if valid.use text_manipulation_rs::dictionary;
dictionary::get_meaning(word: &str);
This module uses an API from DeepL. User needs to generate their own API key to be able to use this module.
deepl::DeepLKey
first.use text_manipulation_rs::deepl::DeepLKey;
let auth = DeepLKey::new("/path/to/secret.txt").unwrap();
Text translation is the most common use case for using the DeepL API. For any translation call, the only required paramaters are the text to translate and the target language to translate to. API requests are under the request
module. DeepL request parameters can be found in the deepl
module.
use text_manipulation_rs::deepl::{DeepLKey, TargetLang};
use text_manipulation_rs::request::translation_request::{TranslationRequest};
let auth = DeepLKey::new("/path/to/secret.txt").unwrap();
let tr = TranslationRequest::new("Hello, World!", TargetLang::De);
let request = TranslationRequest::create_request(&auth);
let res = request.execute();
Additionally, the user may use their basic translation request to add additional specifications.
...
let tr = TranslationRequest::new("Hello, World!", TargetLang::De)
.set_source_lang(SourceLang::En)
.set_preserve_formatting(false)
.set_formality(Formality::More);
...
Glossaries allow the user to give specific translations for certain words. For example, suppose the user wants to translate the English words "Hello" and "Bye" to the German words "Hallo" and "Tschüss". The user would write these words in a tab-separated values format like so and pass the request to the API: "Hello\tHallo\nBye\tTschüss".
use text_manipulation_rs::deepl::{DeepLKey, SourceLang, TargetLang};
use text_manipulation_rs::request::glossary_request::{create_glossary_from_string};
let auth = DeepLKey::new("/path/to/secret.txt").unwrap();
let name = String::from("My Dictionary");
let source = SourceLang::En;
let target = TargetLang::De;
let entries = String::from("Hello\tHallo\nBye\tTschüss");
let res = create_glossary_from_string(&auth, name, source, target, entries);
Glossaries can be used in translation requests if and only if the source language is specified in the translation request. Please see the documentation for more uses of the glossary_request
module.