I assume this question relates to a standalone application (command line, SWING, etc.), and not to a server application (with multiple users accessing simultaneously).
In a stand-alone application, it is easiest to create one static accessor class that will be responsible for loading a single resource package , and then searching for strings in that resource package.
Something like that:
public class ResourceUtil { private static ResourceBundle rb; static {
You can change the active language using the setLocale(Locale) method and access the translated strings using the tr(String,Object...) method.
Then you can call it from your class as follows:
import static ResourceUtil.tr; public String howBigIsTheFile(File f) { String name = f.getAbsolutePath(); long length = f.length(); return tr("The file %s is %d bytes long", name, length); }
Pay attention to static imports.
Disclaimer : All provided code is at the pseudo-code level and cannot be compiled.
Depending on the size of your application, it may be useful to use emergency support for IDE strings (for example, see the Eclipse JDT help chapter, I'm sure other IDEs have some similar features).
You can also use several resource packages and / or several static classes - this depends on the size of your application and your personal preferences. See this question for further discussion of this issue.
In a server environment that uses a static approach, such as the one above, a problem may occur because different users will have different locales. Depending on your webapp platform, you would solve this problem differently (for example, use MessageSource in Spring ).