Ruin0x11 / OpenNefia

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

Move locale files into a namespace per mod #111

Closed Ruin0x11 closed 3 years ago

Ruin0x11 commented 4 years ago

This is similar to what Minecraft does: have a default namespace of base, and let each mod have its own localization namespace separate from it. Therefore, this code:

Gui.mes("ui.inv.common.backpack_is_full")
Gui.mes("autoexplore.pathing.halt.default")

becomes this code:

Gui.mes("base:ui.inv.common.backpack_is_full")
Gui.mes("autoexplore:pathing.halt.default")

Since base will be so commonly used, we would also have the option to omit base: when looking up a localized string/function/list, as before.

Also, we should change the format of locale/ to reflect these namespaces. This is so mods that want to add to a different mod's namespace can organize themselves better.

Before:

locale/en/ui.lua
locale/en/chara.lua
locale/en/autoexplore.lua

After:

locale/en/base/ui.lua
locale/en/_/chara.lua
locale/en/autoexplore/pathing.lua

I am currently thinking that, in relation to #8, there should be a special namespace separate from basewhere the localizations of entries in data should live. (Here it is named _.) If this isn't a good idea, we could just reuse base.

Ruin0x11 commented 3 years ago

I think instead of _ we will just have one namespace per mod. base can be elided when passing in a locale key to I18N.get() and similar, and the rest will be prefixed with a colon.

I18N.get("ui.inv.common.inventory_is_full")
I18N.get("base:ui.inv.common.inventory_is_full") -- equivalent to the above
I18N.get("elona:nefia._.elona.dungeon.name")

If a mod wants to add new things under a namespace for the purpose of localizing the new data entries they add, they will create a folder under locale named with the namespace and put the localizations there.