mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 18:45:09 +00:00
Added ability to query the Language Registry by key and language for specific localized text, as well as loading in localization text from a specific file/URL
This commit is contained in:
1 parent
f0837070d6
commit
8dac58ffc1
1 file changed
+80
-6
@@ -1,5 +1,8 @@
|
|||||||
package cpw.mods.fml.common.registry;
|
package cpw.mods.fml.common.registry;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@@ -20,6 +23,25 @@ public class LanguageRegistry
|
|||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getStringLocalization(String key)
|
||||||
|
{
|
||||||
|
return getStringLocalization(key, StringTranslate.getInstance().getCurrentLanguage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringLocalization(String key, String lang)
|
||||||
|
{
|
||||||
|
String localizedString = "";
|
||||||
|
Properties langPack = modLanguageData.get(lang);
|
||||||
|
|
||||||
|
if (langPack != null) {
|
||||||
|
if (langPack.getProperty(key) != null) {
|
||||||
|
localizedString = langPack.getProperty(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return localizedString;
|
||||||
|
}
|
||||||
|
|
||||||
public void addStringLocalization(String key, String value)
|
public void addStringLocalization(String key, String value)
|
||||||
{
|
{
|
||||||
addStringLocalization(key, "en_US", value);
|
addStringLocalization(key, "en_US", value);
|
||||||
@@ -33,13 +55,28 @@ public class LanguageRegistry
|
|||||||
}
|
}
|
||||||
langPack.put(key,value);
|
langPack.put(key,value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addStringLocalization(Properties langPackAdditions) {
|
||||||
|
addStringLocalization(langPackAdditions, "en_US");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addStringLocalization(Properties langPackAdditions, String lang) {
|
||||||
|
Properties langPack = modLanguageData.get(lang);
|
||||||
|
if (langPack == null) {
|
||||||
|
langPack = new Properties();
|
||||||
|
modLanguageData.put(lang, langPack);
|
||||||
|
}
|
||||||
|
if (langPackAdditions != null) {
|
||||||
|
langPack.putAll(langPackAdditions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void reloadLanguageTable()
|
public static void reloadLanguageTable()
|
||||||
{
|
{
|
||||||
// reload language table by forcing lang to null and reloading the properties file
|
// reload language table by forcing lang to null and reloading the properties file
|
||||||
String lang = StringTranslate.func_74808_a().func_74811_c();
|
String lang = StringTranslate.getInstance().getCurrentLanguage();
|
||||||
StringTranslate.func_74808_a().field_74813_d = null;
|
StringTranslate.getInstance().currentLanguage = null;
|
||||||
StringTranslate.func_74808_a().func_74810_a(lang);
|
StringTranslate.getInstance().setLanguage(lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -47,11 +84,11 @@ public class LanguageRegistry
|
|||||||
{
|
{
|
||||||
String objectName;
|
String objectName;
|
||||||
if (objectToName instanceof Item) {
|
if (objectToName instanceof Item) {
|
||||||
objectName=((Item)objectToName).func_77658_a();
|
objectName=((Item)objectToName).getItemName();
|
||||||
} else if (objectToName instanceof Block) {
|
} else if (objectToName instanceof Block) {
|
||||||
objectName=((Block)objectToName).func_71917_a();
|
objectName=((Block)objectToName).getBlockName();
|
||||||
} else if (objectToName instanceof ItemStack) {
|
} else if (objectToName instanceof ItemStack) {
|
||||||
objectName=((ItemStack)objectToName).func_77973_b().func_77667_c((ItemStack)objectToName);
|
objectName=((ItemStack)objectToName).getItem().getItemNameIS((ItemStack)objectToName);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(String.format("Illegal object for naming %s",objectToName));
|
throw new IllegalArgumentException(String.format("Illegal object for naming %s",objectToName));
|
||||||
}
|
}
|
||||||
@@ -76,4 +113,41 @@ public class LanguageRegistry
|
|||||||
}
|
}
|
||||||
languagePack.putAll(langPack);
|
languagePack.putAll(langPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadLocalization(String localizationFile, String lang, boolean isXML)
|
||||||
|
{
|
||||||
|
loadLocalization(this.getClass().getResource(localizationFile), lang, isXML);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadLocalization(URL localizationFile, String lang, boolean isXML)
|
||||||
|
{
|
||||||
|
InputStream langStream = null;
|
||||||
|
Properties langPack = new Properties();
|
||||||
|
|
||||||
|
try {
|
||||||
|
langStream = localizationFile.openStream();
|
||||||
|
|
||||||
|
if (isXML) {
|
||||||
|
langPack.loadFromXML(langStream);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
langPack.load(langStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
addStringLocalization(langPack, lang);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (langStream != null) {
|
||||||
|
langStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user