Managing resource files in Unity

Hi, I’m making my first videogame in Unity. I want it to be available in multiple languages, so I created this:

using UnityEngine;
using System.Collections.Generic;

[System.Serializable]
internal class LanguageStrings : Dictionary<string, string>
{
}

public static class LanguageSystem
{
    public static Language language { get; private set; }
    private static LanguageStrings strings;

    public static void LoadLanguage(Language lang)
    {
        // Code to load language strings from JSON file...

        language = lang;
    }

    public static string GetString(string key)
    {
        return !(strings == null || !strings.ContainsKey(key)) ? strings[key] : "<invalid>";
    }

    public enum Language
    {
        it,
        en,
        fr,
        de
    }
}

Essentially, whenever text needs to be displayed on screen, instead of displaying a literal string, it gets one from the Language System from a key. Like, for example, if I want to display the “Play” button in the main menu, the text string would be equal to LanguageSystem.GetString("menu_play"), which then returns the “Play” string if the current language is English, or another word if the language is changed.

Now what is the best place to store the strings? Do I write them directly in code (like a public static Dictionary<string, string> english { get; } or in a JSON file (or something else)?

I thought of writing them in JSON files inside a lang folder. But where do I put this folder? Do I just put it into my Assets folder? If I do, what happens to those files when I build the game? Will they appear in the built game folder along with the .exe? Will the code still be able to retrieve the files?
Also, what is the best way to retrieve the files from code? Because I need to load and deserialize the JSON file within the LoadLanguage method. I’ve heard of the Resources class and Resources.Load, but I don’t know how that works and I’ve also heard it’s outdated and that I should use the Addressables system. Took a look at that, and it seems really overkill for this kind of stuff.

Any suggestions? I’m completely new to file and resource management in Unity (and pretty new to Unity in general as well).

My first suggestion is “Don’t bother with localization; it can be a real can of worms.”

If you persist, build on someone else’s hard work, such as the Unity Localization package:

https://docs.unity3d.com/Packages/com.unity.localization@1.0/manual/index.html

Good luck.

There are a lot of localization assets on the asset store, a few that are even free, that may make this process a little easier for you. Just a suggestion to avoid reinventing the wheel.

However, if you want to do this yourself, you can put the json file anywhere you want. Then just create a variable in a script of type TextAsset. Drag and drop the file into the variable in the inspector. Then just retrieve the text from the TextAsset and handle as needed.

Didn’t know it was called Localization (English isn’t my first language). Liked the idea of programming that myself, but if you say it’s complicated, I’ll take a look at the Unity Localization Package.

Also:
@Brathnann I knew I could to that, but adding each language file in the inspector is kind bad in my opinion, I would’ve liked a more automatic way; like, for example, if you want to load German language, it searches in Assets/Languages for de.json

Which is fine. Then there is also nothing wrong with using Addressables for it. It’s not really overkill, since it’s similar to using the Resources folder… but better.