Class JsMessage.Builder

java.lang.Object
com.google.javascript.jscomp.JsMessage.Builder
Enclosing class:
JsMessage

public static final class JsMessage.Builder extends Object
Contains functionality for creating JS messages. Generates authoritative keys and fingerprints for a message that must stay constant over time.

This implementation correctly processes unnamed messages and creates a key for them that looks like MSG_<fingerprint value>;.

  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • getKey

      public String getKey()
      Gets the message's key (e.g. "MSG_HELLO").
    • setKey

      @CanIgnoreReturnValue public JsMessage.Builder setKey(String key)
      Parameters:
      key - a key that should uniquely identify this message; typically it is the message's name (e.g. "MSG_HELLO").
    • setSourceName

      @CanIgnoreReturnValue public JsMessage.Builder setSourceName(String sourceName)
      Parameters:
      sourceName - The message's sourceName.
    • appendPart

      @CanIgnoreReturnValue public JsMessage.Builder appendPart(JsMessage.Part part)
    • appendParts

      @CanIgnoreReturnValue public JsMessage.Builder appendParts(List<JsMessage.Part> parts)
    • appendJsPlaceholderReference

      @CanIgnoreReturnValue public JsMessage.Builder appendJsPlaceholderReference(String name)
      Appends a placeholder reference to the message.
      Parameters:
      name - placeholder name in the format used in JS code (lowerCamelCaseWithOptional_12_34)
    • appendCanonicalPlaceholderReference

      @CanIgnoreReturnValue public JsMessage.Builder appendCanonicalPlaceholderReference(String name)
      Appends a placeholder reference to the message.
      Parameters:
      name - placeholder name in the format used in XML files (UPPER_SNAKE_CASE_12_34)
    • appendStringPart

      @CanIgnoreReturnValue public JsMessage.Builder appendStringPart(String part)
      Appends a translatable string literal to the message.
    • setPlaceholderNameToExampleMap

      @CanIgnoreReturnValue public JsMessage.Builder setPlaceholderNameToExampleMap(Map<String,String> map)
    • setPlaceholderNameToOriginalCodeMap

      @CanIgnoreReturnValue public JsMessage.Builder setPlaceholderNameToOriginalCodeMap(Map<String,String> map)
    • setDesc

      @CanIgnoreReturnValue public JsMessage.Builder setDesc(@Nullable String desc)
      Sets the description of the message, which helps translators.
    • setMeaning

      @CanIgnoreReturnValue public JsMessage.Builder setMeaning(@Nullable String meaning)
      Sets the programmer-specified meaning of this message, which forces this message to translate differently.
    • setAlternateId

      @CanIgnoreReturnValue public JsMessage.Builder setAlternateId(@Nullable String alternateId)
      Sets the alternate message ID, to be used if the primary ID is not yet translated.
    • setIsAnonymous

      @CanIgnoreReturnValue public JsMessage.Builder setIsAnonymous(boolean isAnonymous)
    • setId

      @CanIgnoreReturnValue public JsMessage.Builder setId(String id)
    • setIsExternalMsg

      @CanIgnoreReturnValue public JsMessage.Builder setIsExternalMsg(boolean isExternalMsg)
    • hasParts

      public boolean hasParts()
      Gets whether at least one part has been appended.
    • getParts

      public List<JsMessage.Part> getParts()
    • build

      public JsMessage build()