> ## 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
```

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

#### 多語言設定

若要讓使用者**在不登出的情況下切換語言**，你的 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.