Summary

The Excel DETECTLANGUAGE function detects the language of a given text string. The result is a language code. For example, if the language is English, the result is "en"; if the language is French, the result is "fr"; if the language is German, the result is "de", and so on. 

DETECTLANGUAGE is only available in Excel 365 and requires an internet connection.

Purpose 

Detect the language of a given text string

Return value 

A language code

Syntax

=DETECTLANGUAGE(text)
  • text - A sample of the language as a text string.

How to use 

The DETECTLANGUAGE figures the language for a given text string. The result from DETECTLANGUAGE is a short language code indicating the language. For example, if the language is English, the result is "en"; if the language is French, the result is "fr"; if the language is Japanese, the result is "ja", and so on. Some of these codes are intuitive, but some aren't. See below for a list of common language codes. DETECTLANGUAGE only accepts one argument, text, so the syntax is very simple and looks like this:

=DETECTLANGUAGE(text)

Typically, the text is supplied as a cell reference like A1, but it can also be hardcoded as a string like "apple". 

The DETECTLANGUAGE function uses Microsoft Translation Services, so it requires an internet connection.

Basic Example

To use the DETECTLANGUAGE function, simply provide some text. For example, if we give DETECTLANGUAGE the word "apple", it "detects" English and returns "en":

=DETECTLANGUAGE("apple")  //  returns "en"

Likewise, if we give DETECTLANGUAGE the word for "apple" in four languages (French, Italian, German, and Spanish), it returns the four corresponding language codes: "fr," "it," "de," and "es."

=DETECTLANGUAGE("pomme")  //  returns "fr"
=DETECTLANGUAGE("mela")  //  returns "it"
=DETECTLANGUAGE("Apfel")  //  returns "de"
=DETECTLANGUAGE("manzana")  //  returns "es"

Note that DETECTLANGUAGE always returns a language code like "en", "it", "de", "es", etc. The TRANSLATE function supports over 100 languages, so there are many potential codes. See below for a list of common languages and codes. 

Example: Get language codes

In the worksheet below, we have text for "Is there a coffee shop around here?" in 12 languages. The goal is to determine the language codes based on the text in column B. The formula in D8, copied down, looks like this:

=DETECTLANGUAGE(B5)

As the formula is copied down the column, DETECTLANGUAGE returns a language code for each text string, as seen in column D below:

DETECTLANGUAGE example: Get language codes

Note that the DETECTLANGUAGE function is dynamic. If any of the text in column B is changed to a different language, TRANSLATE will return a new language code. 

Example: Get language names

Getting language codes automatically is great, but you probably want to know how to get an actual language name. To do that, you will want to set up a lookup table in your worksheet with columns for the language code and the language name. In the worksheet below, we have defined an Excel Table called "languages" like this:

A language lookup table for DETECTLANGUAGE

Then we can use the XLOOKUP function to get the correct language for a given code, as seen in column E of the worksheet below. The formula in cell E5 looks like this:

=XLOOKUP(D5,languages[Code],languages[Language])

The inputs to XLOOKUP are as follows:

  • lookup_value - D5
  • lookup_array - languages[Code]
  • return_array - languages[Language]

Using XLOOKUP to get the language name using the code

If you want to look up the language name from the code in one step, you can combine the formulas above into one formula like this:

=XLOOKUP(DETECTLANGUAGE(B5),languages[Code],languages[Language])

In this formula, DETECTLANGUAGE returns a language code to XLOOKUP as the lookup value, and XLOOKUP uses the code to get the language name in a single step.

Excel Tables make it possible to use "structured references" in formulas, like languages[Code] and languages[Language]. One advantage to structured references is that we don't need to lock any references in a formula like this. To learn more see our Excel Table guide.

Codes for common languages

The below shows language codes for some common languages that can be used with the TRANSLATE function. Note that some languages, like Portuguese, have more than one variant. For example, the code "pt" specifies Portuguese for Brazil, while "pt-pt" specifies Portuguese for Portugal.

Language Code Notes
Arabic ar  
Chinese zh-Hans Simplified
Czech cs  
Danish da  
Dutch nl  
English en  
Finnish fi  
French fr  
German de  
Hindi hi  
Indonesian id  
Italian it  
Japanese ja  
Korean ko  
Norwegian nb Bokmål
Polish pl  
Portuguese pt Brazilian
Spanish es  
Swedish sv  
Thai th  
Vietnamese vi  

The DETECTLANGUAGE function supports over 130 languages. You can find the full list of supported languages here.   

Notes

  • DETECTLANGUAGE always returns a language code as text.
  • If the text is an empty string (""), DETECTLANGUAGE also returns an empty string.
  • If the internet is not available, you may see a #CONNECT! error.
  • Use the TRANSLATE function to translate text to another language.
Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.