AWS Builder Center
i18n when the content is generated at runtime

i18n when the content is generated at runtime

Beyond static text, how Entiscore handled i18n for AI-generated findings, server errors, and Claude content across two languages.

Series: Building Entiscore with Kiro (8 articles)

  1. …
  2. 6
    i18n when the content is generated at runtime This article
Software Developer
The build error was specific: a module depending on  next/headers , a Server Components-only API, was being imported from a Client Component context. The error appeared only in production, not in local development, which meant it had been working by accident until the deployment caught it.
The module in question was the i18n system for Entiscore, a web entity audit agent built for the Kiro powered by AWS hackathon. The app needed to work completely in both Spanish and English because some of the hackathon evaluators were English speakers. Tracking down that build error opened up three separate layers of incomplete translation coverage that would have been invisible without running the full flow in both languages on every screen.

The build error and what caused it

The i18n system had a single entry point that re-exported everything from one barrel file: the server-side language reading functions that depend on  cookies()  from  next/headers , and the translation dictionaries that need to be importable from client components like the navbar language selector. Any client component importing the dictionaries was pulling in the server-only code indirectly, and the Next.js bundler flagged it correctly as a build error.
The fix separated the module into two explicit files. One file for anything safe to share between server and client, and another exclusively for the server-side cookie reading logic, with no barrel file merging the two again.
// client.ts
export const dictionaries = { es: {...}, en: {...} };
export function getTranslation(locale) { ... }
// server.ts
import { cookies } from "next/headers";
export async function getLocaleFromCookie() {
const cookieStore = await cookies();
return cookieStore.get("locale")?.value ?? "es";
}
No client component imports  server.ts  directly or indirectly after this separation. This pattern applies to any Next.js project that mixes server-only APIs with shared utilities in the same module.

Why the architecture skipped URL prefixes

The most common approach to i18n in Next.js with App Router is through dynamic route segments with paths like  /es/history  and  /en/history , resolved by a  [locale]  folder wrapping the entire page structure. That option was discarded because the project already had a significant number of routes built and working, and restructuring everything inside a new locale segment represented a high regression risk with limited development time available.
The alternative treats language as a session preference rather than part of the URL. A toggle in the navbar saves the chosen preference in localStorage on the client side and synchronizes it into a server-readable cookie. When the user has not chosen explicitly, the system defaults to the browser language. This dual persistence allows both client components and server-side rendering, including SEO metadata generation, to resolve the correct language without depending on a route parameter.

The three coverage gaps that only appeared in both languages

After fixing the build error, running the full flow in both languages on every screen revealed three separate problems that had nothing to do with the barrel file.
The first was that several institutional pages had been built before the i18n system existed. Their text was still a literal string in Spanish directly inside the component, with no reference to the dictionaries. Switching to English from the navbar left those specific pages fully in Spanish while the rest of the site switched correctly. This kind of gap doesn't surface with a single superficial test, it only appears when someone navigates specifically to those pages with English selected. An explicit page-by-page audit was the only way to find and fix all of them.
A subtler case appeared on the About page after its content was already connected to the dictionary. A section built from an array of dictionary key references disappeared entirely when switching languages in either direction, and didn't return until the page was manually refreshed. The cause was a structural mismatch between the Spanish and English dictionaries for that section: one entry didn't exist identically in both, and accessing a property on a non-existent object during render produced an error that was caught without recovery until a full page remount. Synchronizing the exact structure of both dictionaries resolved it.
The second gap was in the content generated dynamically by the four analyzers. Originally each analyzer built its finding descriptions as complete sentences already assembled in Spanish, directly inside the analysis logic. That had to be refactored so each finding was generated from a translation key plus variable data, the name of a missing field, an HTTP status code, the name of a detected platform, rather than a fixed sentence. The analysis endpoint received the requested language as part of the request body and used that value to resolve the final text of each finding. The first pass of this refactor was incomplete and a second review, pointing out specifically which cases were still returning in Spanish, finished the work across all four analyzers.
The third gap was in the URL comparison flow. After confirming that the individual analysis flow translated correctly, running the same verification on the comparison flow revealed that the comparison endpoint had never been updated to receive and propagate the requested language. The analyzers on the comparison side always generated their content in Spanish regardless of the active preference. The fix propagated the language through the comparison endpoint the same way as the individual analysis endpoint, and unified the presentation components between both flows instead of maintaining two separate implementations.

What static translation testing misses

Covering the static interface in two languages is relatively mechanical and easy to verify at a glance. Complete coverage only shows its gaps when content is built dynamically at runtime from variable data, whether by rule-based logic or by a language model receiving an explicit language instruction in each prompt. Every point where the system assembles text from data is a point where the language can end up hardcoded by accident.
Static text translation gets tested by looking at the screen once. Everything else only gets discovered incomplete by running the full flow, in each language, on each screen, and comparing what actually appears against what's assumed to appear.


Entiscore is available at  entiscore.vercel.app . Built with Next.js, TypeScript, Supabase and the Claude API for the Kiro powered by AWS hackathon by Codigo Facilito.

Series: Building Entiscore with Kiro (8 articles)

  1. …
  2. 6
    i18n when the content is generated at runtime This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article