Record Class JsMessage

java.lang.Object
java.lang.Record
com.google.javascript.jscomp.JsMessage
Record Components:
getSourceName - Gets the message's sourceName.
getKey - Gets the message's key, or name (e.g. "MSG_HELLO").
getId - Gets the message's id, or name (e.g. "92430284230902938293").
getParts - Gets a read-only list of the parts of this message. Each part is either a String or a JsMessage.PlaceholderReference.
getAlternateId - Gets the message's alternate ID (e.g. "92430284230902938293"), if available. This will be used if a translation for `id` is not available.
getDesc - Gets the description associated with this message, intended to help translators, or null if this message has no description.
getMeaning - Gets the meaning annotated to the message, intended to force different translations.
jsPlaceholderNames - Gets a set of the registered placeholders in this message in lowerCamelCase format.

This is the format used in `goog.getMsg()` declarations.

canonicalPlaceholderNames - Gets a set of the registered placeholders in this message in UPPER_SNAKE_CASE format.

This is the format stored into XMB / XTB files and used in `declareIcuTemplate() declarations.


public record JsMessage(@Nullable String getSourceName, String getKey, boolean isAnonymous, boolean isExternal, String getId, com.google.common.collect.ImmutableList<JsMessage.Part> getParts, @Nullable String getAlternateId, @Nullable String getDesc, @Nullable String getMeaning, com.google.common.collect.ImmutableMap<String,String> getPlaceholderNameToExampleMap, com.google.common.collect.ImmutableMap<String,String> getPlaceholderNameToOriginalCodeMap, com.google.common.collect.ImmutableSet<String> jsPlaceholderNames, com.google.common.collect.ImmutableSet<String> canonicalPlaceholderNames) extends Record
A representation of a translatable message in JavaScript source code.

Instances are created using a JsMessage.Builder, like this:

 JsMessage m = new JsMessage.Builder(key)
     .appendPart("Hi ")
     .appendPlaceholderReference("firstName")
     .appendPart("!")
     .setDesc("A welcome message")
     .build();
 
  • Field Details

  • Constructor Details

    • JsMessage

      public JsMessage(@Nullable String getSourceName, String getKey, boolean isAnonymous, boolean isExternal, String getId, com.google.common.collect.ImmutableList<JsMessage.Part> getParts, @Nullable String getAlternateId, @Nullable String getDesc, @Nullable String getMeaning, com.google.common.collect.ImmutableMap<String,String> getPlaceholderNameToExampleMap, com.google.common.collect.ImmutableMap<String,String> getPlaceholderNameToOriginalCodeMap, com.google.common.collect.ImmutableSet<String> jsPlaceholderNames, com.google.common.collect.ImmutableSet<String> canonicalPlaceholderNames)
      Creates an instance of a JsMessage record class.
      Parameters:
      getSourceName - the value for the getSourceName record component
      getKey - the value for the getKey record component
      isAnonymous - the value for the isAnonymous record component
      isExternal - the value for the isExternal record component
      getId - the value for the getId record component
      getParts - the value for the getParts record component
      getAlternateId - the value for the getAlternateId record component
      getDesc - the value for the getDesc record component
      getMeaning - the value for the getMeaning record component
      getPlaceholderNameToExampleMap - the value for the getPlaceholderNameToExampleMap record component
      getPlaceholderNameToOriginalCodeMap - the value for the getPlaceholderNameToOriginalCodeMap record component
      jsPlaceholderNames - the value for the jsPlaceholderNames record component
      canonicalPlaceholderNames - the value for the canonicalPlaceholderNames record component
  • Method Details

    • getPlaceholderOriginalCode

      public String getPlaceholderOriginalCode(JsMessage.PlaceholderReference placeholderReference)
    • getPlaceholderExample

      public String getPlaceholderExample(JsMessage.PlaceholderReference placeholderReference)
    • asJsMessageString

      public String asJsMessageString()
      Returns a single string representing the message.

      In the returned string all placeholders are joined with the literal string parts in the form "literal string part {$jsPlaceholderName} more literal string", which is how placeholders are represented in `goog.getMsg()` text strings.

    • asIcuMessageString

      public final String asIcuMessageString()
      Returns a single string representing the message.

      In the returned string all placeholders are joined with the literal string parts in the form "literal string part {CANONICAL_PLACEHOLDER_NAME} more literal string", which is how placeholders are represented in ICU messages.

    • isEmpty

      public final boolean isEmpty()
      Returns:
      false iff the message is represented by empty string.
    • isLowerCamelCaseWithNumericSuffixes

      public static boolean isLowerCamelCaseWithNumericSuffixes(String input)
      Returns whether a string is nonempty, begins with a lowercase letter, and contains only digits and underscores after the first underscore.
    • toLowerCamelCaseWithNumericSuffixes

      public static String toLowerCamelCaseWithNumericSuffixes(String input)
      Converts the given string from upper-underscore case to lower-camel case, preserving numeric suffixes. For example: "NAME" -> "name" "A4_LETTER" -> "a4Letter" "START_SPAN_1_23" -> "startSpan_1_23".
    • isCanonicalPlaceholderNameFormat

      public static boolean isCanonicalPlaceholderNameFormat(String name)
      Is the name in the canonical format for placeholder names in XTB and XMB files.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • getSourceName

      public @Nullable String getSourceName()
      Returns the value of the getSourceName record component.
      Returns:
      the value of the getSourceName record component
    • getKey

      public String getKey()
      Returns the value of the getKey record component.
      Returns:
      the value of the getKey record component
    • isAnonymous

      public boolean isAnonymous()
      Returns the value of the isAnonymous record component.
      Returns:
      the value of the isAnonymous record component
    • isExternal

      public boolean isExternal()
      Returns the value of the isExternal record component.
      Returns:
      the value of the isExternal record component
    • getId

      public String getId()
      Returns the value of the getId record component.
      Returns:
      the value of the getId record component
    • getParts

      public com.google.common.collect.ImmutableList<JsMessage.Part> getParts()
      Returns the value of the getParts record component.
      Returns:
      the value of the getParts record component
    • getAlternateId

      public @Nullable String getAlternateId()
      Returns the value of the getAlternateId record component.
      Returns:
      the value of the getAlternateId record component
    • getDesc

      public @Nullable String getDesc()
      Returns the value of the getDesc record component.
      Returns:
      the value of the getDesc record component
    • getMeaning

      public @Nullable String getMeaning()
      Returns the value of the getMeaning record component.
      Returns:
      the value of the getMeaning record component
    • getPlaceholderNameToExampleMap

      public com.google.common.collect.ImmutableMap<String,String> getPlaceholderNameToExampleMap()
      Returns the value of the getPlaceholderNameToExampleMap record component.
      Returns:
      the value of the getPlaceholderNameToExampleMap record component
    • getPlaceholderNameToOriginalCodeMap

      public com.google.common.collect.ImmutableMap<String,String> getPlaceholderNameToOriginalCodeMap()
      Returns the value of the getPlaceholderNameToOriginalCodeMap record component.
      Returns:
      the value of the getPlaceholderNameToOriginalCodeMap record component
    • jsPlaceholderNames

      public com.google.common.collect.ImmutableSet<String> jsPlaceholderNames()
      Returns the value of the jsPlaceholderNames record component.
      Returns:
      the value of the jsPlaceholderNames record component
    • canonicalPlaceholderNames

      public com.google.common.collect.ImmutableSet<String> canonicalPlaceholderNames()
      Returns the value of the canonicalPlaceholderNames record component.
      Returns:
      the value of the canonicalPlaceholderNames record component