Skip to content

v0.4.0

Choose a tag to compare

@Avimitin Avimitin released this 26 Jan 05:34
· 105 commits to master since this release
97d12f6

This version implement auto send and breaks all the old API call.

v0.3.0 => v0.4.0 migration guide

  • API creation
// OLD
let api = DeepLApi::new("key", true);

// NEW
let api = DeepLApi::with("key").is_pro(true).new();
let api = DeepLApi::with("key").new();
  • Translate Text
// OLD
let settings = TranslateTextProp::build()
	.target_lang(Lang::DE)
	.build();
let response = api.translate("Hello World", &settings).await.unwrap();

// NEW
let response = api.translate_text("Hello World", Lang::DE).await.unwrap();

//----------------------------------------

let origin = "Hello World <keep>This will stay exactly the way it was</keep>";

// OLD
let settings = TranslateTextProp::builder()
    .source_lang(Lang::EN)
    .target_lang(Lang::DE)
    .ignore_tags(vec!["keep".to_owned()])
    .tag_handling(TagHandling::Xml)
    .build();
let response = api.translate(origin, &settings).await.unwrap();

// NEW
let response = api
    .translate_text(origin, Lang::DE)
    .source_lang(Lang::EN)
    .ignore_tags(vec!["keep".to_owned()])
    .tag_handling(TagHandling::Xml)
    .await
    .unwrap();
  • Translate Document
// OLD
let upload_option = UploadDocumentProp::builder()
    .source_lang(Lang::EN_GB)
    .target_lang(Lang::ZH)
    .file_path("./hamlet.txt")
    .filename("Hamlet.txt")
    .formality(Formality::Default)
    .glossary_id("def3a26b-3e84-45b3-84ae-0c0aaf3525f7")
    .build();
let response = api.upload_document(upload_option).await.unwrap();

// NEW
let filepath = std::path::PathBuf::from("./hamlet.txt");
let response = api.upload_document(&filepath, Lang::ZH)
        .source_lang(Lang::EN_GB)
        .filename("Hamlet.txt")
        .formality(Formality::Default)
        .glossary_id("def3a26b-3e84-45b3-84ae-0c0aaf3525f7")
        .await
        .unwrap();

Changed

  • (BREAKING) Implement auto send for all endpoint
  • (BREAKING) DeepLApi implementation is now separated to multiple endpoint file
  • (BREAKING) DeepLApiResponse is now renamed to TranslateTextResp
  • (BREAKING) DeepLApi is now init by ::with() function and build by .new() function
  • Using docx-rs to parse document content for testing