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 class
Contains functionality for creating JS messages.static interface
ID generatorstatic interface
Represents part of a message.static final class
Thrown when parsing a message string into parts fails because of a misformatted place holder.static class
A reference to a placeholder in a translatable message.static class
Represents a literal string part of a message. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal String
Returns 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 String
Gets the message's alternate ID (e.g.abstract @Nullable String
getDesc()
Gets the description associated with this message, intended to help translators, or null if this message has no description.abstract String
getId()
Gets the message's id, or name (e.g.abstract String
getKey()
Gets the message's key, or name (e.g.abstract @Nullable String
Gets 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 String
Gets the message's sourceName.abstract boolean
static boolean
Is the name in the canonical format for placeholder names in XTB and XMB files.final boolean
isEmpty()
abstract boolean
static boolean
Returns 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 String
Converts 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 aString
or 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.
-