Skip to content
Rumen Damyanov edited this page Dec 4, 2026 · 1 revision

Files and directories

$detector = new LanguageDetector();

$one = $detector->detectFile('/notes/sofia.txt');
$many = $detector->detectPaths(['/notes/a.txt', '/notes/missing.txt']);
$directory = $detector->detectDirectory('/notes');
$here = $detector->detectDirectory('/notes', false);

detectPaths and detectDirectory store a LangidException on the entry that failed. The other entries are still returned. detectFile throws.

Which files are read

Text: txt, md, markdown, html, htm, xhtml, xml, csv, json, rst, log, text.

Reported as binary_document: pdf, doc, docx, rtf, odt, ppt, pptx, xls, xlsx.

Other extensions, dotfiles, and symbolic links are omitted. UTF-8 is the default. A UTF-8 BOM is skipped. UTF-16 LE and UTF-16 BE are accepted when the file starts with a BOM.

HTML and XML lose tags, comments, scripts, and styles before scoring. Character entities such as & and B are decoded.

A file over maxBytes is file_too_large. A directory listing over maxFiles throws too_many_files for the whole call. An empty path or a path containing a NUL byte is invalid_path.

Pass extracted PDF text to detect(). The library does not decode PDF streams.

See Quick start for the result object and Examples for a directory report.

Clone this wiki locally