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 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.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 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 final record
A reference to a placeholder in a translatable message.static final record
Represents 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 aJsMessage
record class. -
Method Summary
Modifier and TypeMethodDescriptionfinal String
Returns a single string representing the message.Returns a single string representing the message.com.google.common.collect.ImmutableSet
<String> Returns the value of thecanonicalPlaceholderNames
record component.final boolean
Indicates whether some other object is "equal to" this one.@Nullable String
Returns the value of thegetAlternateId
record component.@Nullable String
getDesc()
Returns the value of thegetDesc
record component.getId()
Returns the value of thegetId
record component.getKey()
Returns the value of thegetKey
record component.@Nullable String
Returns the value of thegetMeaning
record component.com.google.common.collect.ImmutableList
<JsMessage.Part> getParts()
Returns the value of thegetParts
record component.getPlaceholderExample
(JsMessage.PlaceholderReference placeholderReference) Returns the value of thegetPlaceholderNameToExampleMap
record component.Returns the value of thegetPlaceholderNameToOriginalCodeMap
record component.getPlaceholderOriginalCode
(JsMessage.PlaceholderReference placeholderReference) @Nullable String
Returns the value of thegetSourceName
record component.final int
hashCode()
Returns a hash code value for this object.boolean
Returns the value of theisAnonymous
record component.static boolean
Is the name in the canonical format for placeholder names in XTB and XMB files.final boolean
isEmpty()
boolean
Returns the value of theisExternal
record component.static boolean
Returns 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 thejsPlaceholderNames
record component.static String
Converts the given string from upper-underscore case to lower-camel case, preserving numeric suffixes.final String
toString()
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 aJsMessage
record class.- Parameters:
getSourceName
- the value for thegetSourceName
record componentgetKey
- the value for thegetKey
record componentisAnonymous
- the value for theisAnonymous
record componentisExternal
- the value for theisExternal
record componentgetId
- the value for thegetId
record componentgetParts
- the value for thegetParts
record componentgetAlternateId
- the value for thegetAlternateId
record componentgetDesc
- the value for thegetDesc
record componentgetMeaning
- the value for thegetMeaning
record componentgetPlaceholderNameToExampleMap
- the value for thegetPlaceholderNameToExampleMap
record componentgetPlaceholderNameToOriginalCodeMap
- the value for thegetPlaceholderNameToOriginalCodeMap
record componentjsPlaceholderNames
- the value for thejsPlaceholderNames
record componentcanonicalPlaceholderNames
- the value for thecanonicalPlaceholderNames
record 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 thegetSourceName
record component.- Returns:
- the value of the
getSourceName
record component
-
getKey
Returns the value of thegetKey
record component.- Returns:
- the value of the
getKey
record component
-
isAnonymous
public boolean isAnonymous()Returns the value of theisAnonymous
record component.- Returns:
- the value of the
isAnonymous
record component
-
isExternal
public boolean isExternal()Returns the value of theisExternal
record component.- Returns:
- the value of the
isExternal
record component
-
getId
Returns the value of thegetId
record component.- Returns:
- the value of the
getId
record component
-
getParts
Returns the value of thegetParts
record component.- Returns:
- the value of the
getParts
record component
-
getAlternateId
Returns the value of thegetAlternateId
record component.- Returns:
- the value of the
getAlternateId
record component
-
getDesc
Returns the value of thegetDesc
record component.- Returns:
- the value of the
getDesc
record component
-
getMeaning
Returns the value of thegetMeaning
record component.- Returns:
- the value of the
getMeaning
record component
-
getPlaceholderNameToExampleMap
Returns the value of thegetPlaceholderNameToExampleMap
record component.- Returns:
- the value of the
getPlaceholderNameToExampleMap
record component
-
getPlaceholderNameToOriginalCodeMap
Returns the value of thegetPlaceholderNameToOriginalCodeMap
record component.- Returns:
- the value of the
getPlaceholderNameToOriginalCodeMap
record component
-
jsPlaceholderNames
Returns the value of thejsPlaceholderNames
record component.- Returns:
- the value of the
jsPlaceholderNames
record component
-
canonicalPlaceholderNames
Returns the value of thecanonicalPlaceholderNames
record component.- Returns:
- the value of the
canonicalPlaceholderNames
record component
-