Skip to content

Instantly share code, notes, and snippets.

@bater
Last active September 23, 2016 06:06
Show Gist options
  • Save bater/11851332ef7077424c08383efb25e978 to your computer and use it in GitHub Desktop.
Save bater/11851332ef7077424c08383efb25e978 to your computer and use it in GitHub Desktop.
i18n 搭配model與form的做法

i18n 搭配model與form的做法

在使用simple_form時,很多人會使用label來命名model的中文,其實可以透過設定model的多語系yml來實作解決這樣的需求。同時,model name本身也可以透過activerecord來設定語系。

一般的做法如下: <p><%= t(:website) %></p> 搭配語系檔的寫法:

'zh-TW':
  website: "網站"
zh-TW:
  activerecord:
    attributes:
      website:
        title: "標題"
        description: "網站描述"
en:
  activerecord:
    models:
      user:
        one: Dude
        other: Dudes

Resources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment