Unity Localisation
In addition to Yarn Spinner's own built-in localisation system, your game can also use the Unity Localization package.
Both the Unity Localization and Built-In Localisation approaches are very similar to one another, but there are some caveats and extra steps to make them play together.
The Built-In Localisation system is simpler, but has fewer features.
In this document, we'll refer to the 'Localization' package that Unity provides as 'Unity Localization', to reduce the chance of confusion.
Watch a video where Yarn Spinner developer Jon Manning walks you through using Yarn Spinner with Unity's Localisation package:
Getting Started
Before doing anything with Yarn Spinner, you will need to set up your Unity project to use the Unity Localization system. To install and set up Unity Localization, follow the instructions on the Unity Localization package's documentation.
Once you have followed these instructions, your project should now:
Have the Unity Localization package installed
Created and configured one or more Locales for your project
Created a string table collection.
When localising your game's dialogue using Yarn Spinner, we recommend creating a separate string table collection for your dialogue, set apart from other localised content like button labels. It can make it a little easier to manage.
With these done you should now have your project set up correctly, and have a string table collection for your locales with no entries inside. Yarn Spinner will fill this string table with content that it extracts from your Yarn Scripts.
Importing Default Strings
To fill a string table with content from a Yarn project, follow these steps:
Select the Yarn Project, and go to its Inspector.
Enable the Use Unity Localisation System setting.
Set the
Base Language
to your desired language. This must be ensure its one of the locales that you have configured for your project.In the
String Table Collection
field, add the String Table Collection that you want to populate with line content.Click Apply.
![](https://docs.yarnspinner.dev/~gitbook/image?url=https%3A%2F%2F3844916845-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FW7FKDVQjKCuUze7DY3br%252Fuploads%252Fgit-blob-a24803c91f91b54161ac675bb42da40e21cd80c7%252Fyarn-proj-configured-unity-localisation.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=b23342c0&sv=1)
You can check that the string table has been filled with content by opening the Window menu, and choosing Asset Management -> Localization Tables. You can then view the contents of your string table. The Key of each string will be the #line
ID from the Yarn files.
String Table Locale Fallback
When the Yarn Project importer adds your lines into the string table, it uses the Base language field you set in the Inspector to determine which locale in your String Table Collection should have the lines added into.
If your project doesn't have a Locale which matches your Base Language, Yarn Spinner will attempt to find an appropriate Locale to use. To ensure that the importer uses the correct Locale, be sure to specify it in the Inspector.
Using the Strings
When a Yarn script is run, the Dialogue Runner receives line IDs from the Yarn Project, and must determine what localised content should be shown to the player, using a line provider. In order for the Dialogue Runner to fetch localised data from the Unity string table, you use a Unity Localised Line Provider.
The Dialogue Runner's Inspector will tell you when you need to use a Unity Localised Line Provider. You can click the button it provides to quickly add and configure one. You can also set one up manually, using the Add Component menu.
To configure it, all that needs to be done is hook your string table collection up to the Strings field of the Unity Localised Line Provider.
During gameplay, the Unity Localised Line Provider will fetch content from your string table depending on the game's current locale setting. You can control this at run-time by using the locale selector at the top-right corner of your Game View.
![](https://docs.yarnspinner.dev/~gitbook/image?url=https%3A%2F%2F3844916845-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FW7FKDVQjKCuUze7DY3br%252Fuploads%252Fgit-blob-93c77a73c94ffeb37794ed61db18cb481fcc3d3b%252Funity-locale-selector.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=86d63a98&sv=1)
Localising Assets
In addition to localising the strings that make up your lines, you can also localise assets that go with each line, such as voice-over audio, or custom objects that store other localised data.
To localise assets in Unity Localisation, you create and populate an Asset Table. Yarn Spinner doesn't automatically populate Asset Tables for you like it does String Tables, because Yarn Spinner doesn't manage your assets like it does with your lines.
Instead, you can create an Asset Table that contains assets with the same key as your lines. For example, if you have a line in your Yarn script that has the line ID "line:tom-1
", then the string table will have an entry with the key line:tom-1
. To create a voice-over asset to go with this line, you can create an asset table that contains an entry with the key tom-1
, and maps to an audio file.
The Unity Localised Line Provider will automatically match String Table entries and Asset Table entries if they have the same key, and then deliver them to your Dialogue Views for use. To do this, ensure that your Unity Localised Line Provider has an Asset Table configured in the Inspector.
![](https://docs.yarnspinner.dev/~gitbook/image?url=https%3A%2F%2F3844916845-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FW7FKDVQjKCuUze7DY3br%252Fuploads%252Fgit-blob-9aaf47f93e8f460b9662f4b9e6eca0efc8ea8b0f%252Fyarn-unity-localised-line-provider.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=50eeb795&sv=1)
Potential Trip-ups and Caveats
Because both Yarn Spinner and Unity use the same marker for their string interpolation and manipulation ({
and }
), you can't use the Unity Localization smart strings in Yarn Spinner content.
Last updated