Localization Guide - NeisesMike/VehicleFramework GitHub Wiki

Localization

Localization is the process of making text appear in a chosen language. It's a valuable accessibility tool.

Vehicle Framework offers a simple method for adding localization.

To implement localization using Vehicle Framework, follow this three-part process:

  1. Define your localization enum type.
  2. Translate your text to create variants for different languages.
  3. Invoke VehicleFramework.Localization.Localizer.GetString.

A more in-depth description of each step follows, complete with examples.

Define your localization enumerated type

For every string you want to localize, you should add a value to an enum type that you define. For example, in the Void Depth Upgrade, I use only two strings. So I created an enum type with only two values. Like so:

public enum EnglishString
{
    ModuleDisplayName,
    ModuleDescription,
}

That's all you need to do for this part!

Create your localization files

This is the hard part. For this part, you must translate your messages into all the languages you want to support. Subnautica supports a bunch of languages I don't speak, so I've used ChatGPT to do most of the translations I offer in my mods. Here is the internal Vehicle Framework enum that captures those languages:

internal enum SupportedLanguage
{
    bg_BG,
    zh_CN,
    zh_Hant,
    hr_HR,
    cs_CZ,
    da_DK,
    nl_BE,
    en_US,
    et_EE,
    fi_FI,
    fr_FR,
    de_DE,
    el_GR,
    hu_HU,
    ga_IE,
    it_IT,
    ja_JP,
    ko_KR,
    lv_LV,
    lt_LT,
    nb_NO,
    pl_PL,
    pt_BR,
    pt_PT,
    ro_RO,
    ru_RU,
    sr_Cyrl,
    sk_SK,
    es_ES,
    es_MX,
    es_419,
    sv_SE,
    th_TH,
    tr_TR,
    uk_UA,
    vi_VN
}

These are ISO Codes, but this guide won't go more into what an ISO code is.

Here's the ChatGPT prompt I used to generate the translated strings for the Void Depth Upgrade:

I need some help translating.
I have a string in English, and I want to provide localization for a number of other languages.
So I have one localization file already setup- the English one. It is formatted like this:

ModuleDisplayName=Void Depth Module
ModuleDescription=This upgrade combines advanced alloys with the enigmatic properties of Ghost Weed to achieve extraordinary crush depth capabilities. Stacks.

I need that to be produced for several other languages.
They should follow the same form.
So I want your response to be like this:

[language1]
ModuleDisplayName=[translation] 
ModuleDescription=[translation]

[language2]
ModuleDisplayName=[translation] 
ModuleDescription=[translation]

and so on.

Here are languages I'm targeting:

        bg_BG,
        zh_CN,
        zh_Hant,
        hr_HR,
        cs_CZ,
        da_DK,
        nl_BE,
        en_US,
        et_EE,
        fi_FI,
        fr_FR,
        de_DE,
        el_GR,
        hu_HU,
        ga_IE,
        it_IT,
        ja_JP,
        ko_KR,
        lv_LV,
        lt_LT,
        nb_NO,
        pl_PL,
        pt_BR,
        pt_PT,
        ro_RO,
        ru_RU,
        sr_Cyrl,
        sk_SK,
        es_ES,
        es_MX,
        es_419,
        sv_SE,
        th_TH,
        tr_TR,
        uk_UA,
        vi_VN

Please translate these two strings for all these languages now, using the format I described above!

Once you have your translations, they should be put into individual files in a folder called "Localization," like this:

https://github.com/NeisesMike/VehicleFramework/blob/main/Images/localization1.png https://github.com/NeisesMike/VehicleFramework/blob/main/Images/localization2.png

To be clear, every translation pair should be on its own line. Like this:

StringName=String text
OtherStringName=Other string text

The value on the left should be an exact match for a value in the enum type you defined in step 1. There should be no space before or after the "=" sign. If you need to include a newline, use the "\n" symbol, like this:

TooFast=Velocity is too great.\nTo auto-brake, double tap 

Invoke VehicleFramework.Localization.Localizer.GetString

To use the localization system, invoke:

string localizedText = VehicleFramework.Localization.Localizer<YourEnumName>.GetString(YourEnumName.YourEnumValue);

For example, the Void Depth Upgrade does this, using the enum I defined above:

VehicleFramework.Localization.Localizer<EnglishString>.GetString(EnglishString.ModuleDisplayName);

And that's it! Vehicle Framework takes care of everything else, which includes:

  • knowing what language the player has chosen
  • loading your localization files
  • dereferencing your localized string

There's something important to note. Sometimes, a string is read one time and registered for the duration of the game being open. This can result in strings apparently localizing incorrectly, and it can be remedied by rebooting the game. For example, the Void Depth Upgrade localization happens once at boot, when the upgrade Craftable is registered with Nautilus.