简体   繁体   English

如何在yaml文件中设置字符编码

[英]How to set the character encoding in a yaml file

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. 我们正在使用新的Rails 2.2 i18n系统的简单后端,我想知道在yaml文件中设置编码的正确语法。

On other words what is the yaml for this xml: 换句话说,这个xml的yaml是什么:

<?xml encoding="UTF-8" ?>

You can't define the encoding in YAML. 无法在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. 但是也没有必要 ,因为编码是在文件级别完成的,并且对YAML及其解析是透明的。 When writing a YAML document, this is all you need to remember. 在编写YAML文档时,您需要记住这一切。

On the file level, YAML 1.1 supports UTF-8 and UTF-16 but not UTF-32. 在文件级别,YAML 1.1支持UTF-8和UTF-16,但不支持UTF-32。 The full details of the 1.1 specification is that 1.1规范全部细节

All characters [...] are Unicode code points. 所有字符都是Unicode代码点。 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. 请注意,在UTF-16中,使用代理项对将#xFFFF以上的字符写为四个八位字节。 A YAML processor must support the UTF-16 and UTF-8 character encodings. YAML处理器必须支持UTF-16和UTF-8字符编码。 If a character stream does not begin with a byte order mark (#FEFF), the character encoding shall be UTF-8. 如果字符流不以字节顺序标记(#FEFF)开头,则字符编码应为UTF-8。 Otherwise it shall be either UTF-8, UTF-16 LE or UTF-16 BE as indicated by the byte order mark. 否则,它应为UTF-8,UTF-16 LE或UTF-16 BE,如字节顺序标记所示。 On output, it is recommended that a byte order mark should only be emitted for UTF-16 character encodings. 在输出时,建议只应为UTF-16字符编码发出字节顺序标记。 Note that the UTF-32 encoding is explicitly not supported. 请注意,明确不支持UTF-32编码。

For YAML 1.2, UTF-32 is supported as well. 对于YAML 1.2, 也支持UTF-32

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM