1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

messages.properties内のメッセージをIntelliJ IDEAに分かってもらう

Last updated at Posted at 2016-08-29

IntelliJ IDEAはとても賢いので特に何もしなくても

  1. メッセージコードを使っている文字列リテラル -> springのmessages.propertiesの定義箇所へジャンプ
  2. messages.properties -> メッセージの使用箇所を一覧(find usage : Option + F7)
  3. メッセージへの参照がある場合は色分け

をしてくれます。

idea_1.png
メッセージ定義にジャンプできる(プレビューも)

idea_2.png
メッセージへの参照がある場合はでオレンジ色になる

が、Bean Validationのエラーメッセージみたいにメッセージコードを{, }で囲んでいると

idea_4.png

Cmd + カーソルを合わせてもプレビューできなかったり

idea_5.png

参照されていない扱いになったりして、

  • メッセージ内容を知るまでの操作手順が増える
  • (未参照扱いになるので)うっかりメッセージ定義を削除してしまう可能性が高まる
  • メッセージ定義を整理する際の障害になる

などのデメリットが増えます。

idea_6.png

ですが、こうすることによりメッセージがプレビューできたり

idea_6.png

参照扱いにできて、find usageでも検索できるようになって少し便利になります。

おまけ

2016/08 時点で解決できないタイプのメッセージ

thymeleafのテンプレート
<script type="text/javascript" th:inline="javascript">
  var message = /*[[ #{my_message} ]]*/ 'ダミーのメッセージ';
</script>

javascriptで使うメッセージ

messages.properties
typeMismatch.com.example.MyType=独自の型を変換できなかった時のメッセージ

typeMismatch.* なメッセージ

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?