views:

3933

answers:

5

In Eclipse source code, I've found some '$NON-NLS-1$' in comments used like that :

private String toolTip = ""; //$NON-NLS-1$

What does that mean ?

+11  A: 

The string is not translatable. It tells the Eclipse editor to not flag the string as unresourced. This is important for multilingual applications.

McDowell
+2  A: 

It tells the compiler not to complain about a non externalized string, and that it don't require localization.

Björn
I don't think it's the compiler, I think it's Eclipse that complains.
Paul Tomblin
Eclipse has it's own compiler as part of JDT which it uses for this kind of thing. So yes it is the compiler (Eclipse's compiler anyway).
Aaron Maenpaa
+2  A: 

It's used by Eclipse to indicate that a string doesn't need to be translated, probably because it's not going to be seen by the application's users.

Kees de Kooter
+25  A: 

They silence a warning that Eclipse emits when it encounters string literals (and has been configured to complain).

The idea is that UI messages should not be embedded as string literals, but rather sourced from a resource file (so that they can be translated, proofed, etc). Consequently, Eclipse can be configured to detect string literals, so that you don't accidentally have leave unexternalized UI strings in the code; however, there are strings which should not be externalized (such as regexps) and so, //$NON-NLS-1$ gives you a way to communicate that fact to the compiler.

Aaron Maenpaa
Ok, so, it is only on eclipse ? What about IntelliJ Idea or Netbeans ?
paulgreg
As far as I'm aware it's an Eclipse thing, though other IDEs may have picked it up.
Aaron Maenpaa
So, what does NLS stand for?
MatrixFrog
@MatrixFrog it seems to be "National Language Support", at least that's what it's referred to here: http://msdn.microsoft.com/en-us/library/ms906482.aspx
Daniel Dickison
A: 

Well, does anybody know what the last -N means, like in //$NON-NLS-1$ and //$NON-NLS-3$ ??

Michael Ustrup
McDowell
@Michael Ustrup - oops, you probably mean the digit - 1,2,3,etc. This is for when there's more than one string in the line.
McDowell