Language‑Aware Discovery & Navigation

Navigation labels, links, and routes now derive strictly from the selected language; filenames and manifest language hints are advisory only.

Language‑Aware Discovery & Navigation

This document explains the new language-first behavior in the docs system. The sidebar and routes now reflect the user’s selected language, regardless of filename conventions or manifest language hints.

What changed

How it works

🔄 Language Detection & Navigation

  1. Discovery builds a neutral list of files for the current language context and tags discovered items with that context
  2. When converting discovered items to navigation items, link paths are derived using the selected language:
    • English: /section/page
    • Spanish: /es/section/page
  3. Dynamic route generation includes only routes that match the selected language context

🌐 Cross-Language Linking (NEW)

  1. Frontmatter Priority: When user switches languages, system first checks current page's frontmatter for languageVersions
  2. Intelligent Navigation: If equivalent page exists in target language, navigates directly to it
  3. Graceful Fallback: If frontmatter method fails, falls back to directory translation
  4. Final Fallback: If all methods fail, navigates to language root (/getting-started or /es/getting-started)

🔧 Technical Implementation

Key services involved

Authoring guidelines

🚨 CRITICAL: Avoid Hardcoded Language Logic

❌ NEVER do this:

// BAD: Hardcoded language logic
const langPrefix = currentLang === 'es' ? '/es' : '';
const isSpanish = path.startsWith('/es/');

✅ ALWAYS do this:

// GOOD: Scalable language system
const languageUrlMap: { [key: string]: string } = {
  'en': '',
  'es': '/es',
  'fr': '/fr',
  'de': '/de',
  'pt': '/pt',
  'it': '/it',
  'ja': '/ja',
  'ko': '/ko',
  'zh': '/zh'
};
const langPrefix = languageUrlMap[currentLang] || '';

// For detecting language from URL
const knownPrefixes = Object.values(languageUrlMap).filter(prefix => prefix);
let detectedLanguage = 'en';
for (const [lang, prefix] of Object.entries(languageUrlMap)) {
  if (prefix && (path === prefix || path.startsWith(prefix + '/'))) {
    detectedLanguage = lang;
    break;
  }
}

Why this matters:

Migration notes

🎉 Working Solution: Cross-Language Linking

📋 Implementation Example

To enable cross-language linking for any documentation page, add the following frontmatter to both language versions:

English File (apps/docs-angular/src/assets/docs/english/public/documentation/example-page.md):

---
title: Example Page
description: This is an example page
layout: guide
crossLanguageId: example-page
languageVersions:
  en: documentation/example-page
  es: documentacion/pagina-ejemplo
---

Spanish File (apps/docs-angular/src/assets/docs/spanish/public/documentacion/pagina-ejemplo.es.md):

---
title: Página de Ejemplo
description: Esta es una página de ejemplo
layout: guide
crossLanguageId: example-page
languageVersions:
  en: documentation/example-page
  es: documentacion/pagina-ejemplo
---

🔧 Key Requirements

  1. Identical crossLanguageId: Both files must have the same identifier
  2. Complete languageVersions: Map all supported languages to their paths
  3. No Language Prefixes: Paths should not include /es/ - the system adds this automatically
  4. File Extensions: Spanish files use .es.md extension

✅ Verification

When working correctly, you should see these logs during language switching:

📄 Available frontmatter keys: (5) ['title', 'description', 'layout', 'crossLanguageId', 'languageVersions']
🎯 Frontmatter suggests target path: "documentation/example-page" → "/documentation/example-page"
🧪 Page existence test for "documentation/example-page" (en): ✅ EXISTS
✅ Found frontmatter-based equivalent: "documentacion/pagina-ejemplo" → "/documentation/example-page"

Troubleshooting

Language Display Issues

Content Loading Issues

Performance Improvements

See also