Fabric API

Fabric API

106M Downloads

[Sugesstion] Add Server Side Language Support

SmushyTaco opened this issue ยท 14 comments

commented

Being able to check through code what language a player is using server side and being able to use lang files for easy mutli lingual support for server side related things like commands could be very beneficial. If a player doesn't have fabric installed of course there would have to be something to default to so a default_language entry in the fabric.mod.json could be used for that to select what language to default to. For example:

{
  "default_language": "en_us"
}

would default to English.

Having support of this level would allow developers to do a lot more with their server side mods, for example if it could be checked through code server side a mod developer could use that to:

  1. Automatically translate messages from other languages to the language you have selected in your settings.
  2. Add a prefix next to your name with the language you speak so other players know.
  3. Make chat rooms for each language and put you in your selected language by default.

and whatever else they'd like to do with that functionality.

commented

For server side translations for mods, Server Translation API exists

commented

A big issue here is mods that use TranslatableText everywhere, but that don't have their translations loaded on the server, resulting in the entire mod becoming unreadable from the dedicated server console. FWIW, those mods are also unusable for players who don't have the mod / a resource pack installed, but let's ignore that for now (as making bukkit-plugin-like mods is not super popular yet).

I would be happy to have some (or all) of https://github.com/LoganDark/fabric-languagehack incorporated into fabric-resource-loader-v0, or a new API module. It also solves the second issue, but mods have to explicitly opt into using SSTranslatableText (server-side TranslatableText), because doing this for all TranslatableText would demolish the clients' ability to set their own language (same for mods that expect to be installed on the client as well).

Note that this is not exactly identical to the topic of the issue (which is allowing dedicated servers to set their language to something other than English), but it's a related concern that also can be solved right now without too much bikeshedding.

commented

See #2668

commented

To clarify how a default language should work:
There would be a default provided in the server.properties to specify the server's default language and the default language specified in the fabric.mod.json would be used if the mod didn't support the server's default or if the server didn't provide a default. If the mod or the server don't provide a default then English should be what's defaulted to.

The default would only be used if a player is on a vanilla client or if the players selected language isn't supported.

commented

There is a fundamental problem with your proposal.

The translation functionality of minecraft is not available on the dedicated server.
i.e. The relevant minecraft classes are not in the server jar shipped by mojang.

Also, the language files themselves are stored in resource packs which never get processed by the server.

commented

Vanilla server doesn't have translation support too; it only has American English language.

commented

Seems the dedicated server never loads the lang files provided by mods?

commented

Seems the dedicated server never loads the lang files provided by mods?

Yes, see #1501


On a side note, vanilla dedicated server doesn't even ship non-en_us language files

commented

Couldn't Fabric Loader possibly be used to load the needed language files and classes the server would need for this to work?

commented

A much easier solution: players use a command to set the language for server messages, for example /language set en_us. Can be offhanded to a common third party API if multiple server-side mods make use of this functionality.

No need to hijack loader or API for this.

commented

Couldn't Fabric Loader

Fyi loader only loads mods and set up minecraft for modding. All actual modding and loading of mod content or minecraft content is done by mods, in this case the api (possibly the resource one).

A third-party mod indeed can accomplish this functionality and I agree that is a better approach as api doesn't try to add extra translation to vanilla server. However, Imo we still need #1501 as otherwise translatable text is not properly translated on the server.

commented

Yes, #1501 is useful, and not really related to this.

commented

Where are vanilla lang from? We can read https://launchmeta.mojang.com/mc/game/version_manifest.json, then version.json, then assets-version.json and look for minecraft/lang/preferred_language.json.

Download them when server starts (before world loads). Update version_manifest.json every time server starts, and checksum version.json and assets-version.json in order to check update. You can manually force-update with /language update *.

Edit: later this week I'll give a PR about this.

commented

I don't think our game component is currently downloading anything from the remote, and security is a concern... In addition, this won't work for non-launchermeta versions like combat tests.