Eclipse 3.1 provides a new way to access resource files through the osgi. util. NLS class. The specific method is to construct an NLS subclass, as follows:
Public Class Mymessages Extends NLS {
Private Static Final String bundle_name = " Gr. schason. mymessages " ; // $ NON-NLS-1 $
Public StaticString hello_world;
Public StaticString hello_something;
Static{
//Initialize resource Bundles
NLS. initializemessages (bundle_name, mymessages.Class);
}
}
The content of the resource file is the same as before:
Hello_world = Hello World !
Hello_something = Hello { 0 } !
InProgramThe resource usage method is as follows:
System. Out. println (mymessages. hello_world );
System. Out. println (mymessages. BIND (mymessages. hello_something, " World " ));
In this wayCodeIt is a lot simpler, but the class generated by the externalize strings function provided by ECLIPSE jdt is still the previous method, rather than the NLS subclass.
Tip: Enter nls in the. Java file editor and then automatically complete (CTRL + space) to quickly generate the "// $ NON-NLS-N $" tag.
Original address (inaccessible, it seems to have been deleted)