---
metadata:
  - name: generator
    content: Diplodoc Platform v5.66.0
alternate:
  - https://yandex.com/dev/games/doc/en/sdk/construct-3/text-localization.md
  - https://yandex.com/dev/games/doc/hi/sdk/construct-3/text-localization.md
  - https://yandex.com/dev/games/doc/ko/sdk/construct-3/text-localization.md
  - https://yandex.com/dev/games/doc/ru/sdk/construct-3/text-localization.md
  - https://yandex.com/dev/games/doc/tr/sdk/construct-3/text-localization.md
  - https://yandex.com/dev/games/doc/vi/sdk/construct-3/text-localization.md
  - https://yandex.com/dev/games/doc/zh/sdk/construct-3/text-localization.md
  - href: https://yandex.com/dev/games/doc/zh/sdk/construct-3/text-localization.md
    type: text/markdown
    title: Markdown version
  - href: https://yandex.com/dev/games/doc/zh/llms.txt?revision=r21993288
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/games/doc/zh/llms.txt?revision=r21993288

# 文本本地化

<!-- source: zh/_includes/script-common.md -->
<!-- source: zh/_includes/script/index-js.md -->

<!-- endsource: zh/_includes/script/index-js.md -->

<!-- source: zh/_includes/script/requirements-js.md -->

<!-- endsource: zh/_includes/script/requirements-js.md -->

<!-- source: zh/_includes/script/image-modal-js.md -->

<!-- endsource: zh/_includes/script/image-modal-js.md -->
<!-- endsource: zh/_includes/script-common.md -->

该插件的一项基础功能是文本自动翻译系统。

为此，请以 JSON 格式准备翻译，以便在项目中使用。 在大多数情况下，您无需添加新代码即可本地化游戏。

## 创建翻译文件 {#create-i18n-files}

要本地化游戏，请准备 JSON 翻译文件：

1. 在 `Files` 目录中创建文件夹 `i18n`。
1. 在创建的文件夹中创建 JSON 文件，并以 [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes){.external} 格式的语言代码命名。

![Construct 3 中的操作视频：屏幕左上方显示文件结构。 可以看到部分文件夹列表："Videos"、"Fronts"、"Icons"、"Files"。 用户选中"Files"文件夹，并在上下文菜单中选择"Add subfolder"选项。 在"Files"文件夹中出现一个新文件夹，用户将其命名为"i18n"。 然后他选中新文件夹"i18n"，在上下文菜单中选择"New"→"JSON"，并将其命名为"en.json"。 接着，在同一个"i18n"文件夹中，他创建文件"ru.json"。](../../_images/construct-3/text-localization/create-i18n-files.gif)

举例来说，我们创建`en.json`和`ru.json`文件，内容如下：

{% list tabs %}

- `en.json`

    ```json showLineNumbers
    {
        "game": {
            "title": "First Fantasy 10"
        },
        "potions": {
            "health": "Health Potion",
            "mana": "Mana Potion"
        }
    }
    ```

- `ru.json`

    ```json showLineNumbers
    {
        "game": {
            "title": "Первая Фантазия 10"
        },
        "potions": {
            "health": "Зелье жизни",
            "mana": "Зелье маны"
        }
    }
    ```

{% endlist %}

这样，我们为英语和俄语创建了翻译。现在我们可以在项目中使用它们。

## 在布局中使用 {#use-in-layouts}

接下来，为了使用我们的翻译，让我们在布局中创建文本对象，并将其值设置为`{game.title}`。

![Construct 3 截图：灰色背景上选中了一个文本对象，它看起来像黑色文字"{game.title}"。 旁边打开了一个弹出窗口，其顶部面板中央写着"Text"。 弹出窗口的大部分区域是文本框，其左上方写着"{game.title}"。 窗口右下方有"OK"和"Cancel"按钮，指针悬停在"OK"按钮上。](../../_images/construct-3/text-localization/example.webp)

要测试翻译，请点击 **Play** 按钮（预览）。 在 **Preview** 窗口中，文本将变为"First Fantasy 10"。 这是因为自动本地化系统可以替换 [文本](https://www.construct.net/en/make-games/manuals/construct-3/plugin-reference/text){.external}、[纹理字体](https://www.construct.net/en/make-games/manuals/construct-3/plugin-reference/sprite-font){.external} 和 [自适应文本](https://yandex.com/dev/games/doc/zh/sdk/construct-3/adaptive-text.md){.external} 对象内的文本。

![Construct 3 截图：在 Editor 窗口（左侧）中显示文本"{game.title}"。 在 Preview 窗口（右侧）中显示文本"First Fantasy 10"。](../../_images/construct-3/text-localization/result.webp)

## 在事件中使用 {#use-in-events}

此外，您可以在Construct 3的原生事件中以及其他地方使用翻译键。

自动本地化系统可以在游戏过程中变化时将`{potions.mana}`替换为"Mana Potion"。

![Construct 3 截图：屏幕顶部显示一个表格。 它由三个水平单元格组成：设置图标"System"、"On start of layout"、虚线方块中的字母"T"图标以及文本"Text | Set text to "{potions.mana} = 10$""。 在 Preview 窗口中显示文本"Mana Potion = 10$"。](../../_images/construct-3/text-localization/runtime-set-text.webp)

您不仅可以使用 **Set text**，文本可以随时以任何方式更改。

例如，您可以在按下按钮时启动文本打字动画。

![Construct 3 操作视频：屏幕顶部显示一个表格。 它由三个水平单元格组成："OK"图标和文本"Button"、"On clicked"、虚线方块中的字母"T"图标以及文本"Text | Typewriter text "{potions.mana} = 10$" over 3 seconds"。 在 Preview 窗口中只有一个带有"Button"字样的白色按钮。 用户点击它，文本"Mana Potion = 10$"开始逐字出现。](../../_images/construct-3/text-localization/runtime-typewrite-text.gif)

---


<!-- source: zh/_includes/sdk/button-git.md -->
<a href="https://github.com/yandex-games-plugins/construct3">
  <span class="button">存储库</span>
</a>
<!-- endsource: zh/_includes/sdk/button-git.md -->
