Kwibble
Kwibble

Reputation: 45

How does Minecraft use their lang files?

I have always been fascinated with how they have done it, so I will know ask how.

An example lang file that minecraft uses looks like this:

options.stream.chat.enabled.streaming=Whilst Streaming
options.stream.chat.enabled.always=Always
options.stream.chat.enabled.never=Never
options.stream.chat.userFilter=User Filter
options.stream.chat.userFilter.all=All Viewers
options.stream.chat.userFilter.subs=Subscribers
options.stream.chat.userFilter.mods=Moderators
title.oldgl1=Old graphics card detected; this may prevent you from
title.oldgl2=playing in the future as OpenGL 2.0 will be required.
controls.title=Controls
controls.reset=Reset
controls.resetAll=Reset Keys
key.sprint=Sprint
key.forward=Walk Forwards
key.left=Strafe Left
key.back=Walk Backwards
key.right=Strafe Right
key.jump=Jump
key.inventory=Inventory

What I am asking is, how would I go about doing this code wise? Say, how would I get what is on the right hand side of the equals sign if I 'searched' key.right? How would I even search the file for that string in the first place?

Any help is appreciated, as this seems like a very useful thing to use for making config type files.

Thanks

Upvotes: 0

Views: 187

Answers (2)

Gimby
Gimby

Reputation: 5283

Properties are indeed one part of the whole; the actual whole is a bit of a forgotten term "i18n", which is a shorthand term for internationalization.

http://docs.oracle.com/javase/tutorial/i18n/

Unsurprisingly Java contains mechanisms to handle that and Minecraft likely makes use of it. Of course I'm not a Minecraft dev so I can only guess.

Upvotes: 0

Dmitry Ginzburg
Dmitry Ginzburg

Reputation: 7461

This is the default way to store some settings in Java, using Properties. This is just a HashTable, which can be used for getting some properties and it can be initialized from file this way:

Properties settings = new Properties();
settings.load(inputStream);

inputStream can be loaded by something like:

InputStream inputStream = new FileInputStream(fileName);

Upvotes: 2

Related Questions