Package com.google.javascript.jscomp
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 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.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();
-
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 final recordA reference to a placeholder in a translatable message.static final recordRepresents a literal string part of a message. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJsMessage(@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 aJsMessagerecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal StringReturns a single string representing the message.Returns a single string representing the message.com.google.common.collect.ImmutableSet<String> Returns the value of thecanonicalPlaceholderNamesrecord component.final booleanIndicates whether some other object is "equal to" this one.@Nullable StringReturns the value of thegetAlternateIdrecord component.@Nullable StringgetDesc()Returns the value of thegetDescrecord component.getId()Returns the value of thegetIdrecord component.getKey()Returns the value of thegetKeyrecord component.@Nullable StringReturns the value of thegetMeaningrecord component.com.google.common.collect.ImmutableList<JsMessage.Part> getParts()Returns the value of thegetPartsrecord component.getPlaceholderExample(JsMessage.PlaceholderReference placeholderReference) Returns the value of thegetPlaceholderNameToExampleMaprecord component.Returns the value of thegetPlaceholderNameToOriginalCodeMaprecord component.getPlaceholderOriginalCode(JsMessage.PlaceholderReference placeholderReference) @Nullable StringReturns the value of thegetSourceNamerecord component.final inthashCode()Returns a hash code value for this object.booleanReturns the value of theisAnonymousrecord component.static booleanIs the name in the canonical format for placeholder names in XTB and XMB files.final booleanisEmpty()booleanReturns the value of theisExternalrecord component.static booleanReturns whether a string is nonempty, begins with a lowercase letter, and contains only digits and underscores after the first underscore.com.google.common.collect.ImmutableSet<String> Returns the value of thejsPlaceholderNamesrecord component.static StringConverts the given string from upper-underscore case to lower-camel case, preserving numeric suffixes.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
PH_JS_PREFIX
- See Also:
-
PH_JS_SUFFIX
- See Also:
-
-
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 aJsMessagerecord class.- Parameters:
getSourceName- the value for thegetSourceNamerecord componentgetKey- the value for thegetKeyrecord componentisAnonymous- the value for theisAnonymousrecord componentisExternal- the value for theisExternalrecord componentgetId- the value for thegetIdrecord componentgetParts- the value for thegetPartsrecord componentgetAlternateId- the value for thegetAlternateIdrecord componentgetDesc- the value for thegetDescrecord componentgetMeaning- the value for thegetMeaningrecord componentgetPlaceholderNameToExampleMap- the value for thegetPlaceholderNameToExampleMaprecord componentgetPlaceholderNameToOriginalCodeMap- the value for thegetPlaceholderNameToOriginalCodeMaprecord componentjsPlaceholderNames- the value for thejsPlaceholderNamesrecord componentcanonicalPlaceholderNames- the value for thecanonicalPlaceholderNamesrecord component
-
-
Method Details
-
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. -
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
getSourceName
Returns the value of thegetSourceNamerecord component.- Returns:
- the value of the
getSourceNamerecord component
-
getKey
Returns the value of thegetKeyrecord component.- Returns:
- the value of the
getKeyrecord component
-
isAnonymous
public boolean isAnonymous()Returns the value of theisAnonymousrecord component.- Returns:
- the value of the
isAnonymousrecord component
-
isExternal
public boolean isExternal()Returns the value of theisExternalrecord component.- Returns:
- the value of the
isExternalrecord component
-
getId
Returns the value of thegetIdrecord component.- Returns:
- the value of the
getIdrecord component
-
getParts
Returns the value of thegetPartsrecord component.- Returns:
- the value of the
getPartsrecord component
-
getAlternateId
Returns the value of thegetAlternateIdrecord component.- Returns:
- the value of the
getAlternateIdrecord component
-
getDesc
Returns the value of thegetDescrecord component.- Returns:
- the value of the
getDescrecord component
-
getMeaning
Returns the value of thegetMeaningrecord component.- Returns:
- the value of the
getMeaningrecord component
-
getPlaceholderNameToExampleMap
Returns the value of thegetPlaceholderNameToExampleMaprecord component.- Returns:
- the value of the
getPlaceholderNameToExampleMaprecord component
-
getPlaceholderNameToOriginalCodeMap
Returns the value of thegetPlaceholderNameToOriginalCodeMaprecord component.- Returns:
- the value of the
getPlaceholderNameToOriginalCodeMaprecord component
-
jsPlaceholderNames
Returns the value of thejsPlaceholderNamesrecord component.- Returns:
- the value of the
jsPlaceholderNamesrecord component
-
canonicalPlaceholderNames
Returns the value of thecanonicalPlaceholderNamesrecord component.- Returns:
- the value of the
canonicalPlaceholderNamesrecord component
-