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

# Localization

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

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

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

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

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

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

## Creating translations {#create-translation}

To create a translation, create an `i18n` folder. It will store translations in JSON format files.

As an example, let's create `en.json` and `ru.json` files, which will correspond to the English and Russian languages.

![Screenshot of the file structure: part of the list of folders "fronts", "i18n", "input", and "ysdk" is visible. The "i18n" folder contains the files "en.json" and "ru.json".](../../_images/defold/localization/files-create.webp)

Add the content to the translation files:

{% list tabs %}

- en.json

    ```json showLineNumbers
    {
        "game": {
            "title": "Cool Game"
        },
        "button": "Button"
    }
    ```

- ru.json

    ```json showLineNumbers
    {
        "game": {
            "title": "Крутая игра"
        },
        "button": "Кнопка"
    }
    ```

{% endlist %}

## Retrieving translations {#get-translation}

To get the value of a specific key, you can use the `i18n.key(key)` method.

```lua
print(i18n.key("game.title")) -- "Cool Game"
```

There is also a helper method `i18n.gui(node_id, key)`, which replaces the content of the selected UI node.

With `i18n.gui()`, we can shorten:

```lua
gui.set_text(gui.get_node("title_label"), i18n.key("game.title"))
```

Before:

```lua
i18n.gui("title_label", "game.title")
```

### Example of game localization {#localization-example}

```lua showLineNumbers
local i18n = require('ysdk.i18n')

local function on_localize()
    i18n.gui("title_label", "game.title")
    i18n.gui("button_label", "button")
end

function init(self)
    i18n.on(on_localize)
end

function final(self)
    i18n.off(on_localize)
end
```

![In the center of the black screen there is the label "Cool", slightly below it a white button with the label "Button".](../../_images/defold/localization/example.webp)

## Changing the translation language {#lang-change}

{% note info %}

The i18n module automatically initializes the language to match the user's [environment variables](https://yandex.com/dev/games/doc/en/sdk/defold/environment.md).

It is recommended to use this method only if you want to manually change the language according to the user's request.

{% endnote %}

To change the translation language, you can use the `i18n.set_language(code: string)` method.

```lua showLineNumbers
function settings.change_language(code)
    i18n.set_language(code)
end
```

---


<!-- source: en/_includes/sdk/button-git.md -->
<a href="https://github.com/yandex-games-plugins/defold">
  <span class="button">Repository</span>
</a>
<!-- endsource: en/_includes/sdk/button-git.md -->
