# Validate ISO 639-1 language codes

- Check 23.05 · Hreflang and regional variants · Critical
- Source: https://checklist-seo-geo.com/en/hreflang-regional-variants/validate-iso-639-1-language-codes
- Check that every hreflang value starts with a valid ISO 639-1 language code (ja, not jp; sv, not se) and fix it where the CMS defines it.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/hreflang-regional-variants/validate-iso-639-1-language-codes.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

The value of an `hreflang` attribute always starts with a two-letter language code from the ISO 639-1 standard (ISO, the International Organization for Standardization): `fr`, `en`, `de`, `ja`. A country on its own, a three-letter code or a made-up code are not accepted by Google. Once the task is done, every code on the site actually designates the language of the content, and an automated check no longer reports any errors.

## Why it matters

Google states it in its guide to localized versions: the language code is mandatory, in ISO 639-1 format; only codes listed in that standard are accepted. An annotation whose code is not recognized cannot be used to choose the version to show.

The main trap is confusing country codes with language codes. The two lists look alike but do not overlap: `jp` is Japan, the language is `ja`; `se` is the code for Northern Sami, not Swedish (`sv`). Google itself cites the example of `be`, which designates Belarusian and not Belgium: a region code can never be used on its own.

Some errors even get past validators, because the code exists, but for another language: `ch` is Chamorro, `ca` Catalan, `ar` Arabic. Only a human review of the decoded language catches them.

A few clarifications from Google's documentation:

- case does not matter (`FR` and `fr` are both accepted); the convention is to write the language in lowercase;
- a script can be specified with an ISO 15924 code: `zh-Hans` (Simplified Chinese), `zh-Hant` (Traditional), `sr-Latn`;
- Google uses neither `hreflang` nor the `lang` attribute to determine the language of a page: it detects it itself. A wrong code therefore does not change the detected language; it makes the annotation unusable or misleading.

## What it improves

- **Annotations taken into account**: a valid code is the condition for Google to match the version with the right audience.
- **The right version shown**: a `ch` code meant for Switzerland actually targets Chamorro readers; Swiss users do not get the intended page.
- **Consistency**: the same code everywhere (tags, sitemap, `lang` attribute, converted `og:locale`) simplifies checks.
- **Rankings and AI answers**: no direct effect.

## How to check

Collect the codes actually used, on one page and then on a list of URLs (`urls.txt`):

```bash
curl -s https://example.com/fr/tarifs/ | grep -o -i 'hreflang="[^"]*"' | cut -d'"' -f2

while read -r url; do
  curl -s "$url" | grep -o -i 'hreflang="[^"]*"'
done < urls.txt | cut -d'"' -f2 | sort | uniq -c
```

If the annotations are in the sitemap:

```bash
curl -s https://example.com/sitemap.xml | grep -o 'hreflang="[^"]*"' | cut -d'"' -f2 | sort | uniq -c
```

Expected result: a short list of stable codes, for example `fr`, `en`, `de`, `fr-CH`, `x-default`. Each code appears on a comparable number of pages; an isolated code often signals manual entry.

Tools:

- **Screaming Frog**: with "Store Hreflang" and "Crawl Hreflang" ticked in `Configuration > Spider > Crawl`, open the Hreflang tab, "Incorrect Language & Region Codes" filter.
- **Merkle's hreflang tester**: flags a URL's invalid codes.

## How to implement

### Step 1 — Validate each code

Without a paid tool, download the IANA (Internet Assigned Numbers Authority) Language Subtag Registry: its two-letter language codes are those of ISO 639-1, its two-letter region codes those of ISO 3166-1 alpha-2.

```bash
curl -s -o registre.txt https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
```

Save this script as `codes_hreflang.py`. It checks the language, script and country of each code, and shows their names for review:

```python
import sys

RESERVED = {'AC', 'CP', 'CQ', 'DG', 'EA', 'EU', 'EZ', 'IC', 'TA', 'UN'}

subtags = {}
text = open(sys.argv[1], encoding='utf-8').read()

for record in text.split('%%'):
    fields = {}
    for line in record.splitlines():
        if ': ' in line and not line.startswith(' '):
            key, value = line.split(': ', 1)
            fields.setdefault(key, value)
    if 'Subtag' in fields:
        subtags[(fields['Type'], fields['Subtag'].lower())] = fields


def check(code):
    if code.lower() == 'x-default':
        return 'OK', 'default version'
    if '_' in code:
        return 'ERROR', 'underscore: use a hyphen (fr-FR)'

    parts = code.split('-')
    language = subtags.get(('language', parts[0].lower()))

    if len(parts[0]) != 2 or not language:
        return 'ERROR', f'"{parts[0]}" is not an ISO 639-1 language code'
    if 'Deprecated' in language:
        return 'ERROR', f'deprecated code, replace with "{language.get("Preferred-Value")}"'

    notes = [language['Description']]

    for part in parts[1:]:
        script = subtags.get(('script', part.lower())) if len(part) == 4 else None
        region = subtags.get(('region', part.lower())) if len(part) == 2 else None

        if script:
            notes.append(f'{script["Description"]} script')
        elif len(part) == 3 and part.isdigit():
            return 'ERROR', f'numeric region "{part}" not accepted by Google'
        elif not region or 'Deprecated' in region or region['Description'] == 'Private use':
            return 'ERROR', f'"{part}" is neither a script nor an ISO 3166-1 alpha-2 country code'
        elif part.upper() in RESERVED:
            return 'ERROR', f'"{part}" is a reserved code, with no effect ({region["Description"]})'
        else:
            notes.append(region['Description'])

    return 'OK', ' / '.join(notes)


for code in sorted({line.strip() for line in sys.stdin if line.strip()}):
    status, detail = check(code)
    print(f'{status}\t{code}\t{detail}')
```

