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.

middleman : 多言語化(i18n)

Last updated at Posted at 2014-12-17

備忘録的にメモ。

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