Ruin0x11 / OpenNefia

(Archived) Moddable engine reimplementation of the Japanese roguelike Elona.
MIT License
116 stars 18 forks source link

Standardize localization conventions for data types #8

Open Ruin0x11 opened 4 years ago

Ruin0x11 commented 4 years ago

It is a very common need to attach some localized strings to data entries, like character names. Currently the namespacing for this in locale files is not standardized. It should be consistent across all data types, to make it clear to modders that the strings belong to a data type.

One example of this could be:

_.base.scenario.my_mod.test_scenario.name

Here, the format is as follows:

_.<data_type>.<data_id>.<key>

Laying out the localization like this would allow for creating APIs that unify localizing data entries, perhaps like this:

local name = data["base.chara"]:localize("elona.putit").name

This would be generic across everything in data without the need to write a special function for every single data type.

Ruin0x11 commented 3 years ago

The format I'm now thinking of is: Use the mod that defines the type as the localization namespace (as in #111), and put all the data entry localizations under the prefix <data type name>._<data type ID>. This makes it easy to remember that a type of elona.nefia will have keys like elona:nefia._.elona.dungeon.name, and live in a file named mod/elona/locale/en/elona/nefia.lua.

With this standardized, we could also optimize localization retrieval and stop concatting strings every time a localization for data entries are needed. Once all mods have been loaded, there could be an index built that keeps the namespace, data type name, data entry ID, and keys in separate tables.