In Eclipse source code, I've found some '$NON-NLS-1$' in comments used like that :
在Eclipse源代码中,我发现了一些“$非nls -1$”的注释:
private String toolTip = ""; //$NON-NLS-1$
What does that mean ?
这是什么意思?
6 个解决方案
#1
341
They silence a warning that Eclipse emits when it encounters string literals (and has been configured to complain).
它们静默地警告Eclipse在遇到字符串文本时发出(并已配置为抱怨)。
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.
其思想是,UI消息不应该嵌入到字符串文本中,而是从资源文件中获取(这样它们就可以被翻译、校对等)。因此,可以配置Eclipse来检测字符串文本,这样您就不会意外地在代码中留下非外部化的UI字符串;但是,有一些字符串不应该外部化(例如regexp),所以//$ nonnls -1$提供了一种将这个事实与编译器通信的方法。
#2
49
The string is not translatable. It tells the Eclipse editor to not flag the string as unresourced. This is important for multilingual applications.
该字符串不可译。它告诉Eclipse编辑器不要将字符串标记为无资源。这对于多语言应用程序非常重要。
#3
15
NON-NLS
means Non-National Language Support.
Wikipedia proposes also Non-Native Language Support (NLS) but this last one is not very used.
非nls意味着非国家语言支持。*也提出了非本地语言支持(NLS),但这最后一项并不是很常用。
NLS is about internationalizing your application. Eclipse help to locate hard-coded strings in your code. To indicate a string is not part of the internationalization, append the comment //$NON-NLS-x$
where x is the position of the string. On the following example both "!"
are hard-coded strings not part of the internationalization:
NLS是关于国际化应用程序的。Eclipse有助于在代码中定位硬编码的字符串。要指出字符串不是国际化的一部分,请附加注释//$非nls -x$,其中x为字符串的位置。在下面的示例中,“!”是硬编码字符串,而不是国际化的一部分:
public String foo(String key) {
return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
}
Notes:
注:
- the leading
//
is necessary each time - 领导//是必要的每一次。
- no global
$NON-NLS$
for multiple strings within the same line
(e.g. if your line has six strings, you have to write six times//$NON-NLS-x$
) - 在同一行中,不需要为多个字符串提供全局$非nls $(例如,如果您的行有6个字符串,则必须写6次//$非nls -x$)
The book EMF: Eclipse Modeling Framework at page 250 says:
这本书的EMF: Eclipse建模框架在第250页说:
Non-NLS Markers— Eclipse's Java compiler has the ability to flag non-externalized strings as a warning or error, in order to facilitate enablement of National Language Support (NLS). EMF-generated code does not use hard coded strings for messages that the user will see; however, string literals do appear frequently, for example, as keys for lookup of externalized strings in a property file. This property controls whether to include comments that mark those literals as non-translatable, so that the compiler will not flag them.
非NLS标记——Eclipse的Java编译器有能力将非外部化的字符串标记为警告或错误,以便促进支持国家语言支持(NLS)。emf生成的代码不使用硬编码的字符串表示用户将看到的消息;但是,字符串常量经常出现,例如在属性文件中查找外部化字符串的键。该属性控制是否包含将这些文字标记为不可翻译的注释,这样编译器就不会标记它们。
For more details see also the pages The Generator GUI and How to Internationalize your Eclipse Plug-In.
有关更多细节,请参阅生成器GUI和如何国际化您的Eclipse插件的页面。
You can enable/disable this feature. On Eclipse Neon go toProject > Properties > Java Compiler > Errors/Warnings
and select the fieldNon-externalized strings (missing/unused $NON-NLS$ tag)
您可以启用/禁用此功能。在Eclipse Neon上,到项目>属性> Java编译器>错误/警告,并选择字段非外部化字符串(缺失/未使用$非nls $标签)
#4
14
If you are an Android developer. All strings the user may see should be in the resource file /res/values/strings.xml to read strings.xml file in the code you use R.string.. By adding the tag //$NON-NLS-$ you are noting that the string will not be seen by users.
如果你是Android开发者。用户可能看到的所有字符串都应该在资源文件/res/值/字符串中。xml读取字符串。使用R.string的代码中的xml文件。通过添加标签//$NON-NLS-$,您将注意到用户不会看到该字符串。
The warning in Eclipse Helios may be turned on at Window -> preferences -> java -> Compiler -> code style -> "Non-externalized Strings (missing/unused &NON-NLS$ tag)
.
Eclipse Helios的警告可能会在窗口->首选项-> java ->编译器->代码样式->“非外部化字符串(缺失/未使用和非nls $ tag)。
If you are planning on programming your activity to be multi-language, it would be recommended to turn this on. And then adding the &NON-NLS$ tag to strings that are internal to you activity. Eclipse will add &NON-NLS$ tag in the quick-fix if you right click on the warning or error.
如果您打算将您的活动编程为多语言,那么建议您打开它。然后将和非nls $标签添加到你活动的内部字符串。如果您右键单击警告或错误,Eclipse将在快速修复中添加&非nls $标记。
#5
9
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.
Eclipse使用它来指示字符串不需要翻译,可能是因为应用程序的用户看不到它。
#6
5
It tells the compiler not to complain about a non externalized string, and that it doesn't require localization.
它告诉编译器不要抱怨非外部化的字符串,它不需要本地化。
#1
341
They silence a warning that Eclipse emits when it encounters string literals (and has been configured to complain).
它们静默地警告Eclipse在遇到字符串文本时发出(并已配置为抱怨)。
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.
其思想是,UI消息不应该嵌入到字符串文本中,而是从资源文件中获取(这样它们就可以被翻译、校对等)。因此,可以配置Eclipse来检测字符串文本,这样您就不会意外地在代码中留下非外部化的UI字符串;但是,有一些字符串不应该外部化(例如regexp),所以//$ nonnls -1$提供了一种将这个事实与编译器通信的方法。
#2
49
The string is not translatable. It tells the Eclipse editor to not flag the string as unresourced. This is important for multilingual applications.
该字符串不可译。它告诉Eclipse编辑器不要将字符串标记为无资源。这对于多语言应用程序非常重要。
#3
15
NON-NLS
means Non-National Language Support.
Wikipedia proposes also Non-Native Language Support (NLS) but this last one is not very used.
非nls意味着非国家语言支持。*也提出了非本地语言支持(NLS),但这最后一项并不是很常用。
NLS is about internationalizing your application. Eclipse help to locate hard-coded strings in your code. To indicate a string is not part of the internationalization, append the comment //$NON-NLS-x$
where x is the position of the string. On the following example both "!"
are hard-coded strings not part of the internationalization:
NLS是关于国际化应用程序的。Eclipse有助于在代码中定位硬编码的字符串。要指出字符串不是国际化的一部分,请附加注释//$非nls -x$,其中x为字符串的位置。在下面的示例中,“!”是硬编码字符串,而不是国际化的一部分:
public String foo(String key) {
return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
}
Notes:
注:
- the leading
//
is necessary each time - 领导//是必要的每一次。
- no global
$NON-NLS$
for multiple strings within the same line
(e.g. if your line has six strings, you have to write six times//$NON-NLS-x$
) - 在同一行中,不需要为多个字符串提供全局$非nls $(例如,如果您的行有6个字符串,则必须写6次//$非nls -x$)
The book EMF: Eclipse Modeling Framework at page 250 says:
这本书的EMF: Eclipse建模框架在第250页说:
Non-NLS Markers— Eclipse's Java compiler has the ability to flag non-externalized strings as a warning or error, in order to facilitate enablement of National Language Support (NLS). EMF-generated code does not use hard coded strings for messages that the user will see; however, string literals do appear frequently, for example, as keys for lookup of externalized strings in a property file. This property controls whether to include comments that mark those literals as non-translatable, so that the compiler will not flag them.
非NLS标记——Eclipse的Java编译器有能力将非外部化的字符串标记为警告或错误,以便促进支持国家语言支持(NLS)。emf生成的代码不使用硬编码的字符串表示用户将看到的消息;但是,字符串常量经常出现,例如在属性文件中查找外部化字符串的键。该属性控制是否包含将这些文字标记为不可翻译的注释,这样编译器就不会标记它们。
For more details see also the pages The Generator GUI and How to Internationalize your Eclipse Plug-In.
有关更多细节,请参阅生成器GUI和如何国际化您的Eclipse插件的页面。
You can enable/disable this feature. On Eclipse Neon go toProject > Properties > Java Compiler > Errors/Warnings
and select the fieldNon-externalized strings (missing/unused $NON-NLS$ tag)
您可以启用/禁用此功能。在Eclipse Neon上,到项目>属性> Java编译器>错误/警告,并选择字段非外部化字符串(缺失/未使用$非nls $标签)
#4
14
If you are an Android developer. All strings the user may see should be in the resource file /res/values/strings.xml to read strings.xml file in the code you use R.string.. By adding the tag //$NON-NLS-$ you are noting that the string will not be seen by users.
如果你是Android开发者。用户可能看到的所有字符串都应该在资源文件/res/值/字符串中。xml读取字符串。使用R.string的代码中的xml文件。通过添加标签//$NON-NLS-$,您将注意到用户不会看到该字符串。
The warning in Eclipse Helios may be turned on at Window -> preferences -> java -> Compiler -> code style -> "Non-externalized Strings (missing/unused &NON-NLS$ tag)
.
Eclipse Helios的警告可能会在窗口->首选项-> java ->编译器->代码样式->“非外部化字符串(缺失/未使用和非nls $ tag)。
If you are planning on programming your activity to be multi-language, it would be recommended to turn this on. And then adding the &NON-NLS$ tag to strings that are internal to you activity. Eclipse will add &NON-NLS$ tag in the quick-fix if you right click on the warning or error.
如果您打算将您的活动编程为多语言,那么建议您打开它。然后将和非nls $标签添加到你活动的内部字符串。如果您右键单击警告或错误,Eclipse将在快速修复中添加&非nls $标记。
#5
9
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.
Eclipse使用它来指示字符串不需要翻译,可能是因为应用程序的用户看不到它。
#6
5
It tells the compiler not to complain about a non externalized string, and that it doesn't require localization.
它告诉编译器不要抱怨非外部化的字符串,它不需要本地化。