Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 6 min read

What we learned localizing a Next.js AI image tool into German, French, Spanish and Portuguese

We are the small team behind Dreamixel, a free text-to-image generator that runs in the browser with no signup. It is our own product, so read this with that in mind. The stack is boring on purpose: Next.js, SQLite, and

We are the small team behind Dreamixel, a free text-to-image generator that runs in the browser with no signup. It is our own product, so read this with that in mind. The stack is boring on purpose: Next.js, SQLite, and Cloudflare in front.

We recently translated the home page and every tool page into German, French, Spanish and Portuguese. Most of the work was decisions, not strings. This post covers the routing, the hreflang setup, the sitemap, and the two things that surprised us most: page titles and accented text.

Routes: one prefix per locale, English slugs kept

Every localized page lives under a language prefix. The German logo tool is /de/ai-logo-generator, the French one is /fr/ai-logo-generator, and the English original stays at the root as /ai-logo-generator. The home pages are simply the prefix: our German version of the image generator and our French version are the same app with translated copy.

We kept the English slugs. A translated slug like /de/ki-logo-erstellen might help a little in search, but it means a slug map per language, redirects whenever someone renames a page, and a lot more ways to break hreflang. For a small team, one slug per tool across every locale was the right trade.

Path-based locales also play well with Cloudflare. The language is part of the URL, so the cache key is already correct. Choosing language by cookie or Accept-Language would mean varying the cache on that header, and sooner or later serving a German page to a Spanish visitor. We also do not auto-redirect by browser language. Crawlers mostly fetch without a language preference, and a redirect makes it hard for them to see the other versions at all. A visible language switcher is enough.

hreflang in generateMetadata

Each page has to list all of its siblings, including itself, plus an x-default. The links must point both ways: if the German page names the French one, the French page has to name the German one back. Next.js does this through alternates in the metadata API. Here is a simplified version of what our tool pages do:

// app/[lang]/[tool]/page.tsx (simplified)
import type { Metadata } from "next";

const BASE = "https://dreamixel.com";
const LOCALES = ["en", "de", "fr", "es", "pt"] as const;

const pathFor = (lang: string, slug: string) =>
  lang === "en" ? `/${slug}` : `/${lang}/${slug}`;

export async function generateMetadata(
  { params }: { params: Promise<{ lang: string; tool: string }> }
): Promise<Metadata> {
  const { lang, tool } = await params;
  const copy = await getToolCopy(lang, tool); // reads the locale JSON

  return {
    title: copy.title,
    description: copy.description,
    alternates: {
      canonical: `${BASE}${pathFor(lang, tool)}`,
      languages: {
        ...Object.fromEntries(
          LOCALES.map((l) => [l, `${BASE}${pathFor(l, tool)}`])
        ),
        "x-default": `${BASE}/${tool}`,
      },
    },
  };
}

Two rules we now follow strictly. The canonical of a localized page points to itself, never to the English page; pointing it at English tells search engines to ignore the translation. And every URL in the alternates list has to return a 200. An hreflang pointing at a 404 or a redirect is quietly dropped.

Titles: translate the search, not the words

This was the biggest lesson. A literal translation of an English title reads like a phrasebook. People do not search for the English concept in another language. They search for the thing they already call it.

Some examples from our own title list:

  • Coloring pages. In German nobody says "Malseiten". Parents search for Ausmalbilder, so the German title starts "Ausmalbilder erstellen mit KI". The French title says coloriage and adds Γ  imprimer (printable), because that is how French parents search. Spanish uses dibujos para colorear, Portuguese desenhos para colorir.
  • Stickers. In Brazil, the word people use for chat stickers is figurinhas. Our Portuguese sticker title keeps adesivos for the printed kind and adds "Figurinhas Fofas".
  • Flashcards. French teachers say imagier for a picture word book, so the French title leads with "CrΓ©ateur d'imagier" and keeps "flashcards" as a second keyword. German uses Lernkarten fΓΌr Kinder, Spanish tarjetas didΓ‘cticas with "(Flashcards)" in brackets.
  • Backgrounds. Our English "background generator" makes calm scenes for video calls. In German the title became "Virtueller Hintergrund fΓΌr Zoom & Teams", because that is the actual intent.
  • Coat of arms. German gets Familienwappen and Portuguese BrasΓ£o de FamΓ­lia. Searchers want their family's crest, not heraldry as a topic.
  • "No signup." It is ohne Anmeldung in German, sans inscription in French, sin registro in Spanish and sem cadastro in Portuguese. A literal "sem registro" exists, but Brazilians say cadastro.

None of this comes from a dictionary. It comes from what the search box autocompletes and which words the pages already ranking use. If a title still sounds translated when you read it aloud, rewrite it. You can see where we ended up on the Spanish home page and the Portuguese home page.

Keep typed text out of the image model

Several of our tools put words on the image: the picture flashcard maker prints a word under the drawing, and the name art generator builds a poster around a name. Image models draw the impression of letters, not real spelling. In English that gives you "Tomtae" instead of "Tomato". In German, French, Spanish and Portuguese it is worse, because accented letters are rarer in training data and come out as smudges.

So typed text never goes into the prompt. The model makes the picture and leaves a calm area. Then we render the text ourselves as real text with a real font, exactly as typed. A German teacher gets MΓΌsli with a proper ΓΌ, a French one gets garΓ§on, a Spanish one piΓ±a, a Brazilian one maΓ§Γ£. The same path handles a greeting like "Eid Mubarak, liebe Familie AydΔ±n", with the dotless Δ±.

The details that bit us:

  1. Normalize to NFC. Some keyboards and copy-paste sources send "Γ£" as "a" plus a combining tilde. Measure that string without normalizing and your line-width math is off, and some fonts draw the tilde in the wrong place. Call text.normalize("NFC") before anything else.
  2. Check glyph coverage. A pretty display font may have no Γ§ or Δ±. Pick fonts with full Latin Extended coverage, or set a fallback for missing glyphs.
  3. Pick text color from the image. We measure the brightness under the text area and use dark text with a light halo on bright areas, and white text on dark ones.
  4. Be honest about scope. For now the text fields support Latin-script languages, Turkish letters included. We say that on the pages instead of letting someone find out.

A sitemap per locale

We list every localized URL in the sitemap, and every entry carries the same alternates as the page itself. Splitting the sitemap by locale makes Search Console much easier to read: you can see at a glance that one language is indexed and another is not. With Next.js, generateSitemaps gives you one file per id. A single entry looks like this:

// app/sitemap.ts, one entry for the French flashcard page
{
  url: "https://dreamixel.com/fr/flashcard-maker",
  lastModified: new Date(),
  alternates: {
    languages: {
      en: "https://dreamixel.com/flashcard-maker",
      de: "https://dreamixel.com/de/flashcard-maker",
      es: "https://dreamixel.com/es/flashcard-maker",
      pt: "https://dreamixel.com/pt/flashcard-maker",
    },
  },
}

Generate this from the same list of locales and slugs that builds the pages. When the sitemap and the routes come from two sources, they drift apart.

Pitfalls we hit

  • New pages without translations. When we added a batch of new tools, each one also needed entries in four locale files. A missing key fell back to English, so a German page showed an English title while its hreflang said German. The cheap fix is to make a missing key fail the build instead of falling back quietly. We wish we had done that from day one.
  • Inconsistent brand suffixes. Some of our Spanish titles end in "| Dreamixel" and others do not. It is harmless, but pick one rule and apply it everywhere.
  • Long titles. German and Portuguese run longer than English. Put the keyword first so it survives truncation in the results page.
  • Translating the UI but not the prompts. Example prompts and placeholder text need localizing too, or the page feels half done.

If you are about to do the same thing, our FAQ covers how the tools work from the user side, and the about page has a bit more on who we are. Questions about the setup are welcome in the comments.

You can try every tool, in any of the five languages, at Dreamixel.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.