Skip to content

Instantly share code, notes, and snippets.

@AEnterprise
Created February 21, 2015 11:53
Show Gist options
  • Save AEnterprise/5a75cbd7e32ac36e70aa to your computer and use it in GitHub Desktop.
Save AEnterprise/5a75cbd7e32ac36e70aa to your computer and use it in GitHub Desktop.
package eureka.core;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.resources.IResource;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.client.FMLClientHandler;
/**
* Copyright (c) 2014-2015, AEnterprise
* http://buildcraftadditions.wordpress.com/
* Eureka is distributed under the terms of GNU GPL v3.0
* Please check the contents of the license located in
* http://buildcraftadditions.wordpress.com/wiki/licensing-stuff/
*/
public class TextGetter {
public static List<String> getText(String key){
return getText(key, FMLClientHandler.instance().getCurrentLanguage());
}
public static List<String> getText(String key, String lang) {
List<String> list = new ArrayList<String>();
ResourceLocation location = new ResourceLocation("eureka:localizations/" + lang + "/" + key + ".txt");
try {
IResource resource = FMLClientHandler.instance().getClient().getResourceManager().getResource(location);
InputStream stream = resource.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
String line = reader.readLine();
while (line != null) {
list.add(line);
line = reader.readLine();
}
reader.close();
} catch (Exception e) {
if (!lang.equals("en_US"))
return getText(key, "en_US");
}
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment