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.
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.
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.
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: LTRDialogue: 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: LTRDialogue: 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.
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; }}
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 Graph Meta Node.
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:
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.
using System;using System.Collections.Generic;using System.Linq;using UnityEngine;using KodeFlowStudios.Parley.GraphCore;using KodeFlowStudios.Parley.Localization;public class GraphLocalizationUIToolKit : MonoBehaviour{ public UIToolKitHandler uiToolKitHandler; public LanguageID languageToLoad; ParleyGraph parleyGraph; void Start() { Dialogue(); } async void Dialogue() { // We pass the optional language parameter so we can choose which language to load. parleyGraph = new ParleyGraph("Examples", "Localization", languageToLoad); if (parleyGraph.Meta.TextDirection == TextDirection.LTR) { uiToolKitHandler.SetTextDirection(false); } else { uiToolKitHandler.SetTextDirection(true); } while (parleyGraph.ConversationEnded != true) { uiToolKitHandler.SetSpeakerNameText(parleyGraph.CurrentNode.Speaker); uiToolKitHandler.SetDialogueText(parleyGraph.CurrentNode.Text); await parleyGraph.OnNextDialogue; } parleyGraph = null; }}
Parley handles text with direct string substitution, meaning that you just have to point it to the language and it will use it.