Open topic with navigation

# lang_detect

The function `lang_detect` performs language detection on a document.

## Syntax

    lang_detect(document, params)

## Arguments

Argument | Description
--- | ---
`document` | (LuaDocument) The document to analyze.
`params` | (table) A table of named parameters to configure language detection. The table maps parameter names (String) to parameter values. For information about the parameters that you can set, see the following table.

## Named Parameters

Named Parameter | Description | Configuration Parameter
--- | --- | ---
`section` | (string) The name of a section in the CFS configuration file. If you set this then any parameters not set in the `params` table are read from this section of the configuration file. |
`language_detection_directory` | (string) The path of the directory that contains the `langdetect.dat` file, which is required for language detection. | LanguageDetectionDirectory
`output_field` | (string) The name of the document field to write the name of the detected language to. | OutputField

## Returns

(Boolean). Returns true if the language was successfully detected and added to the specified document field. Returns false if the language could not be detected.

## Example

The following Lua script performs language detection on a document and writes the result to a document field named `DetectedLanguage`. If the language cannot be detected the script adds the field with the value `UNKNOWN`.

    function handler(document)
        if(not lang_detect(document, {language_detection_directory="C:/langdetect/", output_field="DetectedLanguage"})) then
            document:addField("DetectedLanguage", "UNKNOWN")
        end
        return true
    end

© Copyright 2019 Micro Focus or one of its affiliates | Send documentation feedback Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a web mail client, and send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm