Localizing Strings in Daggerfall Unity – Part 6

Series
Localizing Strings in Daggerfall Unity – Part 1
Localizing Strings in Daggerfall Unity – Part 2
Localizing Strings in Daggerfall Unity – Part 3
Localizing Strings in Daggerfall Unity – Part 4
Localizing Strings in Daggerfall Unity – Part 5
Localizing Strings in Daggerfall Unity – Part 6

Custom Fonts

Note: Before progressing to this tutorial, please update source project to Daggerfall Unity 0.11.3 or later. This version has fixes required to complete this part in series.

In Part 3 of this series, we noted the Korean (ko) locale would print out question mark characters (?? ???) instead of proper glyphs.

This happens because Daggerfall Unity does not yet have an appropriate font asset to render these characters. The default fonts have a full complement of Latin characters but non-Latin languages require a new font to display their unique alphabet.

This tutorial will demonstrate how to add a custom Korean font with a Hangul alphabet to Daggerfall Unity, but the same process can be used to add Cyrillic fonts, Kanji fonts, or even just a custom default font.

The font we’ll be using is Noto Serif KR from Google Fonts. Click Download family on that page to download the font used in this tutorial, or substitute with another TTF/OTF font for your language.

Once downloaded, unzip the whole font family and locate NotoSerifKR-Regular.otf. This is the specific font we’ll be using. To start with, we’ll add this font to our Unity project.

  1. In Project view, navigate to our DemoTranslationMod/Resources folder.
  2. Drag and drop the NotoSerifKR-Regular.otf font into this folder with other resources. Unity will import this like below.

Create TextMeshPro Font

Daggerfall Unity uses TextMeshPro (TMP) fonts. Before we can see this font in game, we need to create a TMP font asset.

  1. Click Window menu > TextMeshPro > Font Asset Creator
  2. Set NotoSerifKR-Regular in Source Font File by clicking the circle selector on right-hand side then selecting font

Now we need to determine which character codes our TMP font will support. This will vary based on many factors unique to the target language, but the core concept is that we want to inform Font Asset Creator which character codes from your alphabet to compile into your TMP font. Any characters not added to TMP font asset will continue to display as question marks in game.

There are multiple ways to describe which characters to use. You can select from a basic list of settings, use decimal/hex ranges, import from another TMP font, import from a file, etc. Whatever method you use, keep track of the settings so you can add to it later if any characters are found missing.

