Coming soon: We’ll update our YAML dumper and larger changesets are expected
By Edouard on November 11, 2022
Executive Summary: We will update our YAML dumper (the library used to generate YAML). We are currently using a patched version of ya2yaml and we’re moving to Psych next Monday the 14th of November. Changes in your language files are expected. Here is an example of the differences between our current YAMLer and the new YAMLer.
Why are we updating our YAMLer?
Back in the 2000s and 2010s, YAML dumpers in Ruby used to handle foreign characters badly. Since we needed to generate YAML files in foreign languages, we had to use an alternative YAML dumper. At the time, ya2yaml was the only YAMLer for Ruby that handled foreign characters well.
Over the years, we patched heavily ya2yaml to fix its sometimes weird output. Today, as we’re investigating the performance of our file handlers, we noticed this library is unmaintained, slow and leaks memory. It’s time to move on. Nowadays, Psych, the default YAML dumper in Ruby, is good and handles foreign characters well.
Because Psych formats YAML differently than ya2yaml, changes in your YAML files are to be expected. These changes shouldn’t impact how these YAML files are parsed by your application. When we update our YAMLer on Monday the 14th of November, you will notice numerious changes when you download your YAML file and commit it to your repository.
Notorious changes for YAML files
Currently, strings are consistently wrapped with double quotes. Most of the strings won’t be wrapped by quotes with the new YAMLer, and when they will, they will be wrapped with single quotes.
Currently:
fr:
project_file_exports:
create:
failure: "Sorry, we couldn’t export your file."
Next Monday:
fr:
project_file_exports:
create:
failure: Sorry, we couldn’t export your file.
Nil values ~
won’t be displayed. Instead the key will have no value.
Currently:
en:
some_nil_value: ~
Next Monday:
en:
some_nil_value:
Arrays will use a different indentation.
Currently:
en:
list:
- "Item 1"
- "Item 2"
- "Item 3"
Next Monday:
en:
list:
- Item 1
- Item 2
- Item 3
A maximum line length will be enforced, and longer strings will be written on several lines.
Currently:
en:
translation: "We’re here to help. Get in touch and we’ll get back to you as soon as we can."
Next Monday:
en:
translation: We’re here to help. Get in touch and we’ll get back to you as soon
as we can.
Here is an example changeset of one of our own files: https://gist.github.com/edouard/3842afdd531bb462976c3cab0dd09d9e/revisions
Other changes for plural segments in PO files
ya2yaml is also used to serialize key names for plural strings in Gettext PO files. We will regenerate the key names for these projects using Psych.
If your key name currently look like this:
It will look like this:
This change shouldn’t affect anything on your project.