備忘録的にメモ。
locales/
+ ja.yml
+ en.yml
source/
+ localizable/
+ index.html.erb
locales/ja.yml
ja:
title: 'これはテストです'
contents:
p: 'ほげ'
array:
- 'アイテム その1'
- 'アイテム その2'
- 'アイテム その3'
images:
- src: 'image_a.png'
alt: '代替テキスト'
- src: 'image_b.png'
alt: '代替テキスト'
- src: 'image_c.png'
alt: '代替テキスト'
locales/en.yml
en:
title: 'This is the test'
contents:
p: 'hoge'
array:
- 'item no.1'
- 'item no.2'
- 'item no.3'
images:
- src: 'image_a.png'
alt: 'alternative'
- src: 'image_b.png'
alt: 'alternative'
- src: 'image_c.png'
alt: 'alternative'
source/localizable/index.html.erb
<!-- 通常 -->
<h2><%= t(:title) %></h2>
<!-- ハッシュ -->
<p><%= t('contents.p') %></p>
<!-- 配列 -->
<ul>
<% t('array').each do |item| %>
<li><%= item %></li>
<% end %>
</ul>
<!-- 配列とハッシュ -->
<ul>
<% t('images').each do |image| %>
<li><%= image_tag image[:src], :alt => image[:alt] %></li>
<% end %>
</ul>