---
title: "I18n的human_attribute_name方法"
author: "ZoOL"
date: "2010-07-16T18:26:42Z"
tags: []
categories: ["编程语言"]
slug: "i18n-human-attribute-name"
draft: false
lastmod: "2010-07-16T18:26:42Z"
id: 714681
url: "https://zool.iteye.com/blog/714681"
---

当使用I18n配置mode时， 可以用yml配置'zh-CN':

```
  activerecord:
    models:
      user: "用户"
    attributes:
      user:
        username: "用户名"
        email: "邮箱"
        password: "密码"
```

 

因此在form\_for里的

 

```
f.label :username
```

 

便会自动转化为 用户名

 

那在其他views要使用I18n呢？ 很简单， 使用  User.human\_attribute\_name(:username), 就可以获得  用户名