Blog

The whole site in five languages in 12 minutes, from the command line

This website is written in English. The German, French, Croatian, Spanish and Arabic versions, 54 pages of documentation included, were translated by SwiftLing Pro from the command line, with OpenAI and my own key. Here is what I ran, how long it took and what I still did by hand.

The setup

SwiftLing and SwiftLing Pro are active, the five languages are added on the Languages screen, and an OpenAI key is saved on the Translation service screen. I chose OpenAI as the service that translates and gpt-6-sol as the model. I first translated the home page with DeepL and then the whole site with it, but I found the OpenAI translation better, so I replaced it.

The command

wp swiftling translate --all --kind=post --lang=de --again=machine --user=admin

--all takes every page of a kind, --lang is the language (here German), and --again=machine translates again the texts that a machine translated before, which is how the DeepL pass was replaced. Without --again the command fills only the texts that have no translation yet. Each page is opened on the server first, so SwiftLing sees the texts a visitor sees, and then its texts go to the service.

What I actually ran was this command with a list of pages instead of --all, because I left out the two legal pages on purpose: a legal text should not be translated by a machine without someone checking it. I ran it for all five languages at once, one process per language, so the wall time is the time of the slowest one.

The numbers

Languages5 (German, French, Croatian, Spanish, Arabic)
Pages54, plus the categories
Texts5,870
Characters sent622,050
Modelgpt-6-sol
Total time12 min 33 s
Fastest language (French)9 min 47 s
Slowest language (Croatian)12 min 33 s

I did not translate the languages one after another. I started five processes at once, one for each language, and they ran side by side. So the total time is the time of the slowest one, Croatian. One after another, the five would have taken about 55 minutes (the five times added up). A test of one page into two languages sent 3,810 characters and took 25 seconds, and I used that to plan the run.

What it cost

OpenAI bills tokens, not characters. Its usage page shows $4.67 for that day in total: 437 requests and 353,000 input tokens. That figure is everything I did with the key that day, not only this run. It includes my earlier tests on a more expensive model, gpt-6-astra, so the whole-site run on gpt-6-sol cost less than $4.67. I did not separate the two, and I estimate the whole-site run itself at about $3. SwiftLing’s own counter showed far less, because it lost some of its counts when five processes wrote to it at once.

What I did by hand

  • I chose the service and the model on the Translation service screen.
  • Two kinds of text were not words, so SwiftLing left them alone or I told it to keep the original: addresses of images and a code sample.
  • Arabic is shown right to left, which needs WordPress’s own Arabic language pack.
  • The home page, and the header and footer, were translated earlier with DeepL and have not been redone.

What went wrong, and what this does not mean

  • Running five languages at once exposed two faults in SwiftLing: one search index row was written twice, and the usage counter lost counts. Running the languages one after another does not trigger either. They were bugs in the plugin, and I have fixed both: the index row is now replaced instead of inserted, and the counter is written so that no process can overwrite another’s counts.
  • These are machine translations. Nobody has read them yet, and SwiftLing marks them as such so someone can review them in the editor. I cannot read Arabic, so a native speaker should.
  • The legal pages are not translated, on purpose.
  • Texts that a script builds after the page loads are not found by a command, because the command opens the page without running scripts.

If you want to try it, the commands are in the WP-CLI documentation. If you find something that goes wrong, tell me on GitHub.