Sample code for 30+ languages & platforms
DataFlex

Detect the Primary Language Group of an Email

See more Email Object Examples

Demonstrates the read-only Chilkat Email.Language property, which identifies the primary language group detected in the email's subject and body text, returning values such as latin1, russian, or japanese. The Subject has the greatest influence on the result. This example sets English text and reads the detected language.

Background: This is a heuristic based on Unicode: every character belongs to a Unicode "block" (Latin, Cyrillic, Greek, CJK, etc.), and Chilkat classifies the message by which blocks its characters fall into. The goal is practical — choosing a suitable charset/encoding for the text — not formal linguistic detection. It does not read the MIME Content-Language header, and it ignores characters in address and other header fields.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    String sTemp1

    //  Demonstrates the read-only Email.Language property, a character-based
    //  heuristic that identifies the primary language group detected in the
    //  email's subject and body text (e.g. latin1, russian, japanese, ...).

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    Set ComSubject Of hoEmail To "Hello, this is an English subject line."
    Set ComBody Of hoEmail To "This is the body text, written in English."

    //  The Subject has the greatest influence on the result.
    Get ComLanguage Of hoEmail To sTemp1
    Showln "Language = " sTemp1


End_Procedure