DeprecatedTranslationsInfo .java

net.minecraft.locale.DeprecatedTranslationsInfo (record): members: removed, renamed, loadFromDefaultResource, loadFromResource, loadFromJson, applyToMap.

net.minecraft.localerecord64 linescommon2.3 KB

API Surface (5)

record DeprecatedTranslationsInfo(List<String> removed, Map<String, String> renamed)
DeprecatedTranslationsInfo loadFromJson(final InputStream stream)
DeprecatedTranslationsInfo loadFromResource(final String path)
DeprecatedTranslationsInfo loadFromDefaultResource()
void applyToMap(final Map<String, String> translations)

Fields & Constants (3)

LOGGER
EMPTY
CODEC

String literals (4)

"removed"
"renamed"
"Failed to parse deprecated language data: "
"/assets/minecraft/lang/deprecated.json"

Same Package (2)

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

DeprecatedTranslationsInfo.java64 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.locale;
2
3
import com.google.gson.JsonElement;
4
import com.mojang.logging.LogUtils;
5
import com.mojang.serialization.Codec;
6
import com.mojang.serialization.JsonOps;
7
import com.mojang.serialization.codecs.RecordCodecBuilder;
8
import java.io.InputStream;
9
import java.io.InputStreamReader;
10
import java.nio.charset.StandardCharsets;
11
import java.util.List;
12
import java.util.Map;
13
import net.minecraft.util.StrictJsonParser;
14
import org.slf4j.Logger;
15
16
public record DeprecatedTranslationsInfo(List<String> removed, Map<String, String> renamed) {
17
	private static final Logger LOGGER = LogUtils.getLogger();
18
	public static final DeprecatedTranslationsInfo EMPTY = new DeprecatedTranslationsInfo(List.of(), Map.of());
19
	public static final Codec<DeprecatedTranslationsInfo> CODEC = RecordCodecBuilder.create(
20
		i -> i.group(
21
				Codec.STRING.listOf().fieldOf("removed").forGetter(DeprecatedTranslationsInfo::removed),
22
				Codec.unboundedMap(Codec.STRING, Codec.STRING).fieldOf("renamed").forGetter(DeprecatedTranslationsInfo::renamed)
23
			)
24
			.apply(i, DeprecatedTranslationsInfo::new)
25
	);
26
27
	public static DeprecatedTranslationsInfo loadFromJson(final InputStream stream) {
28
		JsonElement entries = StrictJsonParser.parse(new InputStreamReader(stream, StandardCharsets.UTF_8));
29
		return CODEC.parse(JsonOps.INSTANCE, entries).getOrThrow(msg -> new IllegalStateException("Failed to parse deprecated language data: " + msg));
30
	}
31
32
	public static DeprecatedTranslationsInfo loadFromResource(final String path) {
33
		try (InputStream stream = Language.class.getResourceAsStream(path)) {
34
			if (stream != null) {
35
				return loadFromJson(stream);
36
			}
37
		} catch (Exception e) {
38
			LOGGER.error("Failed to read {}", path, e);
39
		}
40
41
		return EMPTY;
42
	}
43
44
	public static DeprecatedTranslationsInfo loadFromDefaultResource() {
45
		return loadFromResource("/assets/minecraft/lang/deprecated.json");
46
	}
47
48
	public void applyToMap(final Map<String, String> translations) {
49
		for (String key : this.removed) {
50
			translations.remove(key);
51
		}
52
53
		this.renamed.forEach((fromKey, toKey) -> {
54
			String value = translations.remove(fromKey);
55
			if (value == null) {
56
				LOGGER.warn("Missing translation key for rename: {}", fromKey);
57
				translations.remove(toKey);
58
			} else {
59
				translations.put(toKey, value);
60
			}
61
		});
62
	}
63
}
64

Decompiled Minecraft 26.3 source of DeprecatedTranslationsInfo (net/minecraft/locale/DeprecatedTranslationsInfo.java) with Mojang official mappings, stored verbatim on the site.