Feed it the collected codes:

```bash
curl -s https://example.com/sitemap.xml | grep -o 'hreflang="[^"]*"' | cut -d'"' -f2 | python3 codes_hreflang.py registre.txt
```

Sample output:

```txt
OK	ch	Chamorro
OK	de-CH	German / Switzerland
ERROR	en-UK	"UK" is neither a script nor an ISO 3166-1 alpha-2 country code
ERROR	es-419	numeric region "419" not accepted by Google
ERROR	fr_FR	underscore: use a hyphen (fr-FR)
ERROR	jp	"jp" is not an ISO 639-1 language code
OK	zh-Hant	Chinese / Han (Traditional variant) script
```

### Step 2 — Review the decoded language

The script validates the form, not the intent. Read the third column: `ch` is accepted but decoded as "Chamorro", when you were aiming for Switzerland. Compare each line with your table of target languages (see [define target languages](https://checklist-seo-geo.com/en/international-architecture/define-target-languages)).

Common confusions between country and language:

| Wrong code | What it designates | Correct code |
|---|---|---|
| `jp` | nothing (Japan = country) | `ja` |
| `cn` | nothing (China = country) | `zh`, `zh-Hans`, `zh-CN` |
| `kr` | Kanuri | `ko` |
| `se` | Northern Sami | `sv` |
| `dk` | nothing (Denmark = country) | `da` |
| `cz` | nothing (Czechia = country) | `cs` |
| `gr` | nothing (Greece = country) | `el` |
| `ua` | nothing (Ukraine = country) | `uk` |
| `ee` | Ewe | `et` (Estonian) |
| `si` | Sinhala | `sl` (Slovenian) |
| `br` | Breton | `pt-BR` |
| `be` | Belarusian | `fr-BE`, `nl-BE` |
| `ch` | Chamorro | `de-CH`, `fr-CH`, `it-CH` |
| `ca` | Catalan | `en-CA`, `fr-CA` |
| `ar` | Arabic | `es-AR` |
| `at`, `us`, `gb`, `mx` | nothing (countries) | `de-AT`, `en-US`, `en-GB`, `es-MX` |
| `iw`, `in`, `ji` | codes withdrawn from the standard | `he`, `id`, `yi` |
| `eng`, `fra`, `ger` | three-letter codes (ISO 639-2) | `en`, `fr`, `de` |

For a language with no ISO 639-1 code, such as Cantonese (`yue`), Google's documentation offers no solution: a close language-country code (`zh-HK`) is the most widespread practice, with no guarantee.

### Step 3 — Fix at the source

The code is almost always defined in a single place: the language configuration of the CMS or framework. Fix it there, never page by page, then purge the caches and run step 1 again.

### WordPress

Versions: WordPress 6.4 to 7.1; WPML 4 and 5, Polylang 3, TranslatePress 2 and 3, November 2026.

- **WPML**: `WPML > Settings > Languages` (`WPML > Languages` in older versions), Site Languages section, Edit Languages command. Each language has an editable `hreflang` code, separate from the internal language code, which cannot be changed after creation. A custom language (for example Argentinian Spanish) cannot reuse a code taken by a built-in language: give it the internal code `es-ar` and the `hreflang` code `es-AR`.
- **Polylang**: `Languages > Languages`, edit the language. The `hreflang` code is computed from the "Locale" (`fr_FR` becomes `fr-FR`) or from the language code. Choose an existing WordPress locale; the `pll_rel_hreflang_attributes` filter lets you adjust the list per code.
- **TranslatePress**: languages come from WordPress locales; the `trp_hreflang` filter lets you change the code produced.

### Shopify

Versions: Shopify admin, all plans, November 2026.

Codes come from the published languages and the countries of each market, in the standard format. An anomaly usually comes from tags added to the theme or by an app: remove them and leave the automatic tags.

### Drupal

Versions: Drupal 10 and 11.

Drupal uses each language's code (`/admin/config/regional/language`) as the `hreflang` value. For a custom language, choose a valid code from the start (`pt-br`, `zh-hans`): it is hard to change afterwards, because content and translations are attached to it.

### Laravel

Versions: Laravel 11 to 13.

Application locales often follow the `fr_FR` form or in-house abbreviations. Keep an explicit mapping table in the configuration, for example `config/app.php`:

```php
'hreflang_codes' => [
    'fr' => 'fr',
    'en' => 'en',
    'de_CH' => 'de-CH',
    'pt_BR' => 'pt-BR',
],
```

and use `config("app.hreflang_codes.{$locale}")` in the template, rather than a `str_replace('_', '-', $locale)` that lets made-up codes through.

### Symfony

Versions: Symfony 6.4, 7.4 and 8.

Same principle: a `locale => hreflang code` table in the parameters (`config/services.yaml`), passed to the Twig template. Symfony locales accept `fr_FR`; the `hreflang` code is written `fr-FR`.

### Next.js

Versions: Next.js 15 and 16 (App Router).

The keys of `alternates.languages` become the `hreflang` values. If your URL segments are abbreviations (`/jp/`, `/cn/`), do not reuse them as they are: map each segment to its code (`jp` to `ja`, `cn` to `zh-Hans`).

### Nuxt

Versions: Nuxt 3 and 4, @nuxtjs/i18n module 9 and 10.

With `@nuxtjs/i18n`, each locale's `language` property (which replaces `iso`, removed in version 9) becomes the `hreflang` value. The `code` (`jp`, used in the URL) can stay as it is, provided `language` is valid:

```ts
locales: [
  { code: 'jp', language: 'ja' },
  { code: 'ch-fr', language: 'fr-CH' },
],
```

### Astro

Versions: Astro 5 to 7, @astrojs/sitemap integration 3.

In the `i18n` option of `@astrojs/sitemap`, the value associated with each key of `locales` is the code written in the sitemap: `{ jp: 'ja', fr: 'fr-FR' }`.

## Common mistakes

- **Reusing the URL segment or the switcher flag** (`/jp/`, `/uk/`) as the language code.
- **Using the system locale** with an underscore (`fr_FR`), the format of `og:locale`, not of `hreflang`.
- **A country code on its own** (`be`, `ch`, `at`): rejected, or interpreted as another language.
- **Three-letter codes** (`fra`, `eng`) coming from a product database or an ERP (Enterprise Resource Planning) system.
- **Numeric region codes** such as `es-419` for Latin America: not accepted by Google; list the countries (`es-MX`, `es-AR`) or use `es`.
- **Validating without reviewing**: `ch`, `ca` or `ar` pass the automated check but target the wrong language.

## Frequently asked questions

### Should the hreflang language code be written in lowercase?

It is not mandatory: Google states that the hreflang value is not case-sensitive and accepts FR as well as fr. The convention, taken from the standards, is to write the language in lowercase and the country in uppercase, for example fr-CH or en-GB. Choose one form and keep it everywhere, in the tags as in the sitemap, to make comparisons easier during audits.

### What is the hreflang code for Japanese: jp or ja?

The hreflang code for Japanese is ja, from the ISO 639-1 language standard. jp is the code for Japan in the country standard, ISO 3166-1, and cannot be used on its own. To target Japanese in Japan, write ja-JP; to target Japanese readers wherever they are, ja is enough. The same logic applies to Swedish (sv, not se) and Danish (da, not dk).

### Can you use es-419 for Latin American Spanish?

No. Google only accepts ISO 3166-1 alpha-2 region codes, and cites es-419 precisely as an example of an unsupported code, because 419 is a numeric United Nations region code. For a page intended for all of Latin America, use es if no other Spanish version competes with it, or annotate the same URL for each target country, es-MX, es-AR, es-CO, a common practice.

### How do you specify Simplified or Traditional Chinese in hreflang?

Google accepts ISO 15924 script codes: zh-Hans for Simplified Chinese and zh-Hant for Traditional Chinese. A country code can also imply the script, such as zh-TW for Traditional in Taiwan or zh-CN for Simplified in China. The two can be combined, for example zh-Hant-HK. Do not use zh-CHS or zh-CHT, old forms that do not appear in these standards.

## Resources

- [Google Search Central: Supported language and region codes](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=en#language-codes)
- [Library of Congress: ISO 639-1 and 639-2 code list](https://www.loc.gov/standards/iso639-2/php/code_list.php)
- [IANA: Language Subtag Registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry)
- [W3C: Choosing a language tag](https://www.w3.org/International/questions/qa-choosing-language-tags)
- [Screaming Frog: Incorrect Language & Region Codes filter](https://www.screamingfrog.co.uk/seo-spider/issues/hreflang/incorrect-language-region-codes/)
- [Nuxt i18n: SEO and hreflang](https://i18n.nuxtjs.org/docs/guide/seo)

Next steps: [Validate ISO 3166-1 Alpha-2 country codes](https://checklist-seo-geo.com/en/hreflang-regional-variants/validate-iso-3166-1-alpha-2-country-codes), [Use en-GB rather than en-UK](https://checklist-seo-geo.com/en/hreflang-regional-variants/use-en-gb-rather-than-en-uk) and [Set html lang on each page](https://checklist-seo-geo.com/en/development-accessibility-language/set-html-lang-each-page).
