-
@Target({PACKAGE,TYPE}) @Retention(SOURCE) @Repeatable(uk.autores.repeat.RepeatableMessages.class) public @interface Messages
Directive to generate localized format methods from
Properties
files.// EXAMPLE ANNOTATION // planets.properties // planet-event=At {1,time} on {1,date}, there was {2} on planet {0,number,integer}. // planets_de.properties // planet-event=Am {1,time} um {1,date} Uhr gab es {2} auf Planet {0,number,integer}. @Messages("planets.properties")
// EXAMPLE CODE var time = ZonedDateTime.now(); String event = Planets.planetEvent(locale, 4, time, "an attack");
See Backing a
ResourceBundle
with Properties Files for more information on localization.This annotation is strict by default. This helps build systems detect missing translations and bugs in translated format strings. However, developers are likely add or modify strings during development before translations are available. The
missingKey()
andincompatibleFormat()
properties can be set toSeverity.WARN
orSeverity.IGNORE
during development to avoid breaking builds. Create a singlestatic final Severity
variable and reference it in annotations to control this globally. Set these toSeverity.ERROR
prior to release and/or in a "smoke test" branch.
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description Class<? extends TemporalAccessor>
dateTimeType
Signature type where format expression is date/time type.boolean
format
Treat values asMessageFormat
expressions and generate typed method format methods.Severity
incompatibleFormat
How to handle incompatible format string in localized files.boolean
localize
Search for localized properties.Severity
missingKey
How to handle missing keys in localized files.Class<?>
noneType
Signature type where format expression has no type.Class<? extends Number>
numberType
Signature type where format expression is "number" or "choice" type.Processing
processing
Common processing instructions.String[]
value
Resource files.Visibility
visibility
Generated code visibility.
-
-
-
Element Detail
-
value
String[] value
Resource files.- Returns:
- resources
- Default:
- {}
-
-
-
processing
Processing processing
Common processing instructions.- Returns:
- instruction annotation
- Default:
- @uk.autores.Processing(namer=uk.autores.naming.IdiomaticNamer.class)
-
-
-
visibility
Visibility visibility
Generated code visibility.- Returns:
- visibility
- Default:
- uk.autores.Visibility.PACKAGE
-
-
-
format
boolean format
Treat values asMessageFormat
expressions and generate typed method format methods.- Returns:
- whether to format
- Default:
- true
-
-
-
missingKey
Severity missingKey
How to handle missing keys in localized files. Only applies whenlocalize()
is true.- Returns:
- error severity
- Default:
- uk.autores.Severity.ERROR
-
-
-
noneType
Class<?> noneType
Signature type where format expression has no type. Set this to broaden toObject.toString()
or narrow toString
.- Returns:
- type used in generated methods
- Default:
- java.lang.CharSequence.class
-
-
-
dateTimeType
Class<? extends TemporalAccessor> dateTimeType
Signature type where format expression is date/time type. Set this to relax rules on input. Using inappropriateTemporalAccessor
types with some expressions can result inDateTimeException
.- Returns:
- type used in generated methods
- Default:
- java.time.ZonedDateTime.class
-
-