本文翻译自:What does $NON-NLS-1$ mean?
In Eclipse source code, I've found some '$NON-NLS-1$' in comments used like that : 在Eclipse源代码中,我发现在这样的评论中有一些'$ NON-NLS-1 $':
private String toolTip = ""; //$NON-NLS-1$
What does that mean ? 那是什么意思 ?
#1楼
参考:https://stackoom.com/question/2k8z/NON-NLS-是什么意思
#2楼
NON-NLS
means Non - N ational L anguage S upport . NON-NLS
指非 - N的憩大号 anguage 小号 upport。
Wikipedia proposes also Non - N ative L anguage S upport (NLS) but this last one is not very used. 维基百科的提议也非 - N的ative 大号 anguage 小号 upport(NLS),但是这最后一个不是很习惯。
NLS is about internationalizing your application. NLS旨在使您的应用程序国际化。 Eclipse help to locate hard-coded strings in your code. Eclipse有助于在代码中找到硬编码字符串。 To indicate a string is not part of the internationalization, append the comment //$NON-NLS-x$
where x is the position of the string. 要指示字符串不是国际化的一部分,请附加注释//$NON-NLS-x$
其中x是字符串的位置。 On the following example both "!"
在下面的例子中都是"!"
are hard-coded strings not part of the internationalization: 硬编码的字符串不是国际化的一部分:
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 同一行中的多个字符串没有全局$NON-NLS$
(eg if your line has six strings, you have to write six times//$NON-NLS-x$
) (例如,如果你的行有六个字符串,你必须写六次//$NON-NLS-x$
)
The book EMF: Eclipse Modeling Framework at page 250 says: EMF:Eclipse Modeling Framework一书第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). 非NLS标记 - Eclipse的Java编译器能够将非外化字符串标记为警告或错误,以便于启用国家语言支持(NLS)。 EMF-generated code does not use hard coded strings for messages that the user will see; EMF生成的代码不会将硬编码字符串用于用户将看到的消息; 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. 此属性控制是否包含将这些文字标记为不可翻译的注释,以便编译器不会标记它们。
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 to 在Eclipse Neon上去 Project > Properties > Java Compiler > Errors/Warnings
and select the field 并选择该字段 Non-externalized strings (missing/unused $NON-NLS$ tag)
#3楼
If you are an Android developer. 如果您是Android开发人员。 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. 用户可能看到的所有字符串都应该在资源文件/res/values/strings.xml中,以便在您使用R.string的代码中读取strings.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中的警告可以在Window -> preferences -> java -> Compiler -> code style -> "Non-externalized Strings (missing/unused &NON-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. 然后将&NON-NLS $标记添加到您活动内部的字符串中。 Eclipse will add &NON-NLS$ tag in the quick-fix if you right click on the warning or error. 如果右键单击警告或错误,Eclipse将在快速修复中添加&NON-NLS $标记。
#4楼
The string is not translatable. 字符串不可翻译。 It tells the Eclipse editor to not flag the string as unresourced. 它告诉Eclipse编辑器不要将字符串标记为unresourced。 This is important for multilingual applications. 这对多语言应用程序很重要。
#5楼
它告诉编译器不要抱怨非外化字符串,并且它不需要本地化。
#6楼
它被Eclipse用来表示字符串不需要翻译,可能是因为应用程序的用户不会看到它。