Annotation Type Messages.AlternateMessage

Enclosing interface:
Messages

@Retention(RUNTIME) @Target(METHOD) @Documented public static @interface Messages.AlternateMessage
Provides alternate forms of a message, such as are needed when plural forms are used or a placeholder has known gender. The selection of which form to use is based on the value of the arguments marked PluralCount and/or Select.

Example:

   @DefaultMessage("You have {0} widgets.")
   @AlternateMessage({"one", "You have one widget.")
   String example(@PluralCount int count);
 

If multiple Messages.PluralCount or Messages.Select parameters are supplied, the forms for each, in the order they appear in the parameter list, are supplied separated by a vertical bar ("|"). Example:

   @DefaultMessage("You have {0} messages and {1} notifications.")
   @AlternateMessage({
       "=0|=0", "You have no messages or notifications."
       "=0|one", "You have a notification."
       "one|=0", "You have a message."
       "one|one", "You have one message and one notification."
       "other|one", "You have {0} messages and one notification."
       "one|other", "You have one message and {1} notifications."
   })
   String messages(@PluralCount int msgCount,
       @PluralCount int notifyCount);
 
Note that the number of permutations can grow quickly, and that the default message is used when every Messages.PluralCount or Messages.Select would use the "other" value.

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    An array of pairs of strings containing the strings for different forms.
  • Element Details

    • value

      String[] value
      An array of pairs of strings containing the strings for different forms. Each pair is the name of a form followed by the string in the source locale for that form. Each form name is the name of a plural form if Messages.PluralCount is used, or the matching value if Messages.Select is used. An example for a locale that has "none", "one", and "other" plural forms:
       @DefaultMessage("{0} widgets")
       @AlternateMessage({"none", "No widgets", "one", "One widget"})
       
      Note that the plural form "other" gets the translation specified in @DefaultMessage, as does any @Select value not listed. If more than one way of selecting a translation exists, they will be combined, separated with |, in the order they are supplied as arguments in the method. For example:
         @DefaultMessage("{0} gave away their {2} widgets")
         @AlternateMesssage({
           "MALE|other", "{0} gave away his {2} widgets",
           "FEMALE|other", "{0} gave away her {2} widgets",
           "MALE|one", "{0} gave away his widget",
           "FEMALE|one", "{0} gave away her widget",
           "other|one", "{0} gave away their widget",
         })
         String giveAway(String name, @Select Gender gender,
             @PluralCount int count);