> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/on-premises/zh-cn/pei-zhi/overleaf-toolkit/localization.md).

# 本地化

### Overleaf i18 配置

{% hint style="info" %}
本文档介绍如何为自托管的 **Overleaf** 实例配置国际化（i18n）。
{% endhint %}

Overleaf 已被翻译成多种语言。通过适当配置，你可以：

* 以 **单一固定语言**运行你的 Overleaf 实例，或
* 启用 **多语言**，允许用户动态切换语言，类似于 `www.overleaf.com`.

***

#### 单语言配置

站点语言通过环境变量配置 `OVERLEAF_SITE_LANGUAGE`（或 `SHARELATEX_SITE_LANGUAGE` ，适用于 Overleaf 版本 **4.x 及更早版本**).

支持的语言代码包括：

* `en` - 英语（默认）
* `es` - 西班牙语
* `pt` - 葡萄牙语
* `de` - 德语
* `fr` - 法语
* `cs` - 捷克语
* `nl` - 荷兰语
* `sv` - 瑞典语
* `it` - 意大利语
* `tr` - 土耳其语
* `zh-CN` - 中文（简体）
* `no` - 挪威语
* `da` - 丹麦语
* `ru` - 俄语
* `ko` - 韩语
* `ja` - 日语
* `pl` - 波兰语
* `fi` - 芬兰语

英语是默认语言。要更改界面语言（例如改为简体中文），请将以下行添加到 `config/variables.env`:

{% code title="config/variables.env" %}

```bash
OVERLEAF_SITE_LANGUAGE=zh-CN
```

{% endcode %}

然后应用配置：

```bash
bin/up
```

服务重启后，Web UI 菜单中的界面语言应会反映新的设置。

#### 多语言配置

要允许用户 **无需退出登录即可切换语言**，你的 Overleaf 实例必须配置为根据域名提供不同语言。

本节假定：

* 你的主域名是 `overleaftest.com`
* 你拥有 **通配符 TLS 证书** （例如 `*.overleaftest.com`)
* 你 **没有使用 `localhost`** （因为它不支持基于子域的语言路由）

用于本地测试时，你可以使用如下域名： `dev-overleaf.com`.

{% stepper %}
{% step %}

### TLS 代理配置（Nginx）

你的 TLS 反向代理必须转发原始的 `Host` 请求头，以便 Overleaf 能确定用户访问的是哪个语言域名。

请确保包含以下指令：

```nginx
proxy_set_header Host $host;
```

下面是一个 Nginx 配置示例：

<pre class="language-nginx"><code class="lang-nginx">server {
    listen 443 ssl;
    server_name    _; # 全部匹配，参见 http://nginx.org/en/docs/http/server_names.html
    server_name *.overleaftest.com;
    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;
    ssl_protocols               TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers   on;
    # 使用 Cloudflare 的加密套件 https://github.com/cloudflare/sslconfig/blob/master/conf
    ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;

    # 配置以启用 HSTS（HTTP 严格传输安全）https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
    # 以避免 SSL 剥离 https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping	
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
    server_tokens off;
    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;
    client_max_body_size 50M;

    location / {
        proxy_pass http://localhost:5000; # 更改为 Docker 容器正在监听的主机/端口。
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_read_timeout 3m;
        proxy_send_timeout 3m;
        
        # 将此添加到你的 nginx 配置中
<strong>        proxy_set_header Host $host;
</strong>    }
}
</code></pre>

{% endstep %}

{% step %}

### 配置 Cookie 域

为防止用户在切换语言时被登出，Cookie 必须在各语言子域之间共享。

将以下行添加到 `config/variables.env`:

{% code title="config/variables.env" %}

```env
# 注意前导点
COOKIE_DOMAIN=.overleaftest.com
```

{% endcode %}

这可确保认证 Cookie 对 `overleaftest.com`.
{% endstep %}

{% step %}

### 语言—域名映射

接下来，使用\
`OVERLEAF_LANG_DOMAIN_MAPPING`.

#### 示例配置

{% code title="config/variables.env" overflow="wrap" %}

```dotenv
OVERLEAF_LANG_DOMAIN_MAPPING='{"www": {"lngCode": "en","url": "https:\/\/www.overleaftest.com"},"cn": {"lngCode": "zh-CN","url": "https:\/\/cn.overleaftest.com"}}'
```

{% endcode %}

使用此配置：

* `https://www.overleaftest.com` → 英语界面
* `https://cn.overleaftest.com` → 简体中文界面

你可以根据需要使用更多语言和子域扩展此映射。
{% endstep %}

{% step %}

### 重定向 Apex 域名

最后，将 apex 域名（`overleaftest.com`）重定向到默认语言域名（`www.overleaftest.com`).

<pre class="language-nginx"><code class="lang-nginx">server{
    listen 80;
    server_name overleaftest.com;
<strong>    return 301 https://www.overleaftest.com$request_uri;
</strong>}

server {
    listen 443 ssl http2;
    server_name overleaftest.com;
    ssl_certificate     /path/to/fullchain.cer;
    ssl_certificate_key /path/to/overleaftest.com.key;
<strong>    return 301 https://www.overleaftest.com$request_uri;
</strong>}
</code></pre>

{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/on-premises/zh-cn/pei-zhi/overleaf-toolkit/localization.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
