stargate-rewritten / Stargate-Bukkit

The original, and still the best, survival-friendly portal plugin.
https://sgrewritten.org/paper
GNU Lesser General Public License v3.0
30 stars 12 forks source link

Configuration Localisation #284

Open Pheotis opened 1 year ago

Pheotis commented 1 year ago

When we get around to a full release, we will need to handle config localisation for non-english distribution channels.

The config system is currently finicky, so it will probably be a slight pain to implement. When we get around to it, this file should help:

config_foreign_format.zip

Thorinwasher commented 8 months ago

I probably have asked this question before, but how exactly do we know the language to be localized? Although this will be a mess, here's actually one solution:

  1. Load the language from the config
  2. Check against an internally stored property whether this language has been set already
  3. If that was not the case, load the translated configuration comments into the old config file without removing config data
  4. Store an internal property that the modified language has been set

The hard part here of course is number 3.

This is the only behavior that I can see working; the configuration will have to be English initially, as there's no good reliable way to check the localization on a server. Like the server does not have to be located in the same region as that of the server owner. I really see no other reliable way, but let me see if I can find system properties that might give something interesting

Thorinwasher commented 8 months ago

There is apparently the

Locale.getDefault();

But I'm unsure how reliable it is. It's quite hard to know what the system owner wants from that setting. For example I myself would like the configuration to be in English, even though my locale would be Swedish. There's no way for the system to know that. Therefore I suggest not using that property

EpicKnarvik97 commented 8 months ago
3. If that was not the case, load the translated configuration comments into the old config file without removing config data

The migrator has some code which ensures that the comments of the updated config.yml is used, but values are taken from the user's configuration, after the keys have been updated. It should be possible to do the same for changing the configuration language. We should be able to copy (or generalize) that code from the migrator and use the user's current configuration as the input, and the translated configuration file as the one to take comments from.

Thorinwasher commented 8 months ago

Yeah, I suppose it's mostly copy and paste, but I'm still scared to touch that code. But what must be done, must be done.