Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could/should I state colon (punctuation) in a YAML file?

I am using Ruby on Rails 3.1.0 and I would like to know how to correctly state colon (punctuation) in a YAML file. I tried to support that by adding the following code in my config/locales/defaults/en.yml file

en   # ':' is the HTML code for ':'   test_key_html: Test value: 

and in my view file I used

t('test_key_html') 

but it doesn't work (in the front end content is displayed the "plain" Test value: text).

Is it possible? If so how?

like image 344
user12882 Avatar asked Jan 09 '12 03:01

user12882


People also ask

How do you write a colon in YAML?

A colon followed by a space (or newline) ": " is an indicator for a mapping. A space followed by the pound sign " #" starts a comment. …and then the colon will be preserved. The list of allowed escapes can be found in the YAML Specification under “Escape Sequences” (YAML 1.1) or “Escape Characters” (YAML 1.2).


1 Answers

You should be able to double quote the value:

test_key_html: "Test value:" 

This avoids colon-confusion in the YAML and gets your colon into your HTML.

Consider this in irb:

>> { 'en' => { 'test_key_html' => 'Test value:' } }.to_yaml => "--- \nen: \n  test_key_html: "Test value:"\n" 
like image 179
mu is too short Avatar answered Oct 12 '22 14:10

mu is too short