LoginSignup
3
2

More than 3 years have passed since last update.

【Rails】I18nの定義存在チェック

Posted at

指定したkeyがI18n定義済みか確認したい

I18n.exists?(#{key}) で確認できます。

config/locales/ja.yml
ja:
  users:
    index:
      title: ユーザ一覧
I18n.exists?('users.index.title')
=> true # 定義済みなので true

I18n.exists?('users.show.title')
=> false # そんな定義は無いので false
3
2
0

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
3
2