Simple header only client to any instance of lingva translator. Includes basic functions such as translation and display of available languages.
sudo pacman -S curl nlohmann-json
sudo apt install libcurl-dev nlohmann-json-dev
#include "lingva-api/include/lingva.hpp"
Warning This library requires adding curl at compile time, add -lcurl flag.
lingvaClient client;
//OR with default source language
lingvaClient client("auto");
//OR with default source and target language
lingvaClient client("auto", "hu");
//OR with default source and target language and custom instance
lingvaClient client("auto", "hu", "lingva.ml");
client.getLanguages();
They are stored in public class member "languages" which is a vector std::vector<std::pair<std::string, std::string>> where first element is the full name and the second is the code.
client.listLanguages();
client.translate("Witaj świecie!");
Uses values from the initializer, or "auto" as source and "en" as target if nothing were specified in initializer
client.translate("Hello world!", "en", "ru");
std::string getTranslation = client.translate(sampleSentence, "en", "error");
if (getTranslation.length())
std::cout << "Success";
else
std::cout << "Error";
Simply empty result means error