-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6b74d1
commit 28a0182
Showing
5 changed files
with
56 additions
and
51 deletions.
There are no files selected for viewing
34 changes: 0 additions & 34 deletions
34
api/src/main/java/fr/catcore/server/translations/api/mixin/client/I18nMixin.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
api/src/main/java/fr/catcore/server/translations/api/mixin/client/TranslatableTextMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package fr.catcore.server.translations.api.mixin.client; | ||
|
||
import fr.catcore.server.translations.api.resource.language.SystemDelegatedLanguage; | ||
import net.minecraft.text.StringVisitable; | ||
import net.minecraft.text.TranslatableText; | ||
import net.minecraft.text.TranslationException; | ||
import net.minecraft.util.Language; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(TranslatableText.class) | ||
public abstract class TranslatableTextMixin { | ||
|
||
@Shadow @Nullable private Language languageCache; | ||
|
||
@Shadow @Final private List<StringVisitable> translations; | ||
|
||
@Shadow @Final private String key; | ||
|
||
@Shadow protected abstract void setTranslation(String translation); | ||
|
||
/** | ||
* @author CatCore | ||
*/ | ||
@Overwrite | ||
private void updateTranslations() { | ||
Language language = Language.getInstance(); | ||
if (language instanceof SystemDelegatedLanguage delegatedLanguage && delegatedLanguage.languageChanged()) { | ||
this.languageCache = language; | ||
this.translations.clear(); | ||
String string = language.get(this.key); | ||
|
||
try { | ||
this.setTranslation(string); | ||
} catch (TranslationException var4) { | ||
this.translations.clear(); | ||
this.translations.add(StringVisitable.plain(string)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters