How to I18n content which is dynamically loaded via javascript (assets)?

Suppose there is some content which is added dynamically by javascript because it provides javascript functionality only. As an example, I could imagine some buttons to sort a table with the help of js like in .

How to handle these expressions correctly? I guess the code should be moved to a place where embedded ruby is allowed, but I could not find an example.

we can use:

it converts the locale files to js. In JS you can do I18n.t(‘key’)…