remance / Masendor

Open source educational and historical battle action game, All helps accepted
MIT License
142 stars 31 forks source link

i18n & Translation - Separate game logic from translatable strings #50

Closed RybenHill closed 1 year ago

RybenHill commented 1 year ago

In order to make translation and development easier, separate game logic data from translatable strings in .csv files.

Put the translatable strings files in /masendor/data/module/historical/strings/*_en.csv

remance commented 1 year ago

Any reason for why naming the folder "strings"? Wouldn't it make more sense to just simply name it localisation?

RybenHill commented 1 year ago

well, I made that path suggestion inspired by how M&B manages thousands of translatable in-game text strings, with a smart way that allows new translations to be added and is open for mod creation.

It might be worth having a look at... https://mbmodwiki.github.io/String

Also, we could take into account this library...

https://github.com/MyreMylar/pygame_gui

https://github.com/MyreMylar/pygame_gui_examples

https://pygame-gui.readthedocs.io/en/v_067/

that might be useful for saving a lot of effort when implementing a GUI system for a Pygame project; it already includes its own localization support via python-i18n:

https://pygame-gui.readthedocs.io/en/latest/localization.html

https://github.com/danhper/python-i18n

https://pypi.org/project/python-i18n/

--

remance commented 1 year ago

Ok, now I understand. But for this game I think it would be better to use localisation as folder name to make it more clear. Can you send an example of string file from mount and blade game? Would be useful to see how they structure the file.

RybenHill commented 1 year ago

In Mount and Blade, each game module (include the vanilla module or base game, what we are calling historial atm in our project) contains its own translation files:

module_dialogs.py, module_scripts.py, module_troops.py, module_infopages.py, etc.

Here you can read more about how its made in M&B:

For us, if we are using PygameGUI / python-i18n, the format expected would be something like...

{
  "en": {
    "text_id_whatever": "Hello world! :D"
  }
}

As you can see and test yourself from the PygameGUI examples repo:

https://github.com/MyreMylar/pygame_gui_examples/blob/master/translations_test.py

translations_test.py PygameGUI translation system example

remance commented 1 year ago

So I remember I tried making localisation for UI before. I put the old file in dev branch:

It is not used in game yet but we can use it as a starting point.

https://github.com/remance/Masendor/tree/dev/data/module/historical/localisation

remance commented 1 year ago

So the game now put localisation data separate from other data. They are kept in "localsiation" folder. The localisation files are in the same or similar name as the data. For example troop_status in localsation is for troop_status data. The data is in csv format to make it consistent with other data.

remance commented 1 year ago

Forgot to mention that this change is in dev branch for now.