I literally thought this entire system out WHILE AT WORK over the last week haha! I got super excited multiple times and probably made my coworkers think I'm nuts by yelling things like "AHA!" and "I GOT IT!" and "This is gonna be GREAT!" out loud.
I work in a warehouse, noise isn't exactly a concern 🤣
Anyway, here's my infodump:

This is how the entries I can modify from the inspector window are structured internally. Pretty straight forward, LangEntry's contain an internal name and an array of LangDefinitions which represent the definition of that entry in a specified language.

As you might expect, the first member of the LangManager class (the script that is attached to an object in the scene through which I can define lang entries from the inspector window) is a serialized array of LangEntries, however, for the sake of ease of access by other scripts, I changed the hierarchy relating entry names to languages to definitions a bit from how it functions in the inspector window internally. What's happening in this snippet is probably a bit difficult to follow intuitively if you're new to programming, but what is happening here is all of the string data contained in the Entries array (the language names, entry names, and definitions) is copied into a hierarchy of dictionaries. The outermost dictionary maps language names to inner-dictionaries that map lang entry names to their definitions in that language (if they exist).

This copying of data from the LangEntry array I modify from the inspector from to internal dictionaries might seem pointless at first, however, this is actually a best of both worlds scenario. It allows me not only to easily add new definitions for an existing lang entry in other languages but get the definition of that entry in the user's current language without needing to loop through every entry and it's definitions to find it!

The only drawback to this approach is that I cannot modify the game's lang during runtime as the internal dictionaries are constructed on awake, but, at the same time, I cannot imagine a situation in which I'll HAVE to so that should be fine.













3 comments