In this example, we’re going to use a subset of Hangul alphabet by directly entering the characters required. It’s better to start with a subset of characters for the region/dialect you’re targeting rather than just trying to include everything. Some languages have thousands of characters which can result in an unusable TMP atlas without enough fidelity.

  1. In Font Asset Creator, drop down Character Set selector and choose Custom Characters
  2. Copy and paste the following custom characters into the Custom Character List text box. Note the very first character is a space character.
 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz가개갸거게겨고괴괘교구귀궤규그긔기나내냐너네녀노뇌놰뇨누뉘눼뉴느늬니다대댜더데뎌도되돼됴두뒤뒈류드듸디라래랴러레려로뢰뢔료루뤼뤠류르릐리마매먀머메며모뫼뫠묘무뮈뭬뮤므믜미바배뱌버베벼보뵈봬뵤부뷔붸뷰브븨비사새샤서세셔소쇠쇄쇼수쉬쉐슈브븨비아애야어에여오외왜요우위웨유으의이자재쟈저제져조죄좨죠주쥐줴쥬즈즤지차채챠처체쳐초최쵀쵸추취췌츄츠츼치카캐캬커케켜코쾨쾌쿄쿠퀴퀘큐크킈키타태탸터테텨토퇴퇘툐투튀퉤튜트틔티파패퍄퍼페펴포푀퐤표푸퓌풰퓨프픠피하해햐허헤혀호회홰효후휘훼휴흐희히역을선택십시1234567890‘?’“!”(%)[#]{@}/&\<-+÷×=>®©$€£¥¢:;,.*…

The above characters are enough for this tutorial, but will need to be expanded for full language support. This is how it looks in Font Asset Creator. We’re also adding the basic English alphabet to have a well-rounded font that can still display any untranslated English text.

Click Generate Font Atlas to render all the specified characters into a TMP atlas. Once you’ve created the atlas, you’ll see all the characters packed like below. Click for full size.

TextMeshPro renders glyphs using signed distance fields (SDF). How this works is outside the scope of this tutorial, but to summarise it’s a way of representing fonts using mathematical values that can maintain smooth shapes at any resolution.

In the output field, take note of the Missing characters, Excluded characters, and “characters missing from font file”. This will display any character codes you requested but could not be found in the provided TTF/OTF font. If your source font is missing any important characters, then it’s necessary to locate another TTF/OTF font containing those characters.

Depending on your font requirements, you might want to increase Atlas Resolution, e.g. to 4096×4096 or higher to support more characters with good fidelity. You can also adjust packing method, sample size, etc. for your specific font needs.

For this tutorial, the atlas generated above is good enough. Click the Save button and save your new TMP font to DemoTranslationMod/Resources. We’ll use the default name in a moment, please don’t change it. This creates a new TMP font asset like below with the name “NotoSerifKR-Regular SDF”.

This new SDF asset contains the atlas and other information required to render the TMP font in Daggerfall Unity. You can come back and recreate the font later with different properties or more characters if needed.

Associate Font With Locale

There’s one more step before can see this font in game. We need to associate our custom font with the correct locale so that Daggerfall Unity knows to use it. This is done using the StartupScript.cs code we created previously.

Open StartupScript.cs in your code editor and replace the entire contents with below. Don’t forget to save your changes!

using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.Utility.ModSupport;
using DaggerfallWorkshop.Game.UserInterface;

namespace DemoTranslationMod
{
    public class StartupScript : MonoBehaviour
    {
        // Define the names of translated string table collections
        const string runtimeInternalStrings = "Demo_Strings";
        const string runtimeRSCStrings = "Demo_RSC";

        public static Mod mod;

        [Invoke(StateManager.StateTypes.Start, 0)]
        public static void Init(InitParams initParams)
        {
            mod = initParams.Mod;
            var go = new GameObject(mod.Title);
            go.AddComponent<StartupScript>();
        }

        private void Awake()
        {
            // Set TextManager properties to use translated string table collections
            TextManager.Instance.RuntimeInternalStrings = runtimeInternalStrings;
            TextManager.Instance.RuntimeRSCStrings = runtimeRSCStrings;

            // Load KO font
            DaggerfallFont font_ko = new DaggerfallFont(DaggerfallFont.FontName.FONT0003);
            font_ko.LoadSDFFontAsset("NotoSerifKR-Regular SDF");

            // Assign KO font
            Locale ko = LocalizationSettings.AvailableLocales.GetLocale("ko");
            if (ko)
            {
                TextManager.Instance.RegisterLocalizedFont(ko, DaggerfallFont.FontName.FONT0003, font_ko);
            }

            Debug.Log("StartScript has completed.");
        }
    }
}

Let’s take a look at what changed. To start with, we added some new using statements. These import some extra functionality to the script.

using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using DaggerfallWorkshop.Game.UserInterface;

Then we added the following code to associate our custom font with the KO locale to Daggerfall’s FONT003. This is the default font used in most parts of the game.

// Load KO font
DaggerfallFont font_ko = new DaggerfallFont(DaggerfallFont.FontName.FONT0003);
font_ko.LoadSDFFontAsset("NotoSerifKR-Regular SDF");

// Assign KO font
Locale ko = LocalizationSettings.AvailableLocales.GetLocale("ko");
if (ko)
{
    TextManager.Instance.RegisterLocalizedFont(ko, DaggerfallFont.FontName.FONT0003, font_ko);
}

First, we create a custom DaggerfallFont called font_ko. By default we’re loading FONT003, but we’ll replace this in a moment with our custom font.

Second, we tell font_ko to load our custom font asset using LoadSDFFontAsset(). Any font created using the TextMeshPro Font Asset Creator should load OK. Reminder: you need to be on Daggerfall Unity 0.11.3 or later.

Finally, we try to get the “ko” locale and only continue if this locale is found. If the locale is found, we associate our custom DaggerfallFont with the “ko” locale using RegisterLocalizedFont().

When this code executes at startup, Daggerfall Unity now knows it should use a different font when rendering FONT003 within the Korean (ko) locale. You can associate the same SDF font with FONT001, FONT002, etc. but you might want to use different styles of typefaces to better match the desired look and feel in your translation.

Make sure your changes are saved, then we can try this font in game.

  1. Click Play to start the game and click through to title menu.
  2. Use the locale drop-down to select Korean (ko) in Game view.
  3. Click Start New Game in title menu. If everything works as expected, our custom font will be selected and used with our translated text example.

Click Play again to stop game.

To summarise, creating a custom font requires the following steps:

  1. Locate appropriate TTF/OTF source fonts for your language. These fonts must contain all the alphabet characters you need for your translation.
  2. Import the TTF/OTF font into Unity project.
  3. Use the Font Asset Creator to generate a custom TMP font asset with the required characters and resolution.
  4. Associate new font with your custom locale and related Daggerfall font in startup C# script.

You might need to recreate font several times when creating your translation mod, either to add new characters, change resolution, or just finetune the look and feel. If you change the asset name, don’t forget to update this in your startup script.

Now that we have a custom font, we can move on to packaging our localisation to standalone files. This will be covered in Localizing Strings in Daggerfall Unity – Part 7.

Localizing Strings in Daggerfall Unity – Part 5

Series
Localizing Strings in Daggerfall Unity – Part 1
Localizing Strings in Daggerfall Unity – Part 2
Localizing Strings in Daggerfall Unity – Part 3
Localizing Strings in Daggerfall Unity – Part 4
Localizing Strings in Daggerfall Unity – Part 5
Localizing Strings in Daggerfall Unity – Part 6

Create Mod Settings

We’ve now created new locales, string tables, imported text, translated text, and seen how to manually enable translated text in-game. We’ve also worked through concepts unique to Daggerfall Unity like character remapping, macros, and RSC markup. The next step is to create our mod settings.

  1. Click Daggerfall Tools menu > Mod Builder
  2. Click Create New Mod
  3. Navigate to path Assets/Game/Mods/DemoTranslationMod
  4. Set Filename to DemoTranslationMod
  5. Click Save
  6. Fill out some information about your mod, such as mod name, version, creator name and contact, etc.
  7. Select the platforms you want to build for. We’re just building for Windows in this tutorial.
  8. Click Save Mod Settings to File to save our settings. This should be done any time the settings are changed in Mod Builder.

You should now have something like below (click for full size).

Click Save Mod Settings to File and close the Mod Builder window.

Verify Mod Found

After completing Part 4, you should have the DaggerfallUnityStartup scene open. If not, please open this scene now from Assets/Scenes.

Daggerfall Unity will load any mod settings found as a virtual mod when starting from launcher scene. We’re going to check our new mod settings are found.

  1. Click editor Play button to start game
  2. Click Mods button in launcher
  3. Verify that Demo Translation Mod is listed under Mods Found and it is Enabled

Click editor Play button again to stop game.

Note: If you forget to stop Play from editor, your future changes will not be saved. Unity will revert editor changes when Play is stopped.

Create Mod Script

We’re now going to create a small C# script for our mod to coordinate everything at startup. To begin with, this script will simply set the translated text tables to Live String Tables, as we did manually in Part 3.

  1. In Project view, navigate to Assets/Game/Mods/DemoTranslationMod/Assets
  2. Right-click in empty space space inside this folder and click Create menu > Folder to create a new folder
  3. Name this folder Scripts

Now we can create our C# script.

  1. Navigate into Scripts folder above
  2. Right-click in empty space inside this folder and click Create menu > C# Script to create a new C# script
  3. Name this script StartupScript (Unity will automatically save with .cs extension)

Double-click StartupScript to open it in your configured code editor. Replace the full contents with below and save changes.

using UnityEngine;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.Utility.ModSupport;

namespace DemoTranslationMod
{
    public class StartupScript : MonoBehaviour
    {
        // Define the names of translated string table collections
        const string runtimeInternalStrings = "Demo_Strings";
        const string runtimeRSCStrings = "Demo_RSC";

        public static Mod mod;

        [Invoke(StateManager.StateTypes.Start, 0)]
        public static void Init(InitParams initParams)
        {
            mod = initParams.Mod;
            var go = new GameObject(mod.Title);
            go.AddComponent<StartupScript>();
        }

        private void Awake()
        {
            // Set TextManager properties to use translated string table collections
            TextManager.Instance.RuntimeInternalStrings = runtimeInternalStrings;
            TextManager.Instance.RuntimeRSCStrings = runtimeRSCStrings;

            Debug.Log("StartScript has completed.");
        }
    }
}

Add Script To Mod

Now we have a script to set our string tables at start, we need to add this script to our mod’s list of assets.

  1. Click Daggerfall Tools menu > Mod Builder
  2. Select StartupScript in Project view
  3. Click Add Selected Assets in Mod Builder
  4. Expand Files in Mod Builder (click the little arrow next to Files to expand/contract)
  5. Confirm that StartupScript has been added to list of assets included in mod
  6. Click Save Mod Settings to File and close Mod Builder.

Now start the game with Play in Unity Editor. Click Play again on the launcher screen to start game as normal.

As the main game starts, you should see the following output to Console view. It will be near the end of output, but you might have to scroll up a little. The highlighted line below was emitted by our mod script, so we know it ran the Init() method.

If you don’t see the above, check that StartupScript is added to Mod Builder and you clicked Save Mod Settings to save changes. Be careful not to make editor changes while the game is playing.

Now script has executed, click on TextManager in Hierarchy view while game is running and confirm script has set correct names to Live String Tables in Inspector view. This live change by our script will only persist until game closes.

Now test translated strings are being used. We’ll test this by starting a new character as we did in Part 3.

  1. Select French (fr) locale from selector at top-right of Game view.
  2. Click Start New Game
  3. Confirm French language is shown

Click Play in editor to stop the game.

We now have a Daggerfall Unity mod including translated string tables and a C# script to coordinate settings. We will continue to build on this in Localizing Strings in Daggerfall Unity – Part 6.

Localizing Strings in Daggerfall Unity – Part 4

Series
Localizing Strings in Daggerfall Unity – Part 1
Localizing Strings in Daggerfall Unity – Part 2
Localizing Strings in Daggerfall Unity – Part 3
Localizing Strings in Daggerfall Unity – Part 4
Localizing Strings in Daggerfall Unity – Part 5
Localizing Strings in Daggerfall Unity – Part 6

Understanding RSC Markup

Before configuring our mod for distribution, we’re going to look back at the Demo_RSC string table from Part 2. Here, you saw tags like [/center] and [/left] combined with plain text. This is called RSC markup. See screenshot below with some markup highlighted. To fully translate Daggerfall’s text will require an understanding of how to use this markup in RSC strings.

Strings imported from TEXT.RSC contain bytecode controlling how each line of text is to be formatted. Like TEXT.RSC itself, this bytecode is in a binary format and is not easily read or edited by humans. If this bytecode stream was to be translated directly into numbers with no other changes, it would look something like below.

STRENGTH[0xFD] Strength governs encumbrance, weapon damage[0xFC] and the ease of increasing strength-related skills.[0xFC] With your strength of %str, you are considered %ark[0xFC] [0xFB][0x14]%dam [0xFB](modifier is factored into your[0xFC] [0xFB](hand-to-hand / weapon damage.[0xFC] [0xFB][0x14]%enc [0xFB](kilograms is your maximum encumbrance.[0xFC][0xFE]

This is obviously not pleasant for humans to work with. To overcome this, Daggerfall Unity’s localization system converts raw RSC bytecode into neatly formatted RSC markup with plain-text codes standing in for raw numbers. Line breaks are added where appropriate to help make text more readable and simulate how it will format in-game. The end result seen in RSC string tables now looks like below.

STRENGTH[/center]
 Strength governs encumbrance, weapon damage[/left]
 and the ease of increasing strength-related skills.[/left]
 With your strength of %str, you are considered %ark[/left]
 [/pos:x=20,y=0]%dam [/pos:x=40,y=0]modifier is factored into your[/left]
 [/pos:x=40,y=0]hand-to-hand / weapon damage.[/left]
 [/pos:x=20,y=0]%enc [/pos:x=40,y=0]kilograms is your maximum encumbrance.[/left]
 [/end]

At runtime, RSC markup text is converted back into a bytecode stream and printed to screen by Daggerfall’s UI based on these codes. It’s important not to translate markup codes. Anything contained inside of square brackets [ ] in an RSC-compatible string table will be treated as markup code.

Following is a summary of supported codes so far.

  • [/center] – Centre align this line and starts new line.
  • [/left] – Left align this line and starts a new line.
  • [/newline] – Starts a new line.
  • [/record] – Ends a sub-record for multi-record text (e.g. variants of answers or rumours in conversations).
  • [/input] – Requests a prompt from player (e.g. entering “yes” to open gates in Castel Daggerfall).
  • [/pos:x=0,y=0] – Position prefix for text aligned within UI (e.g. indented text under some other text). The X and Y values determine how far text is offset or indented from start position.
  • [/end] – End orecord. Each RSC record must contain [/end] once all data is completed. This tells the reader there are no more subrecords or data to read for this key.

As you work through the RSC strings, remember to never change anything between square brackets [ ] or the formatting will be broken. And as a general rule, any markup code at the end of a line will also start a new line, except for [/end] which terminates the record.

Understanding Macros

You might have noticed many strings contain a word prefixed with % character, e.g. %str in text above. In Daggerfall Unity, these are called macros, as they expand into some other text when printed out. For example, %str will be converted into the character’s actual STR value at time text is printed – e.g. 65 will be printed in-game in place of %str.

There are over a hundred different macros in Daggerfall, so they won’t be covered in detail here. Just keep in mind that like markup codes above between [ ], you should never translate a macro prefixed with %. This macro code has special meaning to the game and changing it will break the purpose of the text and result in an unhandled error.

Variants in Legacy Import

There are a few places where Daggerfall Unity doesn’t have the exact same string records as classic. The main example of this is TEXT.RSC record 9000 – questions and answers for class questionnaire.

In classic, this is one large record with dozens of entries terminated by a special separator character. This record is so large that it’s very difficult for humans to edit even with RSC markup, and the length of text breaks the Unity string editor UI.

To overcome this, Daggerfall Unity splits record 9000 into multiple new records not present in classic TEXT.RSC – 9000.1 through 9000.40. Each record represents a single question/answer block for class questionnaire and does away with special separator character.

If you import legacy TEXT.RSC translations as we did with French and German, you will note that IDs 9000.1 through 9000.40 are not populated.

It will be necessary to manually translate these 40 records again, following the formatting example shown in English. The other locales did not use a legacy TEXT.RSC file so imported with the default English language version of text.

Translate Some RSC

Earlier in this series, we mentioned it’s also possible to translate English strings. There are a few reasons you might want to create an English translation, such as to fix spelling and formatting, or to change the “flavour” of text to create a unique game experience in your mod.

For a bit of fun, we’ll translate the English record for STRENGTH info popup into pirate speak.

Please be sure to have completed Parts 1-3 and confirmed your translated string tables appear in game.

It helps if you have a save game to load here, as we’re going to view something on the Character Sheet which requires an actual character. If you don’t have a character available, quickly start a new game to put together a basic character, then save that game.

To translate your STRENGTH info popup.

  1. Click Window menu > Asset Management > Localization Tables
  2. Dropdown Selected Table Collection and select Demo_RSC (StringTable)
  3. Locate key 0 for STRENGTH text. It will be at top of string table
  4. If you need to, enlarge editor window and drag around column widths until you can comfortably edit the English (en) value
  5. Copy and paste the entire block of text below into the English (en) value field
STRENGTH[/center]
 Ahoy matey! Strength governs yer encumbrance, weapon damage[/left]
 an' the ease o' increasin' strength-related skills.[/left]
 with yer strength o' %str, ye be considered %ark[/left]
 [/pos:x=20,y=0]%dam [/pos:x=40,y=0]modifier be factored into your[/left]
 [/pos:x=40,y=0]hand-to-hand / weapon damage.[/left]
 [/pos:x=20,y=0]%enc [/pos:x=40,y=0]kilograms be yer maximum encumbrance.[/left]
 [/end]

This should look like below.

You can now close the Localization Tables editor. To see your changes in-game:

  1. Click Play to start game
  2. Ensure English (en) is selected at the top-right of Game view
  3. Load a previously saved character
  4. Press F5 to open the Character Sheet UI (if you’ve changed this keybinding from default, use that key instead)
  5. Click on STR button to open the STRENGTH info popup

If everything has worked, it will look like below in-game.

Preparing to Distribute Mod

So far, we’ve done everything directly in the Unity Editor. This is fine for testing, but we eventually want to distribute translations so that others can use them. Getting ready for distribution will be the focus of next parts in this series.

Before we move on, we need to undo a couple of changes made in editor while testing. Moving forward, we’ll be preparing mod as if our translation work is completed and it’s time to ship the mod.

The first change to undo is the manual setting to use our string table collections.

  1. In DaggerfallUnityGame scene, click the TextManager object
  2. On the TextManager inspector, reset Live String Tables and other settings back to defaults as shown in below screenshot
  3. Save the scene using File menu > Save

We’re done with copying string tables, so empty those settings also.

Because we’re going to create a .dfmod for distribution, we need to ensure the DaggerfallUnityStartup scene is how we start the game. This scene is responsible for loading mods, and going direct to the game scene like we did for testing will skip this essential process.

Please open the DaggerfallUnityStartup scene now, and keep this scene open as you work through remainder of tutorial series.

Once you’ve opened DaggerfallUnityStartup scene, please check the settings for TextManager to ensure they’re still set to defaults as pictured above. We did not change startup scene’s TextManager, but please check it hasn’t been changed by mistake.

Now that we’ve reset TextManager properties and opened DaggerfallUnityStartup scene, we’re ready for Localizing Strings in Daggerfall Unity – Part 5.

Localizing Strings in Daggerfall Unity – Part 3

Series
Localizing Strings in Daggerfall Unity – Part 1
Localizing Strings in Daggerfall Unity – Part 2
Localizing Strings in Daggerfall Unity – Part 3
Localizing Strings in Daggerfall Unity – Part 4
Localizing Strings in Daggerfall Unity – Part 5
Localizing Strings in Daggerfall Unity – Part 6

Editing Strings

In Part 1, we setup the string tables to receive our localized text. In Part 2, we imported strings to configure initial data for each locale with either English text or legacy translations from TEXT.RSC.

Before we edit a few strings into their respective language, we’re going to set all string tables to preload. This means their data is fully loaded sooner and region switching will be faster later in this tutorial. This is recommended when creating translation mods.

  1. Click Window menu > Asset Management > Localization Tables to open string editor.
  2. Drop-down Selected Table Collection and select Demo_Strings (StringTable).
  3. Click the metadata button above any of the string tables and put a tick in Preload All Tables. This will automatically select Preload Table for every locale.
  4. Repeat steps 2-3 for Demo-RSC (StringTable)

With that out of the way, let’s take a closer look at the string table and make our first edits.

The left-hand column of string table holds the unique key each for item. This key is how Daggerfall Unity looks up a string for any language. Never change the key value or this will break string lookup in-game.

Then for each language, there is a value field which contains data for that key. All languages share the same key, only the value needs to be translated.

Note: Daggerfall Unity will occasionally add new keys and values which must also be added to your translation mod. Syncing new keys to maintain your mod will be covered in a future tutorial in this series.

We’re now going to change the value of pleaseSelectYourHomeProvince for each locale. This is one of the first strings seen when starting a new character, and also near the top of list, so it’s a good place to start. Copy and paste the following text into each locale’s value field next to the pleaseSelectYourHomeProvince key.

Czech (ch) : Vyberte svou domovskou provincii…
French (fr) : Veuillez sélectionner votre province d’origine…
German (de) : Bitte wählen Sie Ihre Heimatprovinz…
Korean (ko) : 거주 지역을 선택하십시오…

Note: Translations were created using Google Translate.

Once this is completed, your string table should look like below (click for full size).

You can now close the Localization Tables editor.

Setting Play Mode Script

Before we take a look at these translations in-game, we’re going to check the Play Mode Script for addressables in Unity. We won’t go into this in detail, but we need to ensure the correct setting is selected before proceeding.

  1. Click Window menu > Asset Management > Addressables > Groups
  2. Click Play Mode Script and confirm Use Asset Database (fastest) is selected
  3. Close the Addressables Groups UI

The Play Mode Script is how Unity will load addressable assets like string tables during play. For simplicity and speed, we will only select Use Asset Database (fastest) in this tutorial. This is also the default setting.

Assign String Tables To TextManager

The final step to see our translations in-game is to tell Daggerfall Unity how to load our translated assets.

You should already have the DaggerfallGameScene open from Part 2. If not, locate this scene in Project view under Assets/Scenes and open it now.

Locate and select the TextManager component then look to the Inspector view. We must now change the Live String Tables to reference our custom translations instead of the default English language in core game. Make the highlighted edits in below screenshot.

The names Demo_Strings and Demo_RSC match the two string table collections we created back in Part 1. Changing these settings will redirect string lookups to our custom string tables.

To quickly summarise the purpose of each string table collection:

  • Internal Strings – Are all strings previously extracted from FALL.EXE and other hardcoded locations. Their key is in plain text and represents the text being translated.
  • RSC Strings – Are all strings extracted from TEXT.RSC. Their key is a numeric value matching an ID in TEXT.RSC.
  • BOK Strings – Will be all strings extracted from books in game data. This is under development and will be available in a future release of Daggerfall Unity.

Testing In-Game

To quickly recap everything we’ve done so far:

  1. Setup Unity 2019.4.10 and cloned the full Daggerfall Unity project
  2. Created empty string table collections Demo_Strings and Demo_RSC.
  3. Imported initial text to populate our two new string table collections, using legacy translations from French and German TEXT.RSC, and remapped back to correct character codes.
  4. Set all string tables to preload.
  5. Translated string values for “Please select your home province…” into multiple languages.
  6. Set the Play Mode Script to Use Asset Database (fastest).
  7. Opened the DaggerfallUnityGame scene.
  8. Assigned our string table collection to Live String Tables in TextManager inspector.

Click Play button to start the game. Because we have the DaggerfallUnityGame scene open, it will open straight to the title menu. Just click to dismiss any videos that play at startup.

Once game has started, take note of the language dropdown towards top-right of play window.

Note: Depending on your locale settings, you might have another language other than English (en) above.

Whatever your language is, use this dropdown and change the selected locale to French (fr). Then click Start New Game. If everything is working properly, you should see our translated text in French.

Note: There might be a short delay when Unity first preloads string data. You may need to click Start New Game twice after changing language.

Now press Escape key to return to title menu and change language to German (de). Click Start New Game again and the text should now be in German.

Finally, press Escape key back to title menu again, then change language to Korean (ko) and click Start New Game.

So what’s gone wrong here? Why are we seeing question marks? Everything looked OK when creating the translated string in the editor.

These question marks indicate Daggerfall Unity was unable to locate font characters matching one or more codes in source text. The default fonts in Daggerfall Unity have a full complement of Latin characters, but they do not have characters for non-Latin languages. When the game attempts to render these unknown characters, it will display question marks instead.

To fix this, we need to provide new fonts with locale-specific characters to Daggerfall Unity. Fonts will be covered in a future tutorial in this series.

We have a little more ground to cover first in Localizing Strings in Daggerfall Unity – Part 4.

Localizing Strings in Daggerfall Unity – Part 2

Series
Localizing Strings in Daggerfall Unity – Part 1
Localizing Strings in Daggerfall Unity – Part 2
Localizing Strings in Daggerfall Unity – Part 3
Localizing Strings in Daggerfall Unity – Part 4
Localizing Strings in Daggerfall Unity – Part 5
Localizing Strings in Daggerfall Unity – Part 6

Playing in Unity Editor

If you’ve followed tutorial up to this point, you should have the full Daggerfall Unity project open inside Unity 2019.4.10 and created some new locales and empty string tables.

As we progress, we’ll begin testing our translations directly inside of the Unity Editor. To make sure everything is working as expected, let’s begin by opening the startup scene.

  1. In Project view, navigate to Assets/Scenes
  2. Double-click DaggerfallUnityStartup scene to open it in the editor

The DaggerfallUnityStartup scene is the launcher window you see when running a game build. You should see the following structure in your Hierarchy view.

Now click the Play button to start Daggerfall Unity inside editor.

If you’ve previously setup Daggerfall Unity for regular play, it will open straight to the launcher UI in your Game view as normal.

If you’ve never setup Daggerfall Unity for play, you’ll first need to provide a good set of game files. We recommend the DaggerfallGameFiles zip available on Live Builds page.

For more information on setting up Daggerfall Unity for play, head over to Installing Daggerfall Unity and Other Information topic on our forums.

Try playing the game and loading a save if you have one. Everything should work inside the editor as if you were playing Daggerfall Unity normally from a build. When you’re ready, click Unity’s Play button once again to stop the game.

At this point, we’re ready to begin importing text and testing it in game. For convenience, we’re going to open the DaggerfallUnityGame scene to bypass the launcher and go straight into game.

  1. In Project view, navigate to Assets/Scenes
  2. Double-click DaggerfallUnityGame scene to open it in the editor

You’ll notice in Hierarchy there’s more inside the game scene. One particular object you should take note of is TextManager.

The TextManager object is our global interface to string tables and importing text. We’ll get back to this shortly, just remember where it is for now.

Understanding Legacy Translations

Before we bulk import text into our new string tables, some understanding is required about strings in classic Daggerfall.

If you’ve been around for a while and maybe helped translate classic Daggerfall, you will have encountered the problem of its limited 8-bit character set not being able to correctly code accented characters like ç or û.

The way translators had to work around this back then was to remap each accented character to one within Daggerfall’s available character set. For example, the following text:

compétences liées à la volonté

Would be written in modified TEXT.RSC data as:

comp<tences li<es @ la volont<

Then to make these characters appear correctly in game, font glyphs for < and @ were redrawn to look like é and à. Finally, when classic Daggerfall rendered this remapped text in game, it appears correct to the player. But underneath it all, the source text still uses < and @ in place of real character codes.

This means classic translators had to write various degrees of gibberish using remapped characters. And if the target language does not even resemble Latin characters (e.g. Cyrillic), then the work became even harder.

Daggerfall Unity has no such character limitation and can use text written normally with accented or non-Latin characters. It supports standard international character codes and fonts with any number of glyphs.

Unfortunately, legacy translations for classic Daggerfall were all created using remapped characters. When importing classic text data, e.g. from TEXT.RSC, these characters are imported as-is and the translated text just looks like gibberish as written.

Rather than discard legacy translations and start from scratch, Daggerfall Unity has the ability to undo character remappings back to their original character codes while performing a bulk import. This is handled by providing a TextMappingTable to string importer.

Understanding TextMappingTable

The TextMappingTable is a simple data file in .txt format providing conversion from a remapped character code back to their original character. Conversions for multiple locales can be stored in one TextMappingTable.

This tutorial provides a sample TextMappingTable for French (fr) and German (de) legacy strings. To create this table, copy the entire of below into a new text document.

-Character mapping database for importing classic text with remapped character data

schema: *key,locale,source,replacement

-French (fr)
0,   fr, $ , ç
1,   fr, < , é
2,   fr, # , è
3,   fr, @ , à
4,   fr, ^ , ê
5,   fr, ~ , ù
6,   fr, \ , â
7,   fr, ` , û
8,   fr, * , ë
9,   fr, { , ï
10,  fr, } , î
11,  fr, | , ô

-German (de)
12,  de, @ , Ä
13,  de, # , ä
14,  de, $ , Ö
15,  de, & , ö
16,  de, { , Ü
17,  de, } , ü
18,  de, * , ß

Save this text document as TextMappingTable.txt in your DemoTranslationMod/Resources folder created in previous tutorial.

If you’ve already saved document elsewhere, you can also drag and drop it into above path in Unity’s Project view.

If you need to add more locales to your TextMappingTable, follow the example above and be sure that each new line as a unique number for key. For example, the next available key in sequence above is 19.

Note: providing a TextMappingTable is not required if you plan to start from scratch with fresh translations, or don’t have legacy classic translations available.

Download Legacy Translations

We’re almost ready to bulk import classic text data into our string tables.

As a convenience, this tutorial provides legacy translated TEXT.RSC files for French (fr) and German (de). Please download the following zip and extract somewhere.

Download

The files in above download were created by the French and German communities respectively, and all credit belongs to those communities for their work:

When you unzip this archive, you will see it contains two TEXT.RSC files, each with a very specific filename.

The file “TEXT_fr.RSC.bytes” is the French TEXT.RSC file, and “TEXT_de.RSC.bytes” is the German TEXT.RSC. The file data is unchanged from source, only the names are changed so that Daggerfall Unity can identify which file belongs to which locale.

The “.bytes” extension is a Unity convention so resource loader knows the file is a binary asset.

Now that you have a couple of legacy translations available, you need to place them into your mod project.

  1. In Project view, navigate to DemoTranslationMod/Resources
  2. Drag and drop the translated and renamed TEXT.RSC files directly into your Resources folder

This will add the files to Resources along with the TextMappingTable.txt file we added earlier. Your DemoTranslationMod/Resources folder should now contain three files like below.

Note that Unity does not display the .bytes or .txt file extensions in editor.

Initialize String Table Collections

Everything is now in place to bulk import text from classic Daggerfall into your string table collections, which initializes all of them at once with the correct keys and starting text.

If you’ve provided the files above to DemoTranslationMod/Resources, the pre-translated text from TEXT.RSC in French (fr) and German (de) locales will be used, and their remapped character codes will be converted back to normal character codes thanks to the TextMappingTable.

All other locales will be initialised using the English (en) language as a starting point.

Note: As localization is still in Preview, not all text sources are supported for translations. At time of writing, Daggerfall Unity supports localization of strings from TEXT.RSC and strings exported from FALL.EXE. However, only TEXT.RSC is supported for bulk import at this time. Other than Quests and Books, this constitutes around 95%+ of all text in game. Support for more text sources, including Quests and Books, will be added in future.

Remember the TextManager in the Game scene from earlier? Click on this now to select it.

Then locate your Inspector view in editor and you will see that TextManager has a custom editor tool attached.

The Live String Tables are used by game at runtime. We’ll get to this in a later tutorial in series.

For now, we’re just going to copy our source text into the empty string table collections we created in first tutorial. For this we’ll use the Copy String Tables tool.

Enter settings as shown below and click Copy All. Don’t worry about BOK Strings for now. This field will be used later once Books are supported by localization.

After clicking Copy All, you should see information like below output to the Console view. This means the bulk import has completed to the target string collections we specified in Copy String Tables. For simplicity, the importer will copy strings for all locales in a single pass.

If TextManager was able to find pre-translated TEXT.RSC files for a locale, it will import strings from those files. If a TextMappingTable exists for those locales, characters will be automatically remapped back to correct character codes.

Checking Imported Strings

We can now check on our imported strings to make sure everything worked as expected.

  1. Open the Localization Tables editor using Window menu > Asset Management > Localization Tables
  2. Click Selected Table Collection and select Demo_RSC (StringTable).

You should see a fully populated string table collection for all of the locales we configured earlier.

Note the French (fr) and German (de) string tables have been populated by our translated TEXT.RSC files, and accented character codes have been restored. All other locales have been configured with English as a starting point.

You will also notice special RSC markup tags like [/center] and [/end]. These will be covered further in a later tutorial in series.

For now, move on to Localizing Strings in Daggerfall Unity – Part 3.

Localizing Strings in Daggerfall Unity – Part 1

Series
Localizing Strings in Daggerfall Unity – Part 1
Localizing Strings in Daggerfall Unity – Part 2
Localizing Strings in Daggerfall Unity – Part 3
Localizing Strings in Daggerfall Unity – Part 4
Localizing Strings in Daggerfall Unity – Part 5
Localizing Strings in Daggerfall Unity – Part 6

In this technical series, we’ll cover how to create a string localization mod for Daggerfall Unity then distribute it as a .dfmod file alongside built string assets.

The process of creating a string localization mod is similar to creating any other .dfmod for Daggerfall Unity, so parts of this tutorial will assume at least some familiarity with the Unity Engine and modding Daggerfall Unity in general.

If you get stuck with the basics of mod creation, please reach out to the wider modding community on our forums. There are dozens of experienced modders who are more than happy to share their knowledge and help you learn. And Unity has thousands of resources and communities online to learn more about the engine itself.

Throughout this series, please keep in mind that Daggerfall Unity is currently in Beta and the localization feature is considered to be in Preview. This feature will continue to expand through to 1.0 and beyond, and the information in this series is subject to change. Once localization is out of Preview, this tutorial series will be updated and included with the general modding documentation.

Setting Up

To get started, you will first need to download and install Unity 2019.4.10 (specifically this version) from the Unity Download Archive. The Unity Hub download is the easiest way to initiate this process.

Then you need to clone the full Daggerfall Unity source project from GitHub. You can just download a zip file of the source, but it’s recommended to fork Daggerfall Unity to your own GitHub repo so that you can collaborate with others and maintain your translation mod long-term. As Daggerfall Unity continues to grow and reach new versions, your mod will need to be kept up to date to remain compatible.

If you’re not overly familiar with git conventions and GitHub, using GitHub Desktop is the easiest way to get started.

Once you have Unity 2019.4.10 installed and the source project cloned locally, proceed to open the Daggerfall Unity project and we can begin.

Prepare Mod Folder Structure

The first step to creating any .dfmod is to prepare a folder structure to organise all the files your mod needs. In this tutorial, we’ll put everything inside the Assets/Game/Mods folder. Locate this folder in the Project view and create the folder hierarchy as shown below in blue.

Create New Locales

Daggerfall Unity ships with only the English (en) locale. To add strings for additional languages, we first need to generate additional locales.

You will probably only want to create a single translation for your mod, but for the purposes of this tutorial, we’re going to create multiple languages to gain a better understanding of how everything works together.

  1. Click Edit menu > Project Settings
  2. Select Localization
  3. Click Locale Generator
  4. Find and select the French (fr), German (de), Korean (ko), Czech (cs) locales
  5. Once these locales are selected, click the Generate Locales button
  6. Navigate to your prepared DemoTranslationMod/Assets/Locales folder and click Select Folder

You should now have the following languages displayed in the Localization window. If not, just click Locale Generator again and add the missing locales.

Then inside your mod’s Locales folder, you should see the following files. You’ll note that English (en) is not included, that’s because this locale is already part of the core game.

Create String Tables

Now that we’ve created our locales, we can generate new String Table Collections for translated text.

A string table is basically a text database where all strings in the game are held. Each string is uniquely identified by a key that remains the same across all locales. When the game needs to display a string to the player, it will lookup that key within the string tables for current locale.

In this tutorial, we’re going to create a custom English (en) translation to demonstrate that it’s also possible to change core text through the localization system.

  1. Window menu > Asset Management > Localization Tables
  2. Click New Table Collection
  3. Ensure all locales are selected
  4. Enter new Table Collection Name of Demo_Strings
  5. Click Create String Table Collection button
  6. Navigate to your prepared DemoTranslationMod/Assets/StringTables and click Select Folder

Repeat the above process to create a second set of string tables called Demo_RSC.

Once this is completed, you should see the following collection of files inside your DemoTranslationMod/Assets/StringTables folder.

You don’t need to be overly concerned about these files or how they work. Just having them present in the right folder is all that’s needed for now.

To open your string tables for editing, click Window menu > Asset Management > Localization Tables.

Use Selected Table Collection to select between your mod’s Demo_Strings and Demo_RSC string tables.

You’ll notice new string tables are all empty. This is where we get to the next step and import text from classic Daggerfall with all the right keys so we can begin writing translated text.

This will be covered in Localizing Strings in Daggerfall Unity – Part 2.