🔍 SEO ToolsFree Plan

GET_LOCALE_BY_SUBDOMAIN

Extract locale/language code from a subdomain

Formula Signature
=GET_LOCALE_BY_SUBDOMAIN(url)

Returns: string

Overview

GET_LOCALE_BY_SUBDOMAIN extracts the locale or language code from the subdomain portion of a URL. Many international websites use subdomain-based localization, where different language versions of the site are hosted on subdomains like "en.example.com", "fr.example.com", or "de.example.com". This function parses the URL and returns the subdomain value if it matches a recognized locale pattern, making it easy to categorize and analyze URLs by language or region.

Parameters

ParameterTypeRequiredDescription
urlstringYesThe full URL from which to extract the locale subdomain

Examples

1

Extract a simple language code

Extracts the French locale code from the subdomain.

fx
=GET_LOCALE_BY_SUBDOMAIN("https://fr.example.com/page")

Output

fr
2

Detect a regional locale

Extracts the Brazilian Portuguese locale from a regional subdomain.

fx
=GET_LOCALE_BY_SUBDOMAIN("https://pt-br.example.com/produtos")

Output

pt-br
3

No locale in subdomain

Returns an empty string when the subdomain is "www" or another non-locale value.

fx
=GET_LOCALE_BY_SUBDOMAIN("https://www.example.com/page")

Output

4

URL without subdomain

Returns an empty string when there is no subdomain present in the URL.

fx
=GET_LOCALE_BY_SUBDOMAIN("https://example.com/about")

Output

5

Bulk locale classification

References a cell containing a URL. Drag down to classify an entire column of international URLs by their locale.

fx
=GET_LOCALE_BY_SUBDOMAIN(A2)

Output

de

Use Cases

SEO Agency

Hreflang Audit

When auditing hreflang implementations, extract the locale from each URL subdomain to verify it matches the declared hreflang attribute. Identify mismatches that could confuse search engines about which language version to show.

Link Building

International Backlink Analysis

Classify backlinks by the language version of the page they point to. Understand which locale versions are attracting the most external links and identify underperforming language versions that need link building attention.

Technical SEO

Crawl Data Classification

After exporting crawl data from tools like Screaming Frog, use GET_LOCALE_BY_SUBDOMAIN to automatically classify thousands of URLs by language, enabling locale-specific analysis of technical issues.

Enterprise SEO

Content Parity Analysis

Group URLs by locale to count how many pages exist for each language version. Quickly identify which locales are missing content compared to the primary language, guiding translation priorities.

Pro Tips

TIP

Use COUNTIF on the results column to create a summary of how many URLs exist for each locale. This gives you a quick content parity overview across all language versions.

TIP

Combine with FILTER or conditional formatting to highlight URLs where the detected locale does not match the expected hreflang value, quickly surfacing internationalization errors.

TIP

Pair with GET_URLS_FROM_SITEMAP to extract all URLs from an international site and then automatically classify each one by locale for a comprehensive international SEO audit.

This function is essential for international SEO audits where you need to analyze large sets of URLs and determine which language version each page belongs to. When working with hreflang implementations, crawl data exports, or backlink reports, you often have thousands of URLs that need to be classified by locale. Instead of manually inspecting each URL or writing complex text parsing formulas, GET_LOCALE_BY_SUBDOMAIN handles the extraction automatically.

The function recognizes standard locale codes including two-letter language codes (en, fr, de, es, pt, it, nl, ja, ko, zh), extended locale codes with region identifiers (en-us, pt-br, zh-tw), and common subdomain patterns used for localization. If the subdomain does not match a known locale pattern, the function returns an empty string, allowing you to easily filter or flag URLs that do not follow the expected localization structure.

This function is particularly useful when combined with other Unlimited Sheets functions. Use it alongside GET_URLS_FROM_SITEMAP to extract all URLs from multiple language sitemaps and then classify each URL by locale. Pair it with SLUGIFY to generate locale-specific URL slugs, or use it in conditional formulas to create locale-based reports and dashboards.

Common Errors

#VALUE!

Cause: The input is not a valid URL string or the cell is empty.

Fix: Ensure the URL is properly formatted with a protocol (https:// or http://). Verify the cell is not blank and contains a text value.

Unexpected result

Cause: The subdomain contains a value that looks like a locale but is actually a brand or product subdomain (e.g., "tv.example.com").

Fix: Review the results and cross-reference with the actual website structure. Some two-letter subdomains like "tv", "go", or "my" may be falsely identified as locales depending on the implementation.

Empty string for valid locale URL

Cause: The URL uses a locale format that is not in the recognized patterns, or the URL structure is unusual.

Fix: Verify the URL is correctly formatted. If the website uses a non-standard locale format in its subdomains, the function may not recognize it. Check the URL manually and consider using text parsing formulas as a fallback.

Frequently Asked Questions

The function recognizes two-letter language codes (en, fr, de, es, etc.), language-region combinations (en-us, pt-br, zh-tw), and common locale patterns used in subdomain-based internationalization.

The function returns an empty string if the subdomain is not a recognized locale pattern. This includes common non-locale subdomains like "www", "blog", "shop", or "app".

No, this function specifically extracts locale codes from subdomains (e.g., fr.example.com). For subdirectory-based localization (e.g., example.com/fr/), you would need to parse the URL path separately using standard text functions.

Yes, the function returns the exact subdomain value. If the subdomain is "en", it returns "en". If the subdomain is "en-us", it returns "en-us". This preserves the specificity of the locale code used by the website.

For best results, provide URLs with the full protocol (https:// or http://). URLs without a protocol may not be parsed correctly.

Related Functions

Start using GET_LOCALE_BY_SUBDOMAIN today

Install Unlimited Sheets to get GET_LOCALE_BY_SUBDOMAIN and 41 other powerful functions in Google Sheets.