![]() |
YAML Localization and Internationalization |
YAML (Wikipedia) is a human-readable text format that stores structured data. Many applications store their strings and settings in YAML files. Soluling Desktop and Soluling Cloud support YAML files (.yaml and .yml).
The end of the document contains links to get the full source code of the samples. After reading this document, we recommend reading a tutorial about how to use Soluling.
A YAML file contains keys and values. A value can be a string, a number, a boolean, a nested mapping of keys, or a list. Here is the Simple.yml sample file.
one: One two: Two sub: three: Three four: Four
Soluling localizes the string values. The keys are not localized. They are the IDs of the strings, and nested keys such as sub appear as items in the project tree. Soluling supports all the common YAML structures:
sub.three is a string inside a nested mapping.0, 1, and 2.{name: Martin, job: Developer} and ['Apple', 'Orange'].'text' and "text". A quoted value such as "true" is a string, not a boolean.| string keeps the line breaks, and a > string folds the lines into one line.If the root key of the file is a language code (e.g., en:), the file is a Ruby on Rails resource file, and Soluling uses the Rails parser by default.
By default, Soluling writes the localized file into a language subdirectory next to the original file. The Finnish file of Simple.yml is fi\Simple.yml.
--- one: Yksi two: Kaksi sub: three: Kolme four: Neljä
Soluling writes each translation in the style of the original value: a quoted string stays quoted, a | or > string stays a block string, and a flow style mapping or list stays on one line. Here is the original multi.yml sample and its Finnish file.
long: | First line Second line white: > First line Second line simple: Value
--- long: | Ensimmäinen rivi Toinen rivi white: > Ensimmäinen rivi Toinen rivi simple: Arvo
If a translation would be read as another data type, such as true or 1, Soluling quotes it so that it stays a string. Soluling also adds the --- document start, and it does not copy the comments of the original file.
By default, Soluling localizes only strings. A YAML file can also contain other kinds of data:
boolean1: true integer1: 1 float1: 1.2 data1: !!binary iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHe...
A !!binary value is base64 encoded binary data, such as an image. To localize booleans, numbers, or images, check them on the Data types sheet, or select the items that you want to localize on the Items sheet. The Datas.yml sample contains all these data types.
Simple.yml) onto Soluling or click the New from File or Files button and select the file.fi\Simple.yml.When you change the original YAML file, open the Soluling project and choose Home | Scan. Soluling keeps the existing translations, and you only translate the strings that were added or changed.
With Soluling Cloud, you localize the YAML file in your browser: upload the file, translate it in Translate, and download the localized files. You need a Soluling account. See the available Cloud plans.
Simple.yml), or drag and drop the file onto the page. Click Create.Click the project's green Translate button on the dashboard. Translate opens the project, and you can type the translations into the grid. Machine translation suggestions, translation memory, and spell checking are available there. You do not have to finish every language before moving on to the next step.
fi\Simple.yml.When you change the strings, upload the new original file, translate what is new or changed, and download the localized files again. On the dashboard, click the project's Update file button (the upload arrow), select the new file or drop it onto the page, and click Update. Existing translations are kept, so you only translate the strings that were added or changed.
The dashboard is one of four ways to use Soluling Cloud. You can also use the SoluCLI command-line tool, Soluling Desktop, or SoluMake, which can run the update and build steps in your build pipeline. See the Cloud tutorial for all of them.
GitHub and <data-dir>\Samples\YAML contain the following samples. Each .ntp file is a Soluling project that localizes the YAML file into Finnish. The localized files are in the fi subdirectory after you build the project.
| File | Description | Notes |
|---|---|---|
| Simple.yml Simple.ntp |
A simple YAML file with strings and nested keys. The same file as the sample used above. | Try this first! |
| multi.yml multi.ntp |
Multi-line strings in | and > styles. |
|
| List.yml List.ntp |
A list of strings. | |
| fold.yml fold.ntp |
A mapping and a list in flow style, written on one line. | |
| Datas.yml Datas.ntp |
All YAML data types: plain, quoted, and multi-line strings, booleans, integers, floats, and base64 encoded images (!!binary). The project localizes all of them. |
|
| Sport\Sport.yml Sport\Sport.ntp |
Text and numbers about sports. The project localizes the text into Finnish, German, and Japanese. |
You create a YAML localization project by adding a YAML file (e.g., D:\Sample\Simple.yml) into your Soluling project. You can configure how to localize your YAML file
by selecting the item in the project tree, right-clicking, and choosing the Options menu. A source dialog appears that lets you edit the options. This source uses the following option sheets.
Read more about other data files such as XML, XSL, JSON, YAML, INI, Excel, SVG, TMX, XLIFF, text and binary files.