---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.4
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: en/sdk/defold/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/en/llms.txt

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

First, create an `i18n` folder where you will store JSON files containing your translations.

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

![](../../_images/defold/localization/files-create.webp)

Now, let's fill our files with some content:

{% 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 for a specific key, you can use the method `i18n.localize(key)`.

```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", "game.title")
end

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

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

![](../../_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/button-git.md -->
<a href="https://github.com/yandex-games-plugins/defold">
  <span class="button">Repository</span>
</a>
<!-- endsource: en/_includes/button-git.md -->
