Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the exclamation marks in Rails i18N translation yml file mean?

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

like image 780
Zack Xu Avatar asked Jul 06 '12 15:07

Zack Xu


People also ask

What does exclamation mark mean in Yaml?

I'm not an expert, but I see from the YAML spec that you can use an exclamation mark to indicate a custom object/type, and two exclamation marks to indicate an explicit built-in type.

What is I18n in Rails?

The Ruby I18n (shorthand for internationalization) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for translating your application to a single custom language other than English or for providing multi-language support in your application.


2 Answers

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

like image 158
kuboon Avatar answered Sep 28 '22 00:09

kuboon


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

like image 33
DreadPirateShawn Avatar answered Sep 28 '22 01:09

DreadPirateShawn