Managing natural languages through inheritance

Hello. I’m relatively new to Unity and C#. I was hoping for advice on the subject of managing natural languages. I’d like for the user to have a drop-down menu in preferences to select between say, English and Spanish.

My instinct is to have separate files for each language. I’d have a default class called Language:

public class Language : MonoBehaviour {
public string text_greeting = “Hello world”;
}

and then other languages would inherit from it

public class Spanish : Language {
public string text_greeting = “Hola mundo”;
}

and then in my scene instantiate a Language and print chosenLanguage.text_greeting

Now there MUST be a more elegant way to do this. Or maybe even a built-in way that I’ve overlooked? I’m simply storing variables; is MonoBehaviour overkill? I appreciate your input, o wise Unity community!

You do not want to define your strings manually in code. Use, for example, a text file instead, and load the language string you need at runtime.

This is called localization.

If you don’t want to write your own implementation, there are also some plugins in the asset store to help with localization.

A good way to go, is to use an Excel file to keep your strings with translations. Then export it to a custom asset and read the file at runtime. You could also use a little database.

Furthermore, you could add string resources to a custom C# DLL.

Good luck!