Skip to content

Conversation

@Novampr
Copy link
Contributor

@Novampr Novampr commented Sep 30, 2025

Allows extensions to register new translation strings (by placing the language files with the extension's resources or via code)

Parameters use Minecraft Java's translation parameter system.

Example (src/main/resources/languages/en_US.properties) :

test.translation=Test Translation!
test.parameters=Geyser is so cool! Don't you agree %0$s?

Send a translated message

// connection is a GeyserConnection
connection.sendTranslatedMessage("test.translation");

Get a translated string

String locale = GeyserApi.api().getDefaultLocale();

String translatedMessage = GeyserApi.api().getTranslationString(locale, "test.translation");
String translatedFallbackMessage = GeyserApi.api().getTranslationStringOrDefault(locale, "test.translation", "Fallback :(");
String translatedParameteredMessage = GeyserApi.api().getTranslationStringOrDefault(locale, "test.parameters", "%0$s, this is a fallback message, your language did not have a translation :(", "Player");

logger().info(translatedMessage);

Registering translations via code

@Subscribe
public void registerTranslations(GeyserDefineCustomTranslationsEvent event) {
    event.register(localeManager -> {
        String locale = localeManager.getLocaleCode();
        if (locale.equals("en_us")) { // This mess is why the property files exist, lots of if branches otherwise
            localeManager.registerTranslationString("test.translation2", "United States");
        }
    });
}

TODO:

  • Allow registering translations
  • Allow translations from property files
  • Add a way to access translations in API
  • Add parameters to translation strings

@Novampr Novampr marked this pull request as ready for review October 1, 2025 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant