> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 本地化

### Overleaf i18n 配置

<Info>
  本文档介绍如何为自托管的 **Overleaf** 实例配置国际化（i18n）。
</Info>

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

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

***

#### 单语言配置

站点语言通过环境变量 `OVERLEAF_SITE_LANGUAGE` 进行配置（对于 Overleaf **4.x 及更早版本**，使用 `SHARELATEX_SITE_LANGUAGE`）。

支持的语言代码包括：

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

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

```bash title="config/variables.env" theme={null}
OVERLEAF_SITE_LANGUAGE=zh-CN
```

然后应用配置：

```bash theme={null}
bin/up
```

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

#### 多语言配置

要让用户能够**在不退出登录的情况下切换语言**，你的 Overleaf 实例必须配置为根据域名提供不同的语言。

本节假设：

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

在本地测试时，你可以使用 `dev-overleaf.com` 之类的域名。

<Steps>
  <Step title="TLS 代理配置（Nginx）">
    你的 TLS 反向代理必须转发原始的 `Host` 请求头，以便 Overleaf 判断用户访问的是哪个语言域名。

    请确保存在以下指令：

    ```nginx theme={null}
    proxy_set_header Host $host;
    ```

    以下是一个 Nginx 配置示例：

    ```nginx theme={null}
    server {
        listen 443 ssl;
        server_name    _; # Catch all, see 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;
        # used cloudflares ciphers 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;

        # config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
        # to avoid ssl stripping 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; # change to whatever host/port the docker container is listening on.
            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;
            
            # add this to your nginx conf
            proxy_set_header Host $host;
        }
    }
    ```
  </Step>

  <Step title="配置 Cookie 域">
    为防止用户在切换语言时被登出，Cookie 必须在各个语言子域名之间共享。

    在 `config/variables.env` 中添加以下行：

    ```env title="config/variables.env" theme={null}
    # Note the leading dot
    COOKIE_DOMAIN=.overleaftest.com
    ```

    这可确保认证 Cookie 对 `overleaftest.com` 下的所有子域名都有效。
  </Step>

  <Step title="语言与域名映射">
    接下来，使用\
    `OVERLEAF_LANG_DOMAIN_MAPPING` 定义语言代码与子域名之间的映射关系。

    #### 配置示例

    ```dotenv title="config/variables.env" wrap theme={null}
    OVERLEAF_LANG_DOMAIN_MAPPING='{"www": {"lngCode": "en","url": "https:\/\/www.overleaftest.com"},"cn": {"lngCode": "zh-CN","url": "https:\/\/cn.overleaftest.com"}}'
    ```

    使用此配置后：

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

    你可以根据需要为此映射添加更多语言和子域名。
  </Step>

  <Step title="重定向顶级域名">
    最后，将顶级域名（`overleaftest.com`）重定向到默认语言域名（`www.overleaftest.com`）。

    ```nginx theme={null}
    server{
        listen 80;
        server_name overleaftest.com;
        return 301 https://www.overleaftest.com$request_uri;
    }

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.