Using a period in YAML tokens

While working on an internationalized Rails application, I came across a case where the names of countries were being translated through the YAML locale configuration files. While a valid short-term measure, I would prefer using a gem like Globalize and storing the translations in a Country model, for example.

But in the meanwhile, I was asked to update some of the translations, and quickly discovered that you can’t use a period (a.k.a full-stop) in the token names. I tried surrounding them with quotes: "St. Lucia": St. Lucia, escaping them with a slash "St\. Lucia": St. Lucia, looking up the documentation, to no avail. I finally realized I could just break them into parent and child level tokens, like a period is meant to do:

period-in-yaml

Horrible, but works. If you use t("St. Lucia") in your code you get a valid result!

This entry was posted in Technology. Bookmark the permalink. Trackbacks are closed, but you can post a comment.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*

Time limit is exhausted. Please reload the CAPTCHA.