|
15 | 15 | import java.util.Collections;
|
16 | 16 | import java.util.HashMap;
|
17 | 17 | import java.util.Map;
|
| 18 | +import java.util.function.Predicate; |
18 | 19 | import java.util.regex.Pattern;
|
19 | 20 |
|
20 | 21 | /**
|
@@ -145,4 +146,37 @@ public Map<String, String> getAllTranslations() {
|
145 | 146 | public String getLocalisation(final String key, final String fallback) {
|
146 | 147 | return translations.getOrDefault(key, fallback);
|
147 | 148 | }
|
| 149 | + |
| 150 | + /** |
| 151 | + * Clear all the translations |
| 152 | + * <br> |
| 153 | + * Warning, this clears <b>ALL</b> the translations, from all mods that have registered up until this point. |
| 154 | + * This method was mainly added for testing reasons, so don't go misusing it. |
| 155 | + * <br> |
| 156 | + * If you really need to clear some translations, you should probably use {@link DatLocalisation#removeTranslation(String)} |
| 157 | + * or {@link DatLocalisation#removeTranslations(Predicate)} |
| 158 | + * @see DatLocalisation#removeTranslation(String) |
| 159 | + * @see DatLocalisation#removeTranslations(Predicate) |
| 160 | + */ |
| 161 | + public void clearTranslations() { |
| 162 | + translations.clear(); |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Remove the translation with the matching key |
| 167 | + * @see DatLocalisation#removeTranslations(Predicate) |
| 168 | + * @param key The key of the translation to remove |
| 169 | + */ |
| 170 | + public void removeTranslation(final String key) { |
| 171 | + translations.remove(key); |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Remove any translations that match the given predicate |
| 176 | + * @see DatLocalisation#removeTranslation(String) |
| 177 | + * @param predicate The predicate that determines if a key should be removed |
| 178 | + */ |
| 179 | + public void removeTranslations(final Predicate<String> predicate) { |
| 180 | + translations.keySet().removeIf(predicate); |
| 181 | + } |
148 | 182 | }
|
0 commit comments