mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
temporarily remove pufferfish, closes #1625
This commit is contained in:
72
patches/api/0039-Language-API.patch
Normal file
72
patches/api/0039-Language-API.patch
Normal file
@@ -0,0 +1,72 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MelnCat <melncatuwu@gmail.com>
|
||||
Date: Sat, 1 Oct 2022 17:08:23 -0700
|
||||
Subject: [PATCH] Language API
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/language/Language.java b/src/main/java/org/purpurmc/purpur/language/Language.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..cbdad4cf09c170064a45644efdf7aa0b28608301
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/purpurmc/purpur/language/Language.java
|
||||
@@ -0,0 +1,60 @@
|
||||
+package org.purpurmc.purpur.language;
|
||||
+
|
||||
+import net.kyori.adventure.translation.Translatable;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * Represents a language that can translate translation keys
|
||||
+ */
|
||||
+@NullMarked
|
||||
+public abstract class Language {
|
||||
+ private static @Nullable Language language;
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the default language of the server
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public static Language getLanguage() {
|
||||
+ return language;
|
||||
+ }
|
||||
+
|
||||
+ public static void setLanguage(Language language) {
|
||||
+ if (Language.language != null) {
|
||||
+ throw new UnsupportedOperationException("Cannot redefine singleton Language");
|
||||
+ }
|
||||
+ Language.language = language;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Checks if a certain translation key is translatable with this language
|
||||
+ * @param key The translation key
|
||||
+ * @return Whether this language can translate the key
|
||||
+ */
|
||||
+ abstract public boolean has(String key);
|
||||
+
|
||||
+ /**
|
||||
+ * Checks if a certain translation key is translatable with this language
|
||||
+ * @param key The translation key
|
||||
+ * @return Whether this language can translate the key
|
||||
+ */
|
||||
+ public boolean has(Translatable key) {
|
||||
+ return has(key.translationKey());
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Translates a translation key to this language
|
||||
+ * @param key The translation key
|
||||
+ * @return The translated key, or the translation key if it couldn't be translated
|
||||
+ */
|
||||
+ abstract public String getOrDefault(String key);
|
||||
+
|
||||
+ /**
|
||||
+ * Translates a translation key to this language
|
||||
+ * @param key The translation key
|
||||
+ * @return The translated key, or the translation key if it couldn't be translated
|
||||
+ */
|
||||
+ public String getOrDefault(Translatable key) {
|
||||
+ return getOrDefault(key.translationKey());
|
||||
+ }
|
||||
+}
|
||||
Reference in New Issue
Block a user