When I was just getting started with Eclipse, I often see some strange comments in the official example, for example: shell. settext (messages. getstring ("testref. Hello"); // $ NON-NLS-1 $
What exactly does this $ NON-NLS-1 $ represent? This problem was ignored after a while. Today, when reading rich client tutorial part 2, I accidentally discovered the true meaning of this line of comment ......
^_^ Is an unexpected result.
This is actually a method that supports i18n in eclipse. The standard structure of eclipse defines all string constants. properties, such as testref. hello is actually. A key testref in properties. hello = Hello
Now you may be able to guess the meaning of comments $ NON-NLS-1 $. I personally guess it may be the abbreviation of non-need localize string 1. In the RCP document, the string is described as follows:$NON-NLS-1$
Is a hint for both the compiler and the externalization wizard that the first character string on this line is a tag or Keyword of some sort and shoshould not be localized. that is, $ NON-NLS-1 $ indicates that the first string variable in the row is a tag or keyword and does not need to be localized
Testref. Java
Public class testref { Public static void main (string [] ARGs ){ Shell shell = new shell (); Shell. settext (messages. getstring ("testref. Hello"); // $ NON-NLS-1 $ } |
Messages. Java
Public class messages { Private Static final string bundle_name = "test"; // $ NON-NLS-1 $ Private Static final resourcebundle resource_bundle = resourcebundle. getbundle (bundle_name ); Private Messages (){ } Public static string getstring (string key ){ Try { Return resource_bundle.getstring (key ); } Catch (missingresourceexception e ){ Return '! '+ Key + '! '; } } } |
Test. Properties