Package com.google.javascript.jscomp
Class JsMessage
java.lang.Object
com.google.javascript.jscomp.JsMessage
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();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classContains functionality for creating JS messages.static interfaceID generatorstatic interfaceRepresents part of a message.static final classThrown when parsing a message string into parts fails because of a misformatted place holder.static classA reference to a placeholder in a translatable message.static classRepresents a literal string part of a message. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal StringReturns a single string representing the message.Returns a single string representing the message.abstract com.google.common.collect.ImmutableSet<String> Gets a set of the registered placeholders in this message in UPPER_SNAKE_CASE format.abstract @Nullable StringGets the message's alternate ID (e.g.abstract @Nullable StringgetDesc()Gets the description associated with this message, intended to help translators, or null if this message has no description.abstract StringgetId()Gets the message's id, or name (e.g.abstract StringgetKey()Gets the message's key, or name (e.g.abstract @Nullable StringGets the meaning annotated to the message, intended to force different translations.abstract com.google.common.collect.ImmutableList<JsMessage.Part> getParts()Gets a read-only list of the parts of this message.getPlaceholderExample(JsMessage.PlaceholderReference placeholderReference) getPlaceholderOriginalCode(JsMessage.PlaceholderReference placeholderReference) abstract @Nullable StringGets the message's sourceName.abstract booleanstatic booleanIs the name in the canonical format for placeholder names in XTB and XMB files.final booleanisEmpty()abstract booleanstatic booleanReturns whether a string is nonempty, begins with a lowercase letter, and contains only digits and underscores after the first underscore.abstract com.google.common.collect.ImmutableSet<String> Gets a set of the registered placeholders in this message in lowerCamelCase format.static StringConverts the given string from upper-underscore case to lower-camel case, preserving numeric suffixes.
-
Field Details
-
PH_JS_PREFIX
- See Also:
-
PH_JS_SUFFIX
- See Also:
-
-
Constructor Details
-
JsMessage
public JsMessage()
-
-
Method Details
-
getSourceName
Gets the message's sourceName. -
getKey
Gets the message's key, or name (e.g."MSG_HELLO"). -
isAnonymous
public abstract boolean isAnonymous() -
isExternal
public abstract boolean isExternal() -
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 aStringor aJsMessage.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. -
getPlaceholderNameToExampleMap
-
getPlaceholderNameToOriginalCodeMap
-
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.
-
getPlaceholderOriginalCode
-
getPlaceholderExample
-
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
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
Returns whether a string is nonempty, begins with a lowercase letter, and contains only digits and underscores after the first underscore. -
toLowerCamelCaseWithNumericSuffixes
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
Is the name in the canonical format for placeholder names in XTB and XMB files.
-