1

I'm working on a translation project and I'm moving all of the English strings out of the views and into a YAML file. Some of the very well written strings employ special characters such as ampersands and N-dashes.

Is there any way to include those?

In the meantime I've turned "&" to "and" and "–" to "--" but, at least in the English version, I feel like the copy starts to loose it's flavor. I doubt the Chinese version will miss these, but maybe they will want different special characters that I don't know about.

pixelfairy
  • 1,479
  • 1
  • 15
  • 29

1 Answers1

1

You can have special characters in YAML file values as long as they're not at the beginning of a string.

In the case of &, for example, if it is the first character of your string, then your YAML parser will think it's an anchor, when it tries to read the string (if it's not, like key: this & that, then it will be read as a string, as you would expect).

For more information about what you can and can't have in your YAML strings (and what are considered special characters), see:

Community
  • 1
  • 1
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
  • 1
    Thanks! I've been putting special characters as the first character of a string, but maybe I'm getting away with it because every string in my yml file is enclosed in "double quotes." (e.g. twitter_account: "@example") – pixelfairy May 14 '16 at 08:40
  • 1
    @pixelfairy yes, exactly right: if you use [double-quoted strings](http://yaml.org/YAML_for_ruby.html#double-quoted_strings), you'll be able to ensure that none of the characters in your string are interpreted as special characters. – Paul Fioravanti May 14 '16 at 10:15