This article discusses a custom i18n solution for Cloudflare Workers and Astro.js that avoids importing JSON files into the JavaScript bundle to prevent bloating the Worker script size. It uses Cloudflare KV for storing translation dictionaries as external data, ensuring decoupling between code deployment and content updates. The system employs the Cache API for edge caching to minimize KV read costs and latency issues. A key feature is splitting the concept of "Current Locale" into two variables: 'uiLocale' (user intent) and 'translationLocale' (available data), enabling graceful degradation when translations are unavailable. Additionally, it emphasizes namespace splitting in translation files to optimize HTML payload size and recommends using Astro Middleware for determining locale before rendering any components.
Read the full article at DEV Community
Want to create content about this topic? Use Nemati AI tools to generate articles, social posts, and more.





