Adding chinese

How about adding the Chinese supports?

  1. Create a new file named zh-TW.yml under the folder config/locales/.
  2. Put the following content into the file.

         home: "首頁"
  3. Setting the default local to Chinese.
    1. Create a new file named locale.rb under the config/initializers/ folder.
    2. Put the following ruby code in the file. I18n.default_locale = "zh-TW"
    3. Restart the server.

Note: “zh-TW” is for Traditional Chinese. And “zh-CN” is for Simplified Chinese.

Before moving advance, let’s complete the navigation locale:

2  nav:
3    home: "首頁"
4    login: "登入"
5    logout: "登出"
6    signup: "成為用戶"

And make sure we updated the view to use the locale setting. In the application.html.erb file:

 2  <ul>
 3    <li><%= link_to t('nav.home'), root_path %></li>
 4    <% if user_signed_in? %>
 5      <li><%= link_to "#{t('nav.logout')} (#{})", destroy_user_session_path, :method => :delete %></li>
 6    <% else %>
 7      <li><%= link_to t('nav.login'), new_user_session_path  %></li>
 8      <li><%= link_to t('nav.signup'), new_user_registration_path  %></li>
 9    <% end %>
10  </ul>

What’s next? We’re going to take a look at “Switching locale”.

overlaied image when clicked on thumbnail

Makzan | Ruby on rails 101 | Table of Content