Overview
Dev Showcase implements a client-side localization system using JSON files for English and Spanish translations. The system supports dynamic language switching without page reloads and persists user language preferences using cookies.Architecture Components
Language Files
JSON files containing all translatable content
Cookie Persistence
Stores user’s language preference
JavaScript Loader
Dynamically loads and applies translations
Language Files Structure
Translations are stored in JSON files located inwwwroot/languages/:
JSON Structure
Each language file contains hierarchically organized content:wwwroot/languages/en.json:1
Profile-Specific Content
The system supports different content based on the selected profile:wwwroot/languages/en.json:31
Content keys use the pattern
{key}_{profile} to load profile-specific translations dynamically.Language Switching Mechanism
Server-Side: SetLanguage Endpoint
TheHomeController provides an endpoint to persist language preferences:
Controllers/HomeController.cs:29
Cookie Configuration
Cookie expires after 1 year
Set to
true - cookie is required for site functionalityDefaults to Spanish if no language specified
Client-Side: JavaScript Implementation
The language switching is handled by JavaScript intranslation.js:
wwwroot/js/translation.js
How Language Loading Works
Visual Flow
Using Translations in HTML
To make content translatable, use thedata-i18n attribute:
Content Organization
The JSON files are organized into logical sections:Main Sections
typewriter
typewriter
Animated text for the typewriter effect on the homepage
header
header
Main header content and greeting
navigation
navigation
sidebar
sidebar
introduction
introduction
About me section with profile-specific content
skills
skills
Skills section labels, categories, and progress bars
projects
projects
Work experience and personal projects descriptions
education
education
Academic history and certificates
chartsData
chartsData
Numerical data for vocational charts (RIASEC, cognitive scores)
Adding a New Language
To add support for a new language (e.g., French):Content Keys Convention
Follow these naming conventions for consistency:| Pattern | Example | Usage |
|---|---|---|
section.key | navigation.skills | Simple property |
section.key_profile | introduction.aboutContent_webDev | Profile-specific |
section.subsection.key | skills.panels.webDev | Nested properties |
section.list[] | typewriter.phrases[0] | Array values |
Dynamic Content Loading
For content that changes based on user interaction:Benefits of This Approach
No Page Reload
Language changes happen instantly without refreshing the page
Easy Maintenance
All translations in JSON files - no need to rebuild or redeploy
SEO-Friendly URLs
URLs like
/en/dataScience are clear and indexableScalable
Adding new languages is straightforward - just add a JSON file
Best Practices
Keep Keys Consistent
Keep Keys Consistent
Use the same key structure across all language files. Missing keys will result in blank content.
Validate JSON
Validate JSON
Use a JSON validator to ensure files are properly formatted before deployment.
Use Fallbacks
Use Fallbacks
Implement fallback logic to show default language if translation is missing:
Version Control
Version Control
Track translation changes in git to see content evolution over time.
Troubleshooting
Content not updating
Content not updating
Issue: Changed JSON but content still shows old valuesSolution: Clear browser cache or do a hard refresh (Ctrl+F5)
Cookie not persisting
Cookie not persisting
Missing translations
Missing translations
Issue: Some elements show blank or keys instead of translated textSolution: Compare JSON files to find missing keys. Use a diff tool to identify discrepancies between language files.
JSON parse error
JSON parse error
Issue: Translations fail to loadSolution: Validate JSON syntax. Common issues:
- Missing commas
- Trailing commas (invalid in JSON)
- Unescaped quotes in strings
- Incorrect UTF-8 encoding
Performance Considerations
The language JSON files are loaded once per session and cached by the browser. However, consider these optimizations for larger applications:
- Lazy loading: Only load sections as needed
- Compression: Enable gzip compression for JSON files
- CDN: Serve language files from a CDN for global users
- LocalStorage: Cache translations in localStorage to reduce network requests
Next Steps
Routing
Learn how language codes are integrated into URL routing
Architecture Overview
Return to the architecture overview