Localization
Localization Editor
Translations are stored in JSON format within the project, and we strongly recommend using it for editing them.
After installing the plugin, in the Yandex Games SDK section, click on the Localization Editor option.
At first, the editor will look quite empty. This is because you need to create your first localization, which can be done by clicking the Create button in the upper left corner.
A modal window will appear where you can select a language. Once finished, press Create JSON file.
For example, let's select English (en) and enter the following in the editor.
{
"title": "best game in the world 2"
}
Press the Save button to save your localization and test it in the game.
Applying Your Localization
There are two ways to apply localization: using the l10n.t()
method or through the smart localization component.
Method l10n.t
Let's first try using the l10n.t()
method. Create a new component and insert the following:
import { _decorator, Component, Label } from "cc";
import { l10n } from "db://yandex-games-sdk/ysdk";
const { ccclass, requireComponent } = _decorator;
@ccclass("ButtonLocalizationTest") // Component name.
@requireComponent(Label) // Dependency on the Label component.
export class ButtonLocalizationTest extends Component {
onLoad() {
const label = this.getComponent(Label); // Retrieve the Label component.
label.string = l10n.t("title"); // Set the text of the Label based on a previously specified key.
}
}
After you create a node with a Label component on the scene, you can localize it by dragging the component to the node.
The Ready-made Component L10nLabel
If you don't want to reinvent the wheel, the plugin has a ready-made component that displays the key directly in the editor. Compiling the project to view changes is not required, as it automatically updates when changes are made in the translation editor.
Click on the Add Component button for the node you are interested in, scroll to the YandexGamesSDK group, and select L10nLabel.
Now you can enter your key in the Key field and enjoy the result. No matter how you change the localization, changes will be immediately visible here.