Function translate

Source
pub fn translate(
    bible_reference: &str,
    target_lang_code: &str,
) -> Result<String, Box<dyn Error>>
Expand description

Translates a Bible reference in an other language

§Params

  • bible_reference: The Bible reference in any supported language
  • target_lang_code: The language code of the target language (such as de, en, zh_sim)

§Returns

A Result<String, Box<dyn Error>> with the following possible outcomes:

  • If the translation was successful, a String with the translated Bible reference will be returned.
  • If an error occurred, a Box<dyn Error> with the specific error will be returned.

§Example

// The German translation of Genesis 1:1 is "1. Mose 1,1"
let german_reference: String = bibleref::translate("Genesis 1:1", "de").unwrap();
assert_eq!(german_reference, "1. Mose 1,1");
// The Chinese translation of John 3:16 is "约翰福音3:16"
let chinese_reference: String = bibleref::translate("John 3:16", "zh_sim").unwrap();
assert_eq!(chinese_reference, "约翰福音3:16");
// The translation of a non-existing Bible reference will throw an error
assert!(bibleref::translate("Exodus 72", "de").is_err());
// You can also translate chapters of the Bible, the number of spaces will be ignored
let german_chapter: String = bibleref::translate("Matthew   19", "de").unwrap();
assert_eq!(german_chapter, "Matthäus 19");