Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.kodeflowstudios.com/llms.txt

Use this file to discover all available pages before exploring further.

Localization in Parley depends on a few steps, we’ll make the example with English but any of the following steps can be done with your own custom languages, see How To: Add a new language. After adding your own language(s), using them in Parley requires following a few rules.

Creating the Files

The file that you want to load must be placed in with the parley resource path Resources/{languageEnglishName}/{folderName}/{langCode}.{fileName}. For example Resources/English/SpaceshipLocker/en.Brad.

Populating the MetaData

To make Parley use your files semantically and be able to give you useful info about the loaded file, we populate the meta data for our conversation files, whether it is for YAML of Graph. See YAML MetaData.

Making the Conversation

Now write the conversation files in the native script of the language(s) you want to use, we’ll be using English and German as seen in the example below:
en.Localization
MetaData:
  Language: English
  TextDirection: LTR
Dialogue:
  node_1:
    Speaker: "Receptionist"
    Text: "Welcome to Pineville Hotel! How may I help you today?"
    NextNode: node_2
  node_2:
    Speaker: "Guest"
    Text: "I want to book a room"
    NextNode: node_3
  node_3:
    Speaker: "Receptionist"
    Text: "Right away! How many nights will you be staying?"
    NextNode: node_4
  node_4:
    Speaker: "Guest"
    Text: "5 nights, and I want a lake side view"
    NextNode: node_5
  node_5:
    Speaker: "Receptionist"
    Text: "Great choice, I'll have that sorted for you right away."
de.Localization
MetaData:
  Language: German
  TextDirection: LTR
Dialogue:
  node_1:
    Speaker: "Empfangsdame"
    Text: "Willkommen im Pineville Hotel! Wie kann ich Ihnen heute helfen?"
    NextNode: node_2
  node_2:
    Speaker: "Gast"
    Text: "Ich möchte ein Zimmer buchen"
    NextNode: node_3
  node_3:
    Speaker: "Empfangsdame"
    Text: "Sofort! Wie viele Nächte werden Sie bleiben?"
    NextNode: node_4
  node_4:
    Speaker: "Gast"
    Text: "5 Nächte, und ich möchte einen seitlichen Seeblick"
    NextNode: node_5
  node_5:
    Speaker: "Empfangsdame"
    Text: "Gute Wahl, ich werde das sofort für Sie klären lassen."
As you can see we set the language and text direction, in the next heading we’ll use this data in our script to change the UI.

Making the script

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using KodeFlowStudios.Parley.YamlCore;
using KodeFlowStudios.Parley.Localization;

public class YamlLocalizationUIToolKit : MonoBehaviour
{
	public UIToolKitHandler uiToolKitHandler;

	public LanguageID languageToLoad;

	ParleyYaml parleyYaml;

    void Start()
    {
		Dialogue();
    }

	async void Dialogue()
	{
		// We pass the optional language parameter so we can choose which language to load.
		parleyYaml = new ParleyYaml("Examples", "Localization", languageToLoad);

		if (parleyYaml.Meta.TextDirection == TextDirection.LTR)
		{
			uiToolKitHandler.SetTextDirection(false);
		}
		else
		{
			uiToolKitHandler.SetTextDirection(true);
		}

		while (parleyYaml.ConversationEnded != true)
		{
			uiToolKitHandler.SetSpeakerNameText(parleyYaml.CurrentNode.Speaker);
			uiToolKitHandler.SetDialogueText(parleyYaml.CurrentNode.Text);

			await parleyYaml.OnNextDialogue;
		}

		parleyYaml = null;
	}
}
Parley handles text with direct string substitution, meaning that you just have to point it to the language and it will use it.

Wiring Things Up

Now connect things as we’ve done before, select the language from the inspector, and run to see the difference between each selection.