Package com.google.javascript.jscomp
Class JsMessage
- java.lang.Object
-
- com.google.javascript.jscomp.JsMessage
-
public abstract class JsMessage extends java.lang.ObjectA 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 Classes Modifier and Type Class Description static classJsMessage.BuilderContains functionality for creating JS messages.static interfaceJsMessage.IdGeneratorID generatorstatic interfaceJsMessage.PartRepresents part of a message.static classJsMessage.PlaceholderFormatExceptionThrown when parsing a message string into parts fails because of a misformatted place holder.static classJsMessage.PlaceholderReferenceA reference to a placeholder in a translatable message.static classJsMessage.StringPartRepresents a literal string part of a message.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPH_JS_PREFIXstatic java.lang.StringPH_JS_SUFFIX
-
Constructor Summary
Constructors Constructor Description JsMessage()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringasIcuMessageString()Returns a single string representing the message.java.lang.StringasJsMessageString()Returns a single string representing the message.abstract @Nullable java.lang.StringgetAlternateId()Gets the message's alternate ID (e.g.abstract @Nullable java.lang.StringgetDesc()Gets the description associated with this message, intended to help translators, or null if this message has no description.abstract java.lang.StringgetId()Gets the message's id, or name (e.g.abstract java.lang.StringgetKey()Gets the message's key, or name (e.g.abstract @Nullable java.lang.StringgetMeaning()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.java.lang.StringgetPlaceholderExample(JsMessage.PlaceholderReference placeholderReference)abstract com.google.common.collect.ImmutableMap<java.lang.String,java.lang.String>getPlaceholderNameToExampleMap()abstract com.google.common.collect.ImmutableMap<java.lang.String,java.lang.String>getPlaceholderNameToOriginalCodeMap()java.lang.StringgetPlaceholderOriginalCode(JsMessage.PlaceholderReference placeholderReference)abstract @Nullable java.lang.StringgetSourceName()Gets the message's sourceName.abstract booleanisAnonymous()static booleanisCanonicalPlaceholderNameFormat(java.lang.String name)Is the name in the canonical format for placeholder names in XTB and XMB files.booleanisEmpty()abstract booleanisExternal()abstract booleanisHidden()Gets whether this message should be hidden from volunteer translators (to reduce the chances of a new feature leak).static booleanisLowerCamelCaseWithNumericSuffixes(java.lang.String input)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<java.lang.String>jsPlaceholderNames()Gets a set of the registered placeholders in this message.static java.lang.StringtoLowerCamelCaseWithNumericSuffixes(java.lang.String input)Converts the given string from upper-underscore case to lower-camel case, preserving numeric suffixes.
-
-
-
Field Detail
-
PH_JS_PREFIX
public static final java.lang.String PH_JS_PREFIX
- See Also:
- Constant Field Values
-
PH_JS_SUFFIX
public static final java.lang.String PH_JS_SUFFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getSourceName
public abstract @Nullable java.lang.String getSourceName()
Gets the message's sourceName.
-
getKey
public abstract java.lang.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 java.lang.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 aStringor aJsMessage.PlaceholderReference.
-
getAlternateId
public abstract @Nullable java.lang.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 java.lang.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 java.lang.String getMeaning()
Gets the meaning annotated to the message, intended to force different translations.
-
isHidden
public abstract boolean isHidden()
Gets whether this message should be hidden from volunteer translators (to reduce the chances of a new feature leak).
-
getPlaceholderNameToExampleMap
public abstract com.google.common.collect.ImmutableMap<java.lang.String,java.lang.String> getPlaceholderNameToExampleMap()
-
getPlaceholderNameToOriginalCodeMap
public abstract com.google.common.collect.ImmutableMap<java.lang.String,java.lang.String> getPlaceholderNameToOriginalCodeMap()
-
jsPlaceholderNames
public abstract com.google.common.collect.ImmutableSet<java.lang.String> jsPlaceholderNames()
Gets a set of the registered placeholders in this message.
-
getPlaceholderOriginalCode
public java.lang.String getPlaceholderOriginalCode(JsMessage.PlaceholderReference placeholderReference)
-
getPlaceholderExample
public java.lang.String getPlaceholderExample(JsMessage.PlaceholderReference placeholderReference)
-
asJsMessageString
public java.lang.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 java.lang.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(java.lang.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 java.lang.String toLowerCamelCaseWithNumericSuffixes(java.lang.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(java.lang.String name)
Is the name in the canonical format for placeholder names in XTB and XMB files.
-
-