LoginSignup
0
0

More than 3 years have passed since last update.

CSSの擬似要素(content)を多言語化する

Posted at

はじめに

Railsアプリのi18n(tメソッド)をJSでも使用できるようにしています。
CSSの擬似要素(content)を多言語化したかったのですが、style内でjavascriptは使えないのでどのように実装するか悩みました。

解決策

JQueryのappendで擬似要素を追加しました。

test.html
<div class="myclass">質問</div>
test.js
const required = I18n.t('helpers.required')
$('head').append(`<style>.myclass:before { content: "${required}" }</style>`);
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0