Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation fallback #2543

Merged
merged 6 commits into from Oct 13, 2023
Merged

Conversation

tal5
Copy link
Member

@tal5 tal5 commented Oct 4, 2023

Adds support for the 1.19 translatable component fallbacks.

Changes

  • Updated the tag to modern <&translate[key=<key>;(fallback=<fallback>);(with=<text>|...)]> syntax.
  • Tried explaining the fact that the translation is done client-side in the meta, to make what fallback does a bit more understandable.
  • Moved the examples into proper @example's, and updated for the new syntax.
  • Made the tag take an ObjectTag as a param, instead of manually doing !hasParam -> return null.
  • Changed the internal format for translatables to &[translate=MapTag], with the map being the same as &translate's input.

Additions

  • BukkitImplDeprecations.translateLegacySyntax - FutureWarning for the legacy &translate syntax.
  • FormattedTextHelper#parseTranslatable - util method since there are 2 places with practically identical logic for parsing them.

Notes

  • Gave the fallback bit of the internal format for translatable components a prefix with the legacy color char, to make sure it's properly differentiated from the with values - let me know if there's a better way to approach this.
  • The feature was added in 1.19, but this is limited to 1.20+ because that's when Spigot updated the bundled Bungeecord chat version.
  • Is there a reason the example for the tag .escapes all of the with values? seemed to work as expected without that, and I think the values' safety should be pretty much guaranteed in this case? as player names are pretty strict and the other is just another translatable - and either way they're passed through FormattedTextHelper#escape later.
  • Removed the .escape's from the example for with, since the entire map is escaped later on, and it doesn't look like they're needed (I assume they were there for legacy list parsing reasons or something?) - all the old code did was immediately unescape them; the old .with sub-tag should still support that for back-support.
  • Not the biggest fan of the startsWith("@map") check in FormattedTextHelper#parseTranslatable, but don't think there's a cleaner way of doing that? maybe substring the raw object prefix and check if it starts with [? or some core method to avoid hard-coding that sort of check in?

}
StringBuilder output = new StringBuilder().append(ChatColor.COLOR_CHAR).append("[translate=").append(FormattedTextHelper.escape(translateText));
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && fallback != null) {
output.append(';').append(ChatColor.COLOR_CHAR).append("fallback=").append(FormattedTextHelper.escape(fallback.asString()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

injecting color_char inside of the block here is problematic

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to be a MapTag as discussed on Discord

@mcmonkey4eva mcmonkey4eva merged commit dfd911d into DenizenScript:dev Oct 13, 2023
1 check passed
@tal5 tal5 deleted the Translation_Fallback branch October 13, 2023 16:48
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.

None yet

2 participants