Skip to content

Commit

Permalink
Fix Localizations and Translations in Obfuscated Environment
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jan 25, 2024
1 parent a99b48b commit e38264e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/main/java/com/nomiceu/nomilabs/util/LabsTranslate.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.nomiceu.nomilabs.util;

import gregtech.client.utils.TooltipHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.TextFormatting;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

@SuppressWarnings("unused")
Expand All @@ -14,13 +14,9 @@ public static String translate(String key, Object... params) {

public static String translateWithBackup(String key, String backup, Object... params) {
if (LabsSide.isDedicatedServer()) return backup; // I18n is not available on Dedicated Servers
// Try Translating Indirectly
try {
return (String) Class.forName("net.minecraft.client.resources.I18n")
.getMethod("format", String.class, Object[].class)
.invoke(null, key, params);
} catch (ClassNotFoundException | NoSuchMethodException
| InvocationTargetException | IllegalAccessException | ClassCastException e) {
return I18n.format(key, params);
} catch (Exception e) {
return backup;
}
}
Expand Down

0 comments on commit e38264e

Please sign in to comment.