Localization is done, see the format of the en_US.xml file for how to specify your own custom localization files. Feel free to contribute your translations to the GitHub as appropriate.
This commit is contained in:
parent
cabe68356d
commit
d2c456b76f
9 changed files with 182 additions and 16 deletions
|
@ -23,6 +23,7 @@ import ee3.common.core.handlers.AddonHandler;
|
||||||
import ee3.common.core.handlers.ConfigurationHandler;
|
import ee3.common.core.handlers.ConfigurationHandler;
|
||||||
import ee3.common.core.handlers.EntityLivingHandler;
|
import ee3.common.core.handlers.EntityLivingHandler;
|
||||||
import ee3.common.core.handlers.ItemPickupHandler;
|
import ee3.common.core.handlers.ItemPickupHandler;
|
||||||
|
import ee3.common.core.handlers.LocalizationHandler;
|
||||||
import ee3.common.core.handlers.PacketHandler;
|
import ee3.common.core.handlers.PacketHandler;
|
||||||
import ee3.common.core.handlers.PlayerDestroyItemHandler;
|
import ee3.common.core.handlers.PlayerDestroyItemHandler;
|
||||||
import ee3.common.core.handlers.VersionCheckTickHandler;
|
import ee3.common.core.handlers.VersionCheckTickHandler;
|
||||||
|
@ -72,6 +73,9 @@ public class EquivalentExchange3 {
|
||||||
@Init
|
@Init
|
||||||
public void load(FMLInitializationEvent event) {
|
public void load(FMLInitializationEvent event) {
|
||||||
|
|
||||||
|
// Load the localization files into the LanguageRegistry
|
||||||
|
LocalizationHandler.loadLanguages();
|
||||||
|
|
||||||
// Initialize the custom item rarity types
|
// Initialize the custom item rarity types
|
||||||
proxy.initCustomRarityTypes();
|
proxy.initCustomRarityTypes();
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,6 @@ public class ModBlocks {
|
||||||
redWaterStill = new BlockRedWaterStill(BlockIds.RED_WATER_STILL, Material.water);
|
redWaterStill = new BlockRedWaterStill(BlockIds.RED_WATER_STILL, Material.water);
|
||||||
redWaterFlowing = new BlockRedWaterFlowing(BlockIds.RED_WATER_STILL - 1, Material.water);
|
redWaterFlowing = new BlockRedWaterFlowing(BlockIds.RED_WATER_STILL - 1, Material.water);
|
||||||
|
|
||||||
LanguageRegistry.addName(calcinator, "Calcinator");
|
|
||||||
LanguageRegistry.addName(redWaterStill, "Red Water (Still)");
|
|
||||||
LanguageRegistry.addName(redWaterFlowing, "Red Water (Flowing)");
|
|
||||||
|
|
||||||
GameRegistry.registerBlock(calcinator);
|
GameRegistry.registerBlock(calcinator);
|
||||||
GameRegistry.registerBlock(redWaterStill);
|
GameRegistry.registerBlock(redWaterStill);
|
||||||
GameRegistry.registerBlock(redWaterFlowing);
|
GameRegistry.registerBlock(redWaterFlowing);
|
||||||
|
|
|
@ -1,5 +1,70 @@
|
||||||
package ee3.common.core.handlers;
|
package ee3.common.core.handlers;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Properties;
|
||||||
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||||
|
import ee3.common.core.helper.LocalizationHelper;
|
||||||
|
import ee3.common.lib.Localizations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LocalizationHandler
|
||||||
|
*
|
||||||
|
* Loads in all specified localizations for the mod
|
||||||
|
*
|
||||||
|
* @author pahimar
|
||||||
|
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class LocalizationHandler {
|
public class LocalizationHandler {
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Loads in all the localization files from the Localizations library class
|
||||||
|
*/
|
||||||
|
public static void loadLanguages() {
|
||||||
|
InputStream languageStream = null;
|
||||||
|
Properties languageMappings = new Properties();
|
||||||
|
Iterator<String> keyIter = null;
|
||||||
|
String currentKey, currentLang;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// For every file specified in the Localization library class, load them into the Language Registry
|
||||||
|
for (String localizationFile : Localizations.localeFiles) {
|
||||||
|
languageStream = LocalizationHandler.class.getResourceAsStream(localizationFile);
|
||||||
|
|
||||||
|
// If this file is a XML file, load it from XML
|
||||||
|
if (LocalizationHelper.isXMLLanguageFile(localizationFile)) {
|
||||||
|
languageMappings.loadFromXML(languageStream);
|
||||||
|
}
|
||||||
|
// Otherwise, load it like any other Java Properties file
|
||||||
|
else {
|
||||||
|
languageMappings.load(languageStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the locale from the file name of the localization file
|
||||||
|
currentLang = LocalizationHelper.getLocaleFromFileName(localizationFile);
|
||||||
|
|
||||||
|
// For every key in the localization file, add its key:value pair to the Language Registry for the given locale
|
||||||
|
keyIter = (Iterator<String>)languageMappings.keys();
|
||||||
|
while (keyIter.hasNext()) {
|
||||||
|
currentKey = keyIter.next();
|
||||||
|
LanguageRegistry.instance().addStringLocalization(currentKey, currentLang, languageMappings.getProperty(currentKey));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (languageStream != null) {
|
||||||
|
languageStream.close();
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
73
ee3_common/ee3/common/core/helper/LocalizationHelper.java
Normal file
73
ee3_common/ee3/common/core/helper/LocalizationHelper.java
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
package ee3.common.core.helper;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Properties;
|
||||||
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||||
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||||
|
import net.minecraft.src.StringTranslate;
|
||||||
|
import ee3.common.core.handlers.LocalizationHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LocalizationHelper
|
||||||
|
*
|
||||||
|
* Helper class for looking up localized strings in the Language Registry
|
||||||
|
*
|
||||||
|
* @author pahimar
|
||||||
|
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LocalizationHelper {
|
||||||
|
|
||||||
|
// The language data field name for localization data in the Language Registry
|
||||||
|
private static final String LANGUAGE_REGISTRY_LANGUAGE_DATA_FIELD = "modLanguageData";
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Returns the localized version of the text represented by key for the current language from the Language Registry
|
||||||
|
* @param key The key that represents the text we are attempting to localize
|
||||||
|
* @return The localized string for the specified key for the current language, null if no localized version of the key exists in the Language Registry
|
||||||
|
*/
|
||||||
|
public static String localize(String key) {
|
||||||
|
return localize(StringTranslate.getInstance().getCurrentLanguage(), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Returns the localized version of the text represented by key for the specified language from the Language Registry
|
||||||
|
* @param language The language for which to search for the localized version of the key
|
||||||
|
* @param key The key that represents the text we are attempting to localize
|
||||||
|
* @return The localized string for the specified key for the specified language, null if no localized version of the key exists in the Language Registry
|
||||||
|
*/
|
||||||
|
public static String localize(String language, String key) {
|
||||||
|
String localizedValue = "";
|
||||||
|
HashMap<String,Properties> modLanguageData = null;
|
||||||
|
Properties languageMapping = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
modLanguageData = ReflectionHelper.getPrivateValue(cpw.mods.fml.common.registry.LanguageRegistry.class, LanguageRegistry.instance(), LANGUAGE_REGISTRY_LANGUAGE_DATA_FIELD);
|
||||||
|
languageMapping = modLanguageData.get(language);
|
||||||
|
localizedValue = languageMapping.getProperty(key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return localizedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Simple test to determine if a specified file name represents a XML file or not
|
||||||
|
* @param fileName String representing the file name of the file in question
|
||||||
|
* @return True if the file name represents a XML file, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isXMLLanguageFile(String fileName) {
|
||||||
|
return fileName.endsWith(".xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Returns the locale from file name
|
||||||
|
* @param fileName String representing the file name of the file in question
|
||||||
|
* @return String representation of the locale snipped from the file name
|
||||||
|
*/
|
||||||
|
public static String getLocaleFromFileName(String fileName) {
|
||||||
|
return fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -35,8 +35,5 @@ public class ModItems {
|
||||||
miniumStone.setContainerItem(miniumStone);
|
miniumStone.setContainerItem(miniumStone);
|
||||||
philStone.setContainerItem(philStone);
|
philStone.setContainerItem(philStone);
|
||||||
|
|
||||||
LanguageRegistry.addName(miniumShard, "Shard of Minium");
|
|
||||||
LanguageRegistry.addName(miniumStone, "Minium Stone");
|
|
||||||
LanguageRegistry.addName(philStone, "Philosophers Stone");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
20
ee3_common/ee3/common/lib/Localizations.java
Normal file
20
ee3_common/ee3/common/lib/Localizations.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package ee3.common.lib;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BlockIds
|
||||||
|
*
|
||||||
|
* Library containing all mod language related files
|
||||||
|
*
|
||||||
|
* @author pahimar
|
||||||
|
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Localizations {
|
||||||
|
|
||||||
|
private static final String LANG_RESOURCE_LOCATION = "/ee3/lang/";
|
||||||
|
|
||||||
|
public static String[] localeFiles = {
|
||||||
|
LANG_RESOURCE_LOCATION + "en_US.xml"
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -40,10 +40,11 @@ public class Reference {
|
||||||
|
|
||||||
/* Texture related constants */
|
/* Texture related constants */
|
||||||
public static final String SPRITE_SHEET_LOCATION = "/ee3/art/sprites/";
|
public static final String SPRITE_SHEET_LOCATION = "/ee3/art/sprites/";
|
||||||
|
public static final String ARMOR_SHEET_LOCATION = "/ee3/art/armor/";
|
||||||
|
public static final String GUI_SHEET_LOCATION = "/ee3/art/gui/";
|
||||||
public static final String ITEM_SPRITE_SHEET = "ee3_items.png";
|
public static final String ITEM_SPRITE_SHEET = "ee3_items.png";
|
||||||
public static final String BLOCK_SPRITE_SHEET = "ee3_blocks.png";
|
public static final String BLOCK_SPRITE_SHEET = "ee3_blocks.png";
|
||||||
public static final String GUI_SHEET_LOCATION = "/ee3/art/gui/";
|
|
||||||
public static final String ARMOR_SHEET_LOCATION = "/ee3/art/armor/";
|
|
||||||
|
|
||||||
public static final int SECOND_IN_TICKS = 20;
|
public static final int SECOND_IN_TICKS = 20;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
item.miniumShard=Minium Shard
|
|
||||||
item.miniumStone=Minium Stone
|
|
||||||
item.philosophersStone=Philosophers Stone
|
|
||||||
tile.redWaterStill=Red Water
|
|
||||||
tile.redWaterFlowing=Red Water
|
|
15
resources/ee3/lang/en_US.xml
Normal file
15
resources/ee3/lang/en_US.xml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||||
|
<properties version="1.0">
|
||||||
|
<comment>English (US) Localization File</comment>
|
||||||
|
<entry key="item.miniumShard.name">Shard of Minium</entry>
|
||||||
|
<entry key="item.miniumStone.name">Minium Stone</entry>
|
||||||
|
<entry key="item.philStone.name">Philosophers Stone</entry>
|
||||||
|
<entry key="tile.redWaterStill.name">Red Water (Still)</entry>
|
||||||
|
<entry key="tile.redWaterFlowing.name">Red Water (Flowing)</entry>
|
||||||
|
<entry key="tile.calcinator.name">Calcinator</entry>
|
||||||
|
<entry key="version.uninitialized">Uninitialized</entry>
|
||||||
|
<entry key="version.current">Current</entry>
|
||||||
|
<entry key="version.outdated">Outdated</entry>
|
||||||
|
<entry key="version.connection_error">Connection Error</entry>
|
||||||
|
</properties>
|
Loading…
Reference in a new issue