Question

We are working with the simple backend for the new Rails 2.2 i18n system, and I wanted to know the proper syntax for setting the encoding in a yaml file.

On other words what is the yaml for this xml:

<?xml encoding="UTF-8" ?>
Was it helpful?

Solution

You can't define the encoding in YAML. But there's also no need to, since the encoding is done at the file level and is transparent to the YAML and its parsing. When writing a YAML document, this is all you need to remember.

On the file level, YAML 1.1 supports UTF-8 and UTF-16 but not UTF-32. The full details of the 1.1 specification is that

All characters [...] are Unicode code points. Each such code point is written as one or more octets depending on the character encoding used. Note that in UTF-16, characters above #xFFFF are written as four octets, using a surrogate pair. A YAML processor must support the UTF-16 and UTF-8 character encodings. If a character stream does not begin with a byte order mark (#FEFF), the character encoding shall be UTF-8. Otherwise it shall be either UTF-8, UTF-16 LE or UTF-16 BE as indicated by the byte order mark. On output, it is recommended that a byte order mark should only be emitted for UTF-16 character encodings. Note that the UTF-32 encoding is explicitly not supported.

For YAML 1.2, UTF-32 is supported as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top