---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.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: zh/sdk/construct-3/text-localization.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/games/doc/zh/llms.txt

# 文本本地化

<!-- 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翻译。

首先，您应该在`Files`目录中创建一个名为`i18n`的文件夹。然后在该文件夹中创建JSON文件，并使用[ISO 639-1](https://zh.wikipedia.org/wiki/ISO_639-1){.external}格式的对应语言代码命名。

![](../../_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}`。

![](../../_images/construct-3/text-localization/example.webp)

现在，如果我们按下播放按钮（预览），我们将看到奇迹发生，我们的文本自动更改为"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)对象内的文本。

![](../../_images/construct-3/text-localization/result.webp)



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

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

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

![](../../_images/construct-3/text-localization/runtime-set-text.webp)

更重要的是，您不仅限于使用**Set text**，您可以随时以任何方式更改文本。

例如，您可以在按下按钮时启动文本打字动画，一切都会正常工作。

![](../../_images/construct-3/text-localization/runtime-typewrite-text.gif)


---


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