AI live translation
wuchale
can use LLMs to translate messages on-the-fly, during development or
during the CLI invokation. When coupled with the HMR support,
you can get a seamless experience where you edit the source code in one
language and see the updates in the browser in another language live.
Gemini
Section titled “Gemini”Gemini was chosen as the default particularly because it has free (limited) access to use it with an API key. You can get your own free API key from Google AI Studio. Once you have that, you can set it to the environment variable:
export GEMINI_API_KEY=your_api_key
And then you can use wuchale
as normal: start the dev server or use the CLI
command. It will pick up the untranslated messages and translate them using
Gemini.
To customize how Gemini is used, you can import it and customize it in the config:
import { gemini } from "wuchale";
export default { //... ai: gemini({ batchSize: 40, parallel: 5, think: true, // default: false }), //...};
Other LLMs
Section titled “Other LLMs”To use another LLM, you can create your own object that conforms to the AI config type.
export default { //... ai: { name: "ChatGPT", // e.g. batchSize: 50, parallel: 10, translate: (content, instruction) => { // logic return translatedContent; }, }, //...};
Mistake handling
Section titled “Mistake handling”If the LLM makes mistakes (which it often does) and doesn’t translate some of
the messages, or makes mistakes on the message keys etc, wuchale
collects the
untranslated messages and the messages whose keys (untranslated) were not
properly returned and gives it to the LLM again.
For example, let’s say we have this:
msgid "Hello!"msgstr ""
msgid "Welcome"msgstr ""
msgid "Welcome {0}!"msgstr ""
And the LLM returns this:
msgid "Hello"msgstr "Hola"
msgid "Welcom-"msgstr "Bienven-"
msgid "Welcome {0}!"msgstr ""
Then wuchale
retries for the following:
msgid "Welcome"msgstr ""
msgid "Welcome {0}!"msgstr ""
And if it still makes mistakes, the process continues until all messages are translated.
Usage limit optimization
Section titled “Usage limit optimization”wuchale
is designed to keep the number of requests as low as possible in
order not to exceed the limit. How:
Requests
Section titled “Requests”You can use the batchSize
and parallel
options to control how big and how
many the requests are. Reasonable defaults have been chosen for the default
Gemini, but you can customize them.
No re-translation
Section titled “No re-translation”Once a message is translated, it is stored in the catalog, just like a human
translated it. And wuchale
never makes another request to translate that same
message.