Tutorial: Making Dialogue Compatible with Other Languages (i18n)

From Stardew Modding Wiki
Jump to navigation Jump to search

In this tutorial, we will be making dialogue entries compatible with other languages using the i18n format.

To make our dialogue compatible with other languages, we will create an i18n folder and default.json file, add the strings in a patch, and create i18n keys/values for those strings that will be used in the content.json and the default.json.

We are using CP for this!

Assumptions we're working with

This tutorial assumes you are familiar with the basics of how to create or edit dialogue entries and are only here to learn about how to format the dialogue to make it compatible with other languages.

Set up i18n folder and default.json file

First, in addition to the content.json file and manifest.json file you need for the mod (tutorial on this here), we will need to create an i18n folder, and a default.json file to go in that folder. A default.json file is created the same way as a content.json / manifest.json file. The default.json file will contain the string texts to show, and we will edit the contents later. Your mod folders should look like this:

Mod Folder Structure

Dialogue file reference

For reference, this is Haley's vanilla dialogue that we'll be i18n-ing today.

{
        "LogName": "Haley Dialogue",
        "Action": "EditData",
        "Target": "Characters/Dialogue/Haley",
        "Entries": {
            "Mon": "This town is so small. It sucks.$u#$e#I have to drive, like, twenty miles to buy any decent clothes.$s#$e#That's why I usually just order online.#$e#What?",
            "Tue2": "I wonder if any nice shells washed up on the beach this morning?#$e#This isn't the best time of year for shells, though.",
            "fall_Sat_old": "I'll probably take a nap later.",
            "summer_Tue8": "I guess living in the country isn't so bad.#$e#If I lived in the city I might start to miss all the trees.#$e#@, I think I've been hanging out with you too much.$h",
            "summer_Fri4": "I spent 3 hours practicing my signature today.#$e#I guess that's pretty silly, huh?",
            "fall_1": "It's fall already?$s",
        }
}

Create i18n keys and values

Next, we have to create internal IDs for each line. Our example token format will be Haley.Dialogue.(Line) but you can use Haley_Dialogue_(Line), as long as the format is uniform. These will be used in the content.json as well as in the default.json. Specifically, these are:

String name in the file Key for i18n Value for i18n Actual string to go in default.json file
Mon Haley.Dialogue.Mon {{i18n:Haley.Dialogue.Mon}} "This town is so small. It sucks.$u#$e#I have to drive, like, twenty miles to buy any decent clothes.$s#$e#That's why I usually just order online.#$e#What?"
Tue2 Haley.Dialogue.Tue2 {{i18n:Haley.Dialogue.Tue2}} "I wonder if any nice shells washed up on the beach this morning?#$e#This isn't the best time of year for shells, though."
fall_Sat_old Haley.Dialogue.fall_Sat_old {{i18n:Haley.Dialogue.fall_Sat_old}} "I'll probably take a nap later."
summer_Tue8 Haley.Dialogue.summer_Tue8 {{i18n:Haley.Dialogue.summer_Tue8}} "I guess living in the country isn't so bad.#$e#If I lived in the city I might start to miss all the trees.#$e#@, I think I've been hanging out with you too much.$h"
summer_Fri4 Haley.Dialogue.summer_Fri4 {{i18n:Haley.Dialogue.summer_Fri4}} "I spent 3 hours practicing my signature today.#$e#I guess that's pretty silly, huh?"
fall_1 Haley.Dialogue.fall_1 {{i18n:Haley.Dialogue.fall_1}} "It's fall already?$s"

Note that you could have chosen to format the keys and values a little differently, based on personal preference. It's up to you to decide how specific you want to get.

Since we have multiple dialogue lines, we have to denote the strings for each with something. In this example, it's .(season)(day)(hearts) at the end of the key and value. You can change the format, but I find this is the simplest and easiest to read.

Add patch for strings in content.json file

Next we will add a patch to add the strings in the content.json file, which will look like this, using the keys and values from the table above:

{
        "LogName": "Haley Dialogue",
        "Action": "EditData",
        "Target": "Characters/Dialogue/Haley",
        "Entries": {
            "Mon": "{{i18n:Haley.Dialogue.Mon}}",
            "Tue2": "{{i18n:Haley.Dialogue.Tue2}}",
            "fall_Sat_old": "{{i18n:Haley.Dialogue.fall_Sat_old}}",
            "summer_Tue8": "{{i18n:Haley.Dialogue.summer_Tue8}}",
            "summer_Fri4": "{{i18n:Haley.Dialogue.summer_Fri4}}",
            "fall_1": "{{i18n:Haley.Dialogue.fall_1}}",
        }
}

Add i18n keys and strings in default.json file

Then we will go to the default.json file, and add the i18n keys and the actual strings text, so the default.json file should look like this:

{
    "Haley.Dialogue.Mon": "This town is so small. It sucks.$u#$e#I have to drive, like, twenty miles to buy any decent clothes.$s#$e#That's why I usually just order online.#$e#What?",
    "Haley.Dialogue.Tue2": "I wonder if any nice shells washed up on the beach this morning?#$e#This isn't the best time of year for shells, though.",
    "Haley.Dialogue.fall_Sat_old": "I'll probably take a nap later.",
    "Haley.Dialogue.summer_Tue8": "I guess living in the country isn't so bad.#$e#If I lived in the city I might start to miss all the trees.#$e#@, I think I've been hanging out with you too much.$h",
    "Haley.Dialogue.summer_Fri4": "I spent 3 hours practicing my signature today.#$e#I guess that's pretty silly, huh?",
    "Haley.Dialogue.fall_1": "It's fall already?$s"
}

Test the dialogue

If you made it this far, congratulations, you have made your dialogue compatible with other languages! Don't forget to test the dialogue in game, to make sure all the strings display correctly.

Set up the dialogue for i18n from the start

Now that you know how to convert an existing set of dialogue to i18n format, you may be wondering how you can start your dialogue with i18n in mind.

One approach is to write the order per these steps: Add i18n keys for the dialog in content.json file (step 4 and 7 bundled together), then write the strings patch in the content.json file (step 5), and then lastly write the actual strings in the default.json file (step 6). If you find it easier to write the mod in a different order than that, that's fine too! As long as you cover all 4 steps, you're set.

See also