Modding:Custom languages

From Stardew Valley Wiki
Revision as of 23:49, 21 October 2021 by Pathoschild (talk | contribs) (create initial page with data format + Content Patcher example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Index

This page explains how to create custom languages in Stardew Valley 1.5.5+. This is an advanced guide for modders.

Add a custom language

Data format

You can now add custom languages by editing the Data/AdditionalLanguages asset. Each entry consists of an object with these fields:

field description
ID A unique ID value. This is not shown in-game.
LanguageCode The language code for this localization. This should ideally be a ISO 639-1 code. You should avoid commas for compatibility with Content Patcher packs checking the {{Language}} token.
ButtonTexture The asset name for a 174x78 pixel texture containing the button of the language for language selection menu. The top half of the sprite is the default state, while the bottom half is the hover state.
UseLatinFont Whether the language uses the same Latin character font as English. If set to false, you must set the FontFile field.
TimeFormat A string which describes the in-game time format, with tokens replaced by in-game values. For example, [HOURS_12]:[MINUTES] [AM_PM] would show 12:00 PM at noon.

The valid tokens are:

  • [HOURS_12]: hours in 12-hour format, where midnight and noon are both "12".
  • [HOURS_12_0]: hours in 12-hour format, where midnight and noon are both "0".
  • [HOURS_24]: hours in 24-hour format, where midnight is "0" and noon is "12".
  • [HOURS_24_00]: hours in 24-hour format with zero-padding, where midnight is "00" and noon is "12".
  • [MINUTES]: minutes with zero-padding.
  • [AM_PM]: the localized text for "am" or "pm" (taken from Strings\\StringsFromCSFiles:DayTimeMoneyBox.cs.10370 and DayTimeMoneyBox.cs.10371 respectively). The game shows "pm" between noon and 11:59pm inclusively; it shows "am" otherwise.
ClockTimeFormat A string which describes the in-game time format. Equivalent to TimeFormat, but used for the in-game clock.
ClockDateFormat A string which describes the in-game date format as shown in the in-game clock, with tokens replaced by in-game values. For example, [DAY_OF_WEEK]. [DAY_OF_MONTH] would show Mon. 1.

The valid tokens are:

  • [DAY_OF_WEEK]: the abbreviated day of week as returned by Game1.shortDayDisplayNameFromDayOfSeason (like Mon for Monday).
  • [DAY_OF_MONTH]: the numerical day of the month.
FontFile (optional) The asset name for the font file to use (if UseLatinFont is false).
FontPixelZoom (optional) A factor by while to multiply the font size.
FontApplyYOffset (optional) Whether to shift the font up by four pixels (multiplied by the FontPixelZoom), to better align languages with larger characters like Chinese and Japanese.
NumberComma (optional) The string to use as the thousands separator (e.g. "," for 5,000,000). Defaults to a comma.
SmallFontLineSpacing (optional) The line spacing value used by smallFont. Defaults to 26.
UseGenderedCharacterTranslations (optional) Whether the social tab and gift log will use gender-specific translations (like the vanilla Portuguese language). Defaults to false.

Specifically, this affects the Strings\StringsFromCSFiles:SocialPage.cs.11635 translation ("(Single)"). When enabled, it can contain male and female translations separated by /, like the vanilla Portuguese translation: "(solteiro)/(solteira)".

Example

This Content Patcher pack would add Esperanto to the game. You should change Pathoschild.Esperanto to your mod's actual ID.

{
    "Format": "2.0.0",
    "Changes": [
        // define language
        {
            "Action": "EditData",
            "Target": "Data/AdditionalLanguages",
            "Entries": {
                "Pathoschild.Esperanto": { // for technical reasons, you need to specify the ID here *and* in the "ID" field
                    "ID": "Pathoschild.Esperanto",
                    "LanguageCode": "eo",
                    "ButtonTexture": "Mods/Pathoschild.Esperanto/Button",
                    "UseLatinFont": true,
                    "TimeFormat": "[HOURS_24_00]:[MINUTES]",
                    "ClockTimeFormat": "[HOURS_24_00]:[MINUTES]",
                    "ClockDateFormat": "[DAY_OF_WEEK] [DAY_OF_MONTH]"
                }
            }
        },

        // load button texture
        {
            "Action": "Load",
            "Target": "Mods/Pathoschild.Esperanto/Button",
            "FromFile": "assets/button.png"
        }
    ]
}

Once the language is defined, you can add translations to the game by patching game assets like usual, and use the language code you specified above. For example:

{
    "Action": "EditData",
    "Target": "Strings/StringsFromCSFiles",
    "Entries": {
        "Game1.cs.3043": "Lundo",
        "Game1.cs.3044": "Mardo",
        ...
    },
    "When": {
        "Language": "eo"
    }
}