12

I'm using Rails i18n to localize my website.

In the translation yml file, I see

time:
    am: am
    formats:
      default: ! '%a, %d %b %Y %H:%M:%S %z'
      long: ! '%d %B, %Y %H:%M'
      short: ! '%d %b %H:%M'
    pm: pm

(taken from https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en-GB.yml)

What does the exclamation mark mean? How is it different if you take away the exclamation mark?

Thanks

Zack Xu
  • 11,505
  • 9
  • 70
  • 78
  • 2
    Did you _try_ removing them to see if you could notice any difference? What happened to the adventuring spirit? – TheZ Jul 06 '12 at 15:36
  • 3
    See http://stackoverflow.com/questions/9664113/what-does-a-single-exclamation-mark-do-in-yaml – Stefan Jul 06 '12 at 15:43
  • 1
    I've read the link posted by @Stefan but I'm still don't understand how this applies to Rails. – Andy Waite May 31 '13 at 09:07
  • 1
    See this answer : http://stackoverflow.com/questions/9664113/what-does-a-single-exclamation-mark-do-in-yaml – tigrish May 31 '13 at 09:26
  • @Stefan - If you're game to recap the solution as your own answer, I'll delete my answer. (See http://meta.stackexchange.com/questions/90263/unanswered-question-answered-in-comments for elaboration of why this is helpful.) Thanks! – DreadPirateShawn Oct 09 '13 at 16:25
  • @DreadPirateShawn I've marked it as a duplicate – Stefan Oct 09 '13 at 18:22

2 Answers2

9

% is a special character in YAML. Single exclamation mark avoids it to be parsed as a special character and passes it as a String.

kuboon
  • 9,557
  • 3
  • 42
  • 32
  • 2
    would it be equivalent to wrap the entire string in quotation marks instead of using the single exclamation mark in front? – Magne Feb 05 '15 at 22:10
2

Copying the answer from the comments in order to remove this question from the "Unanswered" filter:

See What does a single exclamation mark do in YAML?

~ link per Stefan, linked question answered by Juan Mellado

Community
  • 1
  • 1
DreadPirateShawn
  • 8,164
  • 4
  • 49
  • 71