Relatude Help

34.4 Translation

// one text
string norwegian = await db.Services.Translation.TranslateAsync("Good morning", "nb");

// many texts in one call; a TranslationText can name languages of its own
var result = await db.Services.Translation.TranslateAsync(
    ["Good morning", new TranslationText("Hej och välkommen", From: "sv"), new TranslationText("Free delivery", To: "de")],
    to: "nb");
string[] texts = result.Texts;                // in the order they were sent
string? from = result.Translations[0].From;   // "en", detected

// the language of a text
var found = await db.Services.Translation.DetectLanguageAsync("Hei på deg");   // found.Language is "nb"
  • Languages are BCP 47 codes such as en, nb, zh-Hans and pt-PT. Answers use the codes GetLanguagesAsync() lists, so nb-NO and no come back as nb. A language the service does not translate is refused with a 400 before anything is charged.
  • Send many texts in one call. It is cheaper and faster than one call per text. Without a from, each text's language is detected.
  • HTML: pass format: TranslationFormat.Html to keep the markup and translate only the text.
  • GetLanguagesAsync() gives the languages, the price and the most one call may carry, for free. DetectLanguagesAsync costs the same as translating the texts.