This is another instance of using the LLM to produce translation of natural strings with an embedded DSL, similarly to the Documentation Translation guide.
MakeCode uses a microformat to define the shape of coding blocks.
When translating the format strings, it is critical to converse the properties of the blocks, such as the number of arguments,
their types, and the order of the arguments.
For example, the string for the Jacdac buzzer play tone block
contains reference to variables (%music) that should be maintained in the translated string.
and Bing Translate gives us the following translation
As one can see, bing translated the %variable name which will break the block definition.
If you look closely in the script source, you will find guidance in the prompt to properly
handle the variables.
Custom data format
Another challenge with translations is that the localized string often
contain escaped characters that break formats like JSON or YAML.
Therefore, we use a custom simple key=value format
to encode the strings, to avoid encoding issues.
We use the defFileMerge feature to convert the parse key-value file, and merge them with the existing translations.
Parameterization for Automation
The language code langCode is pulled from variablesenv.vars or defaulted to de.
This technique allows to reconfigure these variables from the command line
using the --vars lang=fr argument.
Script
The full script is show below.
The result from this script can be inspected
in this pull request.