# 配置

```javascript
{
    lang: 'en',
    locales: {
        en: {
            string: {
                required: 'required',
            },
        },
    },
    chains: {
        string: {
            name: 'string',
            transform: value => String(value)
        },
    },
    context: {},
    translate: (string, locale) => 'hello',
}
```

#### lang

语言环境。默认为 `en`，目前支持 `en` 和 `zh-cn`

#### locales

自定义语言。

#### chains

验证链配置。每一个验证都是一个验证链，有时候，验证链本身也有一些行为，可以在这里定义。目前支持 `transform` 来提供默认的数据转换功能

上面的代码片段中，string 表示给 `string` 类型定义默认参数

#### context

上下文。一些情况下，可能需要在验证规则中获取应用的实例，比如 egg 中，我们很多数据库查询可能写在 service 中，而 service 又依赖于 ctx，ctx 极难获取，如果能够在应用启动时传递，将可以省下很大的麻烦。

在自定义验证中获取 `context`

```javascript
acr.type('string')
    .define('rule', (value, { context }) => {
        // ...
    });
```

#### translate

翻译。acr 只提供了少量的国际化支持，这个接口是用于自定义配置。一般我们都会在验证规则时自定义提示，因为通用的在某些场景下总会感觉很奇怪。

两个参数分别是 `string` 要翻译的字符串 和 `lang` 语言


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://seek.gitbook.io/acr/config.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
