diff --git a/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java b/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java index c12c631..4368e4c 100644 --- a/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java +++ b/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java @@ -3,6 +3,8 @@ import io.wispforest.limelight.api.extension.LimelightExtension; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.Language; +import net.minecraft.util.Util; /** * Represents a result entry in the Limelight GUI. @@ -24,4 +26,15 @@ public sealed interface ResultEntry permits InvokeResultEntry, SetSearchTextEntr * @return the text of this entry */ Text text(); + + /** + * @return the prefix used to identify the extension in the search result. + * @apiNote By default, it'll use the translation if it exists, if it doesn't, it'll use the extension's name + * */ + default Text prefix() { + String key = extension().baseTranslationKey() + ".prefix"; + if (Language.getInstance().hasTranslation(key)) + return Text.translatable(key); + return extension().name(); + } } diff --git a/src/client/java/io/wispforest/limelight/api/extension/LimelightExtension.java b/src/client/java/io/wispforest/limelight/api/extension/LimelightExtension.java index 604e159..aa284c4 100644 --- a/src/client/java/io/wispforest/limelight/api/extension/LimelightExtension.java +++ b/src/client/java/io/wispforest/limelight/api/extension/LimelightExtension.java @@ -24,11 +24,18 @@ public interface LimelightExtension extends ResultEntryGatherer { */ Identifier id(); + /** + * @return the base translation key + * */ + default String baseTranslationKey() { + return Util.createTranslationKey("limelightExtension", id()); + } + /** * @return the name of this extension, to be used in the main and config screens */ default Text name() { - return Text.translatable(Util.createTranslationKey("limelightExtension", id())); + return Text.translatable(baseTranslationKey()); } /** @@ -55,7 +62,7 @@ default List tooltip() { * @return the description of this extension, to be used in the main and config screens */ default @Nullable Text description() { - String key = Util.createTranslationKey("limelightExtension", id()) + ".desc"; + String key = baseTranslationKey() + ".desc"; if (!Language.getInstance().hasTranslation(key)) return null; return Text.translatable(key); } diff --git a/src/client/java/io/wispforest/limelight/impl/ui/ResultEntryComponent.java b/src/client/java/io/wispforest/limelight/impl/ui/ResultEntryComponent.java index 9024b0b..ca0f4cb 100644 --- a/src/client/java/io/wispforest/limelight/impl/ui/ResultEntryComponent.java +++ b/src/client/java/io/wispforest/limelight/impl/ui/ResultEntryComponent.java @@ -50,7 +50,7 @@ public ResultEntryComponent(LimelightScreen screen, ResultEntry entry, boolean i labelBuilder.append( Text.empty() - .append(entry.extension().name()) + .append(entry.prefix()) .styled(x -> x.withColor(isChild ? theme.childSourceExtensionColor() : theme.sourceExtensionColor())) .styled(x -> x.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltipText))) );