> 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-tw/she-ding/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 Strict Transport Security）的設定 https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
    # 為避免 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; # 改成 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 %}

### 將根網域重新導向

最後，將根網域（`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-tw/she-ding/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.
