Web application localization for multiple languages has traditionally depended on manually translated static files .json or slow and expensive external translation APIs. In Portelcore Web, we implemented a fully automated pipeline that combines DJB2 cryptographic hashing with local language model inference in Cloudflare Workers AI.
1. The Deterministic Translation Flow
The system divides the process into three execution stages:
[ HTML con Textos ] ---> [ Hash DJB2 de 64 bits ] ---> [ ¿Existe en KV? ] │ ┌────────────────────────────────────────┴───────────────────┐ ▼ SÍ ▼ NO [ Cache Hit: 0 ms ] [ Workers AI LLM ] [ Guarda en KV ] [ Entrega Traducción ]- Compile-Time / SSR Extraction: Texts are wrapped in the
<AITranslate>component or tagged in the HTML. - Unique Key Generation: A deterministic DJB2 hash of the Spanish string is computed (e.g.,
msg-1085732109). - Global Cache in KV: Before querying the AI model, the
PORTELCORE_KV_COREnamespace is inspected. If the key exists for the target language, the response is delivered in less than 5 ms.
2. Implementation of the DJB2 Algorithm
The speed of hash computation is essential to not penalize the server response time in Astro SSR:
/** * Calcula el hash DJB2 optimizado para cadenas de texto. * Produce un identificador numérico determinista e inmutable. */export function djb2Hash(str: string): string { let hash = 5381; for (let i = 0; i < str.length; i++) { hash = ((hash << 5) + hash) + str.charCodeAt(i); hash |= 0; // Conversión forzada a entero de 32 bits con signo } return Math.abs(hash).toString(36);}3. Inference with LLM Models in Workers AI
When a new key does not exist in the edge cache, the satellite Worker dispatches the request to the Workers AI runtime:
/** * Invoca el modelo Llama 3.3 en Workers AI con un prompt de sistema rígido. */export async function translateText(text, targetLanguage, env) { const systemPrompt = `Eres un traductor técnico profesional.Traduce el siguiente texto técnico exactamente al idioma '${targetLanguage}'.Conserva términos técnicos de programación (ej: WAF, Cloudflare, KV, SSR, TypeScript).Devuelve ÚNICAMENTE la traducción limpia sin explicaciones ni comillas.`;
const response = await env.AI.run("@cf/meta/llama-3.3-70b-instruct-fp8-fast", { messages: [ { role: "system", content: systemPrompt }, { role: "user", content: text } ], temperature: 0.1 });
return response.response.trim();}4. Conclusion
This design allows the platform to support 14 international languages without the need to maintain desynchronized manual dictionaries, maintaining a smooth, fast, and consistent experience worldwide.
[ Continue Exploring ]
Mitigation of L7 Attacks and WAF in Cloudflare Edge with V8 Isolates
V8 Isolates vs. Containers: Low-Latency Serverless Architecture
Knowledge Base · 200+ Manuals
Verified Linux, Windows Server, hybrid Cloud, networking and cybersecurity procedures.
Consultancy & Contact
Cloud architecture, DevSecOps audit, hybrid infrastructure or technical collaboration.


