Hreflang for Independent Multilingual Content: When Pages Are Not Translations
An English article and a Traditional Chinese article can cover the same technology without being localized versions of the same page. Connecting them with hreflang anyway sends a stronger equivalence signal than the content supports.
For a multilingual technical blog with independently planned articles, the safe default is a self-canonical page with no hreflang. Add reciprocal alternates only when the two URLs genuinely represent the same article for different language audiences.
Canonical and hreflang answer different questions
A canonical link identifies the preferred URL for the current page:
<link rel="canonical" href="https://example.com/en/posts/pagefind-multilingual-search-astro/">An hreflang alternate identifies another localized version of the same content:
<link rel="alternate" hreflang="zh-Hant" href="https://example.com/posts/pagefind-multilingual-search-astro/"><link rel="alternate" hreflang="en" href="https://example.com/en/posts/pagefind-multilingual-search-astro/">Google Search Central describes hreflang as a way to identify localized variations of a page. It also expects every version to list the other versions, including itself. A one-way link is not a complete relationship.
The canonical on each localized page should normally point to that page itself. Do not canonicalize an English translation to the Traditional Chinese original; doing so conflicts with the intent to index both language versions.
Decide whether two articles are equivalents
Use content intent, not shared tags, to make the decision.
| Relationship | Self-canonical | Reciprocal hreflang |
|---|---|---|
| Direct translation with the same examples and purpose | Yes | Yes |
| Localized adaptation with the same reader task and equivalent main content | Yes | Yes |
| Two tutorials about Astro with different problems | Yes | No |
| English article inspired by a shorter Chinese note | Yes | No |
| Only one language version exists | Yes | No |
For example, an English guide about preserving legacy URLs and a Chinese post about generating an Astro sitemap both belong to an Astro/SEO cluster. They are useful internal links, but they are not language alternatives. Each should remain self-canonical without an hreflang connection.
Represent translation as optional content data
Folder names and matching slugs are weak evidence of equivalence. Use an explicit optional key in the content schema:
const postsCollection = defineCollection({ schema: z.object({ title: z.string(), lang: z.enum(["en", "zh-TW", "zh_TW", ""]).optional(), translationKey: z.string().trim().min(1).optional(), }),});Independent articles omit translationKey. A verified pair receives the same value:
# Traditional Chinese articlelang: zh-TWtranslationKey: astro-i18n-routing# English articlelang: entranslationKey: astro-i18n-routingThis model makes the editorial decision visible and reviewable. It also allows translated titles and different slugs without relying on filename equality.
Build alternates only for complete pairs
Group posts by non-empty translationKey, then require one unambiguous entry for each supported locale.
type Locale = "zh-TW" | "en";
for (const post of posts) { const key = post.data.translationKey?.trim(); if (!key) continue;
const locale = normalizeLocale(post.data.lang); const group = groups.get(key) ?? new Map<Locale, Post>();
if (group.has(locale)) { throw new Error(`Duplicate translation key: ${key} (${locale})`); }
group.set(locale, post); groups.set(key, group);}When a group has both zh-TW and en, create two alternates and pass them into the page layout. When only one side exists, emit nothing. This avoids publishing a relation to a missing URL.
The resulting Astro layout can render absolute URLs:
{alternates.map((alternate) => ( <link rel="alternate" hreflang={alternate.hreflang} href={new URL(alternate.path, Astro.site).href} />))}Fail the build when the same locale uses one translation key twice. Choosing the first match would make the output depend on collection order and could connect the wrong article.
Keep independent English articles unpaired
For an English-first experiment, it is acceptable for every initial article to have no equivalent Chinese page. Give each English URL:
- an absolute self-canonical containing
/en/posts/; html lang="en";BlogPosting.inLanguageset toen;- its own English title, description, and body;
- no article-level
hreflanguntil an equivalent page exists.
These technical boundaries work alongside the URL and query design in Build an Astro Multilingual Blog Without Migrating Existing URLs. If the site uses Pagefind, the same root language value can also keep multilingual search results separated.
Verify the generated HTML
Check output files after the production build. Source components cannot prove which conditional tags were rendered.
pnpm build
rg 'rel="canonical"' dist/en/postsrg 'hreflang=' dist/en/postsrg '"inLanguage":"en"' dist/en/postsrg '/en/posts/en/' distFor a pilot containing only independent English articles, the hreflang search should return no matches. The double-prefix search should also be empty.
If you later add a translation pair, inspect both generated pages and verify that:
- both pages remain self-canonical;
- both list the English and Traditional Chinese alternates;
- alternate URLs are absolute and return successful pages;
- no third page shares the key in either locale.
The editorial test comes before the markup test: if two articles do not solve the same reader problem with equivalent main content, do not pair them. A shared topic is an internal-link relationship, not automatically a language-alternate relationship.
FAQ
Q: Does every page on a multilingual site need hreflang?
A: No. A page needs hreflang only when another URL is an equivalent localized version for a different language or region. A multilingual site can contain many independent self-canonical pages with no alternate relationship.
Q: Should an English translation canonicalize to the original article?
A: Normally, no. If both localized pages are intended to be indexed, each should use a self-canonical URL and list the reciprocal language alternates. Canonicalizing the English page to the original sends a conflicting consolidation signal.
Q: Should I publish hreflang when only one side of a translation pair exists?
A: Wait until both localized URLs exist and can reference each other. An incomplete one-way relationship does not represent a complete alternate set, so the safer output is no article-level hreflang until the pair is ready.
References:
Google Search Central: Tell Google about localized versions of your page
Report a typo or broken link, or suggest a related topic.