@Retention(value=SOURCE) @Target(value={PACKAGE,TYPE,METHOD,CONSTRUCTOR,FIELD}) public static @interface NbBundle.Messages
The generated class will be called Bundle
and be in the same package.
Each key is placed in a Bundle.properties
file also in the same package,
and the helper class gets a method with the same name as the key
(converted to a valid Java identifier as needed)
which loads the key from the (possibly now localized) bundle using NbBundle.getMessage(Class, String)
.
The method will have as many arguments (of type Object
) as there are message format parameters.
It is an error to duplicate a key within a package, even if the duplicates are from different compilation units.
Example usage:
package some.where; import org.openide.util.NbBundle.Messages; import static some.where.Bundle.*; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; class Something { @Messages({ "dialog.title=Bad File", "# {0} - file path", "dialog.message=The file {0} was invalid." }) void showError(File f) { NotifyDescriptor d = new NotifyDescriptor.Message( dialog_message(f), NotifyDescriptor.ERROR_MESSAGE); d.setTitle(dialog_title()); DialogDisplayer.getDefault().notify(d); } }
which generates during compilation Bundle.java
:
class Bundle { static String dialog_title() {...} static String dialog_message(Object file_path) {...} }
and Bundle.properties
:
dialog.title=Bad File # {0} - file path dialog.message=The file {0} was invalid.
public abstract String[] value
key=Some Value
.
Anything is permitted in the value, including newlines.
Unlike in a properties file, there should be no whitespace before the key or around the equals sign.
Values containing {0}
etc. are assumed to be message formats and so may need escapes for metacharacters such as '
.
A line may also be a comment if it starts with #
, which may be useful for translators;
it is recommended to use the format # {0} - summary of param
.