use of net.coderbot.iris.shaderpack.LanguageMap in project Iris by IrisShaders.
the class LanguageMapTest method testLoadLanguages.
@Test
void testLoadLanguages() {
ShaderPack shaderPack;
// ensure that we can actually load the shader pack
try {
shaderPack = new ShaderPack(IrisTests.getTestShaderPackPath("language_maps"));
} catch (Exception e) {
Assertions.fail("Couldn't load test shader pack language_maps", e);
return;
}
// ensure that we only loaded two language files
LanguageMap languageMap = shaderPack.getLanguageMap();
Assertions.assertEquals(2, languageMap.getLanguages().size(), "number of languages loaded");
// test that en_US.lang was loaded properly
{
Map<String, String> english = languageMap.getTranslations("en_us");
Assertions.assertNotNull(english, "en_us translations");
Assertions.assertEquals(2, english.size(), "number of translations in en_US.lang");
Assertions.assertEquals("Test screen", english.get("screen.TEST"));
Assertions.assertEquals("Test option", english.get("option.TEST_OPTION"));
}
// test that fr_FR.lang was loaded properly
{
Map<String, String> french = languageMap.getTranslations("fr_fr");
Assertions.assertNotNull(french, "fr_fr translations");
Assertions.assertEquals(1, french.size(), "number of translations in fr_FR.lang");
Assertions.assertEquals("Écran de test", french.get("screen.TEST"));
}
}
use of net.coderbot.iris.shaderpack.LanguageMap in project Iris by IrisShaders.
the class MixinClientLanguage method iris$lookupOverriddenEntry.
@Unique
private String iris$lookupOverriddenEntry(String key) {
ShaderPack pack = Iris.getCurrentPack().orElse(null);
if (pack == null) {
// This prevents a cryptic NullPointerException when shaderpack loading fails for some reason.
return null;
}
// Minecraft loads the "en_us" language code by default, and any other code will be right after it.
//
// So we also check if the user is loading a special language, and if the shaderpack has support for that
// language. If they do, we load that, but if they do not, we load "en_us" instead.
LanguageMap languageMap = pack.getLanguageMap();
if (storage.containsKey(key)) {
// TODO: Should we allow shader packs to override existing MC translations?
return null;
}
for (String code : languageCodes) {
Map<String, String> translations = languageMap.getTranslations(code);
if (translations != null) {
String translation = translations.get(key);
if (translation != null) {
return translation;
}
}
}
return null;
}
Aggregations