Sunday, February 27, 2011

String interpolation in en.yml

suppose we need to create a copyright statement which shows current year dynamically.

in the language text file (en.yml), we expect a variable current_year:

en:
layout:
copyright_statement: "© 2010 - %{current_year} RU05. All rights reserved."
view raw en.yml hosted with ❤ by GitHub

in the layout view, we provide this current_year as hash:

<html>
...
<body>
...
<div id="footer">
<%= I18n.t("layout.copyright_statement", :current_year => Date.today.year) %>
</div>
...
</body>
</html>

No comments:

Post a Comment