We quietly launched an English version of our blog, Yuruilog, not long ago. This post covers what went on behind the scenes, especially how we solved the question of whether multilingual support on an SSR site causes translation API costs to spiral.
Background: We Use EmDash as Our CMS
This blog runs on EmDash, an Astro-based CMS. Articles are written in the admin panel, and the front end is server-side rendered (SSR) with Astro.
It feels similar to WordPress in how intuitive it is to use, and it is said to be the spiritual successor to WordPress.
EmDash has a built-in multilingual content system. Posts, pages, menus, and taxonomies (categories and tags) can be stored as separate records for each locale. Simply link an English article to its source Japanese article using the translationOf field, and EmDash treats it as another language version of the same content.
We Migrated from microCMS to EmDash + Cloudflare
When it comes to multilingual sites, SSG makes things easy.
Generally speaking, automating multilingual translation through an API is straightforward with SSG (static site generation).
- Call the translation API only once, at build time
- Cache the results as static files
- After that, all that's left is to serve the HTML
As a result, no matter how many articles you have, API costs are only incurred on each build. Frequency is easy to control, and caching is straightforward.
But YuruLog uses SSR. So does that mean calling the API on every single request?
This is the problem. By design, EmDash's CMS pages are all rendered with SSR (output: "server"). Rather than building pages through a static build process, the system fetches the latest content from the CMS's API and database and renders it on every incoming request.
So what would happen if we implemented the straightforward approach: when an English page is requested, have Gemini translate the content on the spot and serve it?
- Translation API charges would be incurred on every request
- Latency would increase, since the response would have to wait for the LLM
- The same article might return slightly different translations each time (no reproducibility)
This is a complete non-starter. Simply choosing SSR and calling the API on every request would break both cost and UX.
Solution: Move translation from "request time" to "content creation time"
The answer is simple: do not perform translation at request time.
Specifically, we built the pipeline as follows.
- Write and publish Japanese articles in the EmDash admin panel
- Run the translation script (
scripts/translate.mjs) just once- Fetch the Japanese article's Portable Text (structured rich text) from the EmDash API
- Extract only the text portions that need translation and send them to the Gemini API (
gemini-3.6-flash) - Pass through blocks such as images and Amazon product cards without translation
- Save the translated result to the EmDash database as a new English article
- Specify the original Japanese article ID in
translationOfto link it as the English version within the same article group - It is saved as a draft, so it can be reviewed before publishing
- Specify the original Japanese article ID in
In other words, the translation is not something generated on the fly, but is treated as separate language content stored in the CMS.
This way, the SSR request handling itself is no different from normal article display. The English content already stored in the database is simply retrieved using EmDash's standard locale-aware query (getEmDashEntry(..., { locale: "en" })). Communication with the Gemini API happens only once, when the article is translated, and never occurs during page viewing.
In other words, the setup looks like this
When translation runs | API cost per request | |
|---|---|---|
SSG + on-demand translation | At build time | Zero (static file delivery) |
SSR + on-demand translation (bad example) | Per request | Occurs per article × number of accesses 😱 |
SSR + pre-translated content saved in the DB (the approach used this time) | At content creation (once) | Zero |
The insight this time was that if we bring SSG's idea of "batching and caching at build time" into the SSR world, the equivalent is to "persist the translated content in the DB." Even with SSR, the content itself doesn't have to be regenerated dynamically every time. By handling only the heavy translation work in advance, delivery itself becomes as lightweight as a regular CMS page.
The time I kept saying "Wait, where did it go?!" because the local and production databases were different
This implementation was honestly the most draining part. EmDash has separate databases for the local development environment and the production environment. It's obvious when you think about it, but this caused me to repeatedly experience "The feature was there a moment ago, and now it's gone!"
Here's what the symptoms usually looked like
- The nav in the header suddenly went empty
- The footer's Categories list disappeared
- The sidebar widgets on article pages disappeared
- The local menu items and widgets I had carefully set up had reverted to their original state
All of this happened right after things had been working fine, so at first I suspected that I had broken something and went looking for the cause with that in mind.
Cause 1: The process that pulls the production DB into local (pull.sh)
During development, I ran a script several times to pull the entire production DB into my local environment, because I wanted to see the latest production data locally as well. Doing this completely overwrites the local DB with the production state, meaning English articles that were still drafts or menu structures from before the publishing work was finished.
As a result, when I tried to check features that were not yet published on production locally, the moment I ran the pull, the local environment reverted to match production. Work I had already advanced locally temporarily disappeared from view.
Cause 2: The seed process that runs each time you log back into the local admin
The other cause was that the development bypass login I used to get back into the local admin also re-read seed.json (the initial data definition file) every time it ran.
The tricky part is that
- Menu items and widgets are overwritten to match the seed side exactly (so anything added manually locally gets wiped out).
- Taxonomies such as categories and tags are skipped if they already exist, so they are not deleted.
In other words, the behavior varied depending on the item. As a result, it looked puzzling: categories remained, but only menus and widgets kept getting wiped out every time.
Workaround I applied
Eliminating this dual overwrite structure (overwrites from pull and overwrites from seeding) was difficult, so as a practical compromise,
- I emptied all of the demo dummy content (menu items, widgets, categories, etc.) in
seed.json - and recreated the necessary menus and widgets via the API each time I re-entered the local environment.
This was a mitigation rather than a root-cause fix, but it at least prevents accidental overwrites from unintended demo data.
Summary
- EmDash is a multilingual CMS that natively supports storing content per locale.
- With SSG, you can get by with "translate at build time and cache", but with SSR, "translating on every request" turns into a billing nightmare.
- The solution is to run translation only once, at content creation time, rather than at request time, and save the results to the DB as regular CMS content.
- The translation engine I used was the Gemini API (
gemini-3.6-flash). - That said, when making a CMS multilingual, tidying up the translation flow isn't the end of it. Don't forget that having separate databases for local and production itself creates new pitfalls.
- In particular, development that works on things locally before they exist in production is easily thrown off by the side effects of environment sync mechanisms such as pull, seeding, and caching.
The lesson from this project: if you plan these two timing decisions in advance, namely when to translate and when and what the environment sync overwrites, you can build multilingual support with SSR without being thrown off by operating costs or incidents.
How about making your site multilingual too?
I work mainly on markup and frontend development using JavaScript, React, and Next.js. I'm always happy when a site I've been involved in launches successfully! My hobbies are playing the guitar. I love cats and roasted sweet potatoes 🐱🍠
Hirocchi
Frontend Engineer / Joined in 2022