8
votes

Does Java have an equivalent to .NET resource (.resx) files for localization?

In .NET, you can define resources as key-value pairs within a standard XML document.

The resource files are named according to the culture. For example:

myresources.resx

myresources.en-us.resx

myresources.fr-fr.resx

myresources.de-de.resx

Is there an equivalent in Java? Are the similar naming conventions used for files?

3

3 Answers

9
votes

The Java equivalent is called ResourceBundle. Resource Bundle are java properties file (with a .properties file extension that can be accessed using java.util.ResourceBundle class) that contains locale-specific data.

From your example,

myresources.resx
myresources.en-us.resx
myresources.fr-fr.resx
myresources.de-de.resx

Is equivalent to (in java)

myresources.properties
myresources_en_US.properties
myresources_fr_FR.properties
myresources_de_DE.properties

For Technical data on ResourceBundle check this Oracle article here: https://docs.oracle.com/javase/tutorial/i18n/resbundle/concept.html

2
votes

What you are looking for is ResourceBundles in Java. Here is a nice link