Although the percent sign probably could be allowed a the start of plain scalars that are not starting at the beginning of a document (where they indicate a directive), not all parsers allow this. You can check that online by comparing the Nim
based parser with the PyYAML based one. The YAML specification explicitly disallows %
(which is a c-indicator) from appearing at the beginning of a plain scalar.
You would run into similar problems if your edit would introduce colons (followed by whitespace) or backslashes.
The simple solution is quoting that value:
example.translation: '%variable% example translation'
I use single quotes here, as within those only single quotes have special meaning (if your original has a single quote, make that two single quotes).
Quoting YAML scalars with double quotes is also possible, but then any backlashes (\
) and double quotes in the original must be preceded by a backslash (i.e. \\
and \"
)
You can also make such a plain scalar into a literal style block-scalar:
example.translation: |-
%variable% example translation
You'll have to use the -
chomping indicator, otherwise your scalar ends in a newline, where the original did not. Then you don't have to
do anything special for single or double quotes in your original, nor for any backslashes.