How to handle language pack

Hi guys,
in the game that I am developing I need to have things like item descriptions, spell tooltips etc I don’t know how to handle these texts.
I gues it is a bad idea to save them as static string in the various classes, isn’t it? :frowning:
Maybe I should have a different jar containing only these texts (I guess it is also useful to implement different language packs)
Who can help me? ???

At its most basic, a Map of languages to phrases is what you’re looking for. Something like:

Map<String, String> helloMap = new HashMap<String, String>();
helloMap.put("english", "hello");
helloMap.put("spanish", "hola");
helloMap.put("french", "bonjour");

String language = "spanish";
System.out.println(helloMap.get(language));

Of course, there are any number of ways to organize this kind of data structure- using enums instead of Strings for the languages, using a multimap, etc.

Whether you store that data in a jar or a properties file or a serialized object or something else is completely up to you, and which direction you go really depends on your context. There isn’t a “correct” answer here.

I dont know what device you are focusing.
But maybe ResourceBundles are what you are looking for.
http://docs.oracle.com/javase/tutorial/i18n/intro/

-ClaasJG

You could also save each language string map in a properties file and just have a class like this:

public class LanguageFile {

	private Properties properties;

	public LanguageFile(File file) {
		properties = new Properties();
		properties.load(new FileInputStream(file));
	}

	public String getTranslation(String key) {
		return properties.getProperty(key);
	}

}

[quote]Of course, there are any number of ways to organize this kind of data structure- using enums instead of Strings for the languages, using a multimap, etc.
[/quote]
I like you solution, I will test it very soon :slight_smile:

I also like this one, I can try both and see which is better for me.

Thank you guys ;D