Browse the docs

detectLanguage

Tells which language text is written in.

Details #

detectLanguage(text) uses the Mac's language recognizer, offline, and returns a record: code (en, fr, ja, zh-Hans), name (in English) and confidence (0 to 1).

When it is not at least half sure, code is "und" and name is "Unknown": one or two Latin-script words are too little, and short names such as iPhone or Tokyo are guessed wrongly otherwise. From about two words it is right for English, French, German and Spanish; Japanese is recognised from a single word.

Parameters #

Takes 1 argument. {{ detectLanguage(text) }}

Examples #

detectLanguage("Peux-tu m'envoyer la facture ?").name
→ French
detectLanguage("ok").code
→ und

Gotchas #

  • code is "und" for empty text and for anything under 0.5 confidence. Test for it before relying on the language.