ActiveAdmin國際化_ROR

來源:互聯網
上載者:User
ActiveAdmin漢化 第一步:局部漢化
ActiveAdmin.register AdminUser do  menu :label => "使用者管理"  index do    column "郵箱",:email    column "最近登入",:current_sign_in_at    column "上次登入",:last_sign_in_at    column "登入次數",:sign_in_count    default_actions  end  filter :email, :label=>"郵箱"  form do |f|    f.inputs "使用者資料" do      f.input :email ,:label=>"郵箱"      f.input :password ,:label=>"密碼"      f.input :password_confirmation ,:label=>"重複密碼"    end    f.actions  end  # 右側協助  sidebar :help,:only => :index do    "如果您在使用後台管理時遇到問題,請聯絡robot.zhu@icitymobile.com"  endend

按上述設定後,頁面部分內容將變成中文。

menu 功能表列文字
index column 列表中某列
filter label 篩選器標籤
form inputs 表單的標題
form input label 單個文本輸入框前的標籤

這個時候看,整個架構還是英文的。 第二步:架構漢化

匯入ActiveAdmin提供的語言檔案。根據需要選擇。簡體中文就選擇zh-CN.yml。
地址:https://github.com/activeadmin/activeadmin/tree/master/config/locales
中文:https://github.com/activeadmin/activeadmin/blob/master/config/locales/zh-CN.yml

將zh-CN.yml複製到自己的 config/locales/目錄下。 第三步:修改配置

修改config/application.rb檔案,添加下面兩行。

    config.i18n.available_locales = [:"zh-CN", :en]    config.i18n.default_locale = :"zh-CN"

重啟Rails Server。

整個架構就變成中文了。 Model國際化

實際上面這麼做之後,還有少量地方仍然是英文。
比如:導覽列上的模組名稱(Posts),右側的“建立Post”按鈕。

我們肯定希望“Posts”顯示為“博文”,“建立Post”顯示為“建立博文”。

這個時候需要在語言檔案zh-CN.yml裡加上models的國際化。

  activerecord:    models:      user: '使用者'      post: '博文'      organization: '機構'
Device國際化

下載漢化包 devise.zh-CN.yml ,並複製到自己的 config/locales/目錄下。
下載地址:https://github.com/plataformatec/devise/wiki/I18n 錯誤清單

錯誤資訊:

ActionView::Template::Error (translation missing: zh-CN.time.formats.long):    1: insert_tag renderer_for(:index)  app/admin/admin_user.rb:6:in `block (2 levels) in <top (required)>'

解決辦法

引入Rails的語言檔案。複製內容至zh-CN.yml檔案中。地址:https://github.com/tsechingho/rails-i18n/tree/master/rails/locale中文:https://github.com/tsechingho/rails-i18n/blob/master/rails/locale/zh-CN.yml

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.