Search code examples
ruby-on-railsrails-i18n

How can I put CSS style in my I18n locale?


I have a following translation:

welcome: Hello there, %{general_kenobi}

Now I know, that I can put HTML tags in the translation, like <em> or so. But what if I want this general_kenobi to have my custom style? How do I implement it? I've tried to google it, but didn't find anythin useful (or maybe I'm just bad at googling). Thank in advance!


Solution

  • If you want to add something fancy like this to your locale you must add the _html extension to the key.

    From the docs

    Keys with a '_html' suffix and keys named 'html' are marked as HTML safe. When you use them in views the HTML will not be escaped.

    en:
      welcome_html: "<b>Bolded text</b>"
    

    then just the regular stuff in your views

    <%= t('welcome_html')