Class JsMessage

java.lang.Object
com.google.javascript.jscomp.JsMessage

public abstract class JsMessage extends Object
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()
  • Method Details

    • getSourceName

      public abstract @Nullable String getSourceName()
      Gets the message's sourceName.
    • getKey

      public abstract String getKey()
      Gets the message's key, or name (e.g. "MSG_HELLO").
    • isAnonymous

      public abstract boolean isAnonymous()
    • isExternal

      public abstract boolean isExternal()
    • getId

      public abstract String getId()
      Gets the message's id, or name (e.g. "92430284230902938293").
    • getParts

      public abstract com.google.common.collect.ImmutableList<JsMessage.Part> getParts()
      Gets a read-only list of the parts of this message. Each part is either a String or a JsMessage.PlaceholderReference.
    • getAlternateId

      public abstract @Nullable String 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

      public abstract @Nullable String getDesc()
      Gets the description associated with this message, intended to help translators, or null if this message has no description.
    • getMeaning

      public abstract @Nullable String getMeaning()
      Gets the meaning annotated to the message, intended to force different translations.
    • getPlaceholderNameToExampleMap

      public abstract com.google.common.collect.ImmutableMap<String,String> getPlaceholderNameToExampleMap()
    • getPlaceholderNameToOriginalCodeMap

      public abstract com.google.common.collect.ImmutableMap<String,String> getPlaceholderNameToOriginalCodeMap()
    • jsPlaceholderNames

      public abstract com.google.common.collect.ImmutableSet<String> jsPlaceholderNames()
      Gets a set of the registered placeholders in this message in lowerCamelCase format.

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

    • canonicalPlaceholderNames

      public abstract com.google.common.collect.ImmutableSet<String> 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.

    • 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.