Features of !SEMTools
↑ Navigate Excel tasks and !SEMTools add-in features ↑

DETECTLANGUAGE

cldeditorUpdated 4 min read

DETECTLANGUAGE returns the language code for a piece of text in Excel for Microsoft 365. Use the code to filter multilingual reviews or translate only the rows that need it.

Function categoryText functions
Introduced inMicrosoft 365
ReturnsLanguage code
Related functionsTRANSLATE

DETECTLANGUAGE syntax and result

=DETECTLANGUAGE(A2)

Pass text or a cell reference. The result is a code such as “es” for Spanish, “fr” for French, or “en” for English. The function takes one argument and uses Microsoft’s online language service.

Identify languages in a column of reviews

Enter the formula in B2 and fill down. IF leaves blank rows unclassified. Turn on the filter in column B and select the language codes you need.

Reviews in several languages
B2=IF(A2="","",DETECTLANGUAGE(A2))
AB
1ReviewLanguage code
2Entrega rápida y buen embalajees=IF(A2="","",DETECTLANGUAGE(A2))
3La commande est arrivée à tempsfr=IF(A3="","",DETECTLANGUAGE(A3))
4The order arrived on timeen=IF(A4="","",DETECTLANGUAGE(A4))
5=IF(A5="","",DETECTLANGUAGE(A5))

Full sentences give the service more context. Short replies such as “OK,” names, and product codes can be ambiguous.

Translate rows in a different language

Detect the source language in column B and enter the target in D2. The formula in C keeps the source text when the codes match. On the other rows, it passes the source code to TRANSLATE.

Check the language before translating
C2=IF(B2="","",IF(B2=$D$2,A2,TRANSLATE(A2,B2,$D$2)))
ABCD
1ReviewSource codeResultTarget code
2Entrega rápida y buen embalajees=IF(A2="","",DETECTLANGUAGE(A2))Fast delivery and good packaging=IF(B2="","",IF(B2=$D$2,A2,TRANSLATE(A2,B2,$D$2)))en
3La commande est arrivée à tempsfr=IF(A3="","",DETECTLANGUAGE(A3))The order arrived on time=IF(B3="","",IF(B3=$D$2,A3,TRANSLATE(A3,B3,$D$2)))
4The order arrived on timeen=IF(A4="","",DETECTLANGUAGE(A4))The order arrived on time=IF(B4="","",IF(B4=$D$2,A4,TRANSLATE(A4,B4,$D$2)))
5=IF(A5="","",DETECTLANGUAGE(A5))=IF(B5="","",IF(B5=$D$2,A5,TRANSLATE(A5,B5,$D$2)))

C4 returns the English review as it is. Column B still calls the language service to determine the code.

When to check the language code

The formula returns one code for the input. If you need to label each part of a mixed-language review, split it into separate cells first. Review codes for very short replies and names before you depend on them for a mail merge or publication.

If the function is missing, check your Microsoft 365 version. If the service reports that you reached its daily quota, wait for it to reset. Once your text is final, you can paste the verified codes as values.

LanguageDetect: detect languages locally in Excel

I built LanguageDetect for multilingual keyword lists. The XLL runs locally with the fastText lid.176 model. It recognizes 176 languages and returns the two highest-scoring language codes.

In the recording, Microsoft returns en for the German queries below, while LanguageDetect ranks de first. Compare columns B and C. fastText can also make mistakes, particularly on short or mixed-language queries.

Compare DETECTLANGUAGE and LanguageDetect results in Excel
Compare language detection for Excel search queries
Results from the animation
C2=LanguageDetect(A2)
ABC
1QueryMicrosoftLanguageDetect
23 wurzel in excel berechnenden=DETECTLANGUAGE(A2)de,91%,en,4%=LanguageDetect(A2)
35te wurzel in excelen=DETECTLANGUAGE(A3)de,91%,en,5%=LanguageDetect(A3)
45 wurzel in excel berechnenden=DETECTLANGUAGE(A4)de,92%,en,4%=LanguageDetect(A4)

Column A contains queries from the recording, B shows Microsoft’s result, and C shows fastText’s top two predictions. Select a cell in B or C to copy its formula.

For example, de,91%,en,4% means a 91% score for German and 4% for English. These are rounded model scores, not the proportions of the text written in each language. The top two scores do not have to add up to 100% because the model considers other languages too.

For one query, copy the formula from column C above and fill it down. With dynamic arrays, you can pass the whole range in one formula. Empty cells return blank text.

=LanguageDetect(A2:A1000)

Download and install LanguageDetect

Download both files and keep them in the same folder. This build is for 64-bit Excel on Windows. The model loads on the first call and stays in Excel’s memory. Calculations work offline.

In Excel, open File → Options → Add-ins. Select Excel Add-ins in the Manage list and click Go, then Browse and select LanguageDetect.xll. Keep lid.176.bin beside the add-in without renaming it.

The model was trained on Wikipedia, Tatoeba and SETimes text and is distributed under CC BY-SA 3.0. The fastText engine uses the MIT licence. Attribution and licence information.

Language detection without Microsoft 365

In Excel 2013, you can get language codes from an external service, paste them into a helper column, and filter the rows. If your goal is translation, GTranslate and the translation options can let the model infer the source language. These formulas return translated text. Keep a separate column when you also need language codes.