> For the complete documentation index, see [llms.txt](https://overleaf-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://overleaf-pro.ayaka.space/on-premises/zh-tw/she-ding/overleaf-toolkit/localization.md).

# 在地化

### Overleaf i18n 設定

{% 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
```

服務重新啟動後，網頁 UI 選單中的介面語言應會反映新的設定。

#### 多語言設定

若要讓使用者 **在不登出的情況下切換語言**，您的 Overleaf 執行個體必須設定為依據網域名稱提供不同語言。

本節假設：

* 您的主要網域是 `overleaftest.com`
* 您擁有 **萬用 TLS 憑證** （例如 `*.overleaftest.com`)
* 您 **沒有使用 `localhost`** （因為它無法支援基於子網域的語言路由）

若要本機測試，您可以使用如下網域： `dev-overleaf.com`.

{% stepper %}
{% step %}

### TLS 代理伺服器設定（Nginx）

您的 TLS 反向代理必須轉送原始的 `Host` 標頭，讓 Overleaf 可以判斷使用者存取的是哪個語言網域。

請確認以下指令存在：&#x20;

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

以下是一個 Nginx 設定範例：&#x20;

<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 網域

最後，將頂級網域（`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     /<a data-footnote-ref href="#user-content-fn-1">p</a>ath/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 %}

[^1]:


---

# 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://overleaf-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.
