Table of Content
Adding chinese
How about adding the Chinese supports?
- Create a new file named
zh-TW.yml
under the folderconfig/locales/
. -
Put the following content into the file.
zh-TW: nav: home: "首頁"
- Setting the default local to Chinese.
- Create a new file named
locale.rb
under theconfig/initializers/
folder. - Put the following ruby code in the file. I18n.default_locale = "zh-TW"
- Restart the server.
- Create a new file named
Note: “zh-TW” is for Traditional Chinese. And “zh-CN” is for Simplified Chinese.
Before moving advance, let’s complete the navigation locale:
And make sure we updated the view to use the locale setting. In the application.html.erb
file:
1<nav> 2 <ul> 3 <li><%= link_to t('nav.home'), root_path %></li> 4 <% if user_signed_in? %> 5 <li><%= link_to "#{t('nav.logout')} (#{current_user.email})", 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> 11</nav>
What’s next? We’re going to take a look at “Switching locale”.