i18n.MessageFormat Extends
Constructor of MessageFormat.

Inheritance

Constructor

goog.i18n.MessageFormat(pattern)

Parameters

pattern : string
The pattern we parse and apply positional parameters to.

Instance Methods

Public Protected Private
buildPlaceholder_(literals) string
Builds a placeholder from the last index of the array.
Arguments:
literals : !Array
All literals encountered during parse.
Returns: string  \uFDDF_ + last index + _.
code »
extractParts_(pattern) !Array.<Object>
Breaks pattern into strings and top level {...} blocks.
Arguments:
pattern : string
(sub)Pattern to be broken.
Returns: !Array.<Object>  Each item is {type, value}.
code »
format(namedParameters) string
Formats a message, treating '#' with special meaning representing the number (plural_variable - offset).
Arguments:
namedParameters : !Object
Parameters that either influence the formatting or are used as actual data. I.e. in call to fmt.format({'NUM_PEOPLE': 5, 'NAME': 'Angela'}), object {'NUM_PEOPLE': 5, 'NAME': 'Angela'} holds positional parameters. 1st parameter could mean 5 people, which could influence plural format, and 2nd parameter is just a data to be printed out in proper position.
Returns: string  Formatted message.
code »
formatBlock_(parsedPatternnamedParametersignorePoundresult)
Parses generic block and returns a formatted string.
Arguments:
parsedPattern : !Array.<!Object>
Holds parsed tree.
namedParameters : !Object
Parameters that either influence the formatting or are used as actual data.
ignorePound : boolean
If true, treat '#' in plural messages as a literary character, else treat it as an ICU syntax character, resolving to the number (plural_variable - offset).
result : !Array.<!string>
Each formatting stage appends its product to the result.
code »
formatIgnoringPound(namedParameters) string
Formats a message, treating '#' as literary character.
Arguments:
namedParameters : !Object
Parameters that either influence the formatting or are used as actual data. I.e. in call to fmt.format({'NUM_PEOPLE': 5, 'NAME': 'Angela'}), object {'NUM_PEOPLE': 5, 'NAME': 'Angela'} holds positional parameters. 1st parameter could mean 5 people, which could influence plural format, and 2nd parameter is just a data to be printed out in proper position.
Returns: string  Formatted message.
code »
formatPluralOrdinalBlock_(parsedPatternnamedParameterspluralSelectorignorePoundresult)
Formats plural or selectordinal block. Only one option is selected and all # are replaced.
Arguments:
parsedPattern : !Object
JSON object containing plural block info.
namedParameters : !Object
Parameters that either influence the formatting or are used as actual data.
pluralSelector : !function(number, number=):string
A select function from goog.i18n.pluralRules or goog.i18n.ordinalRules which determines which plural/ordinal form to use based on the input number's cardinality.
ignorePound : boolean
If true, treat '#' in plural messages as a literary character, else treat it as an ICU syntax character, resolving to the number (plural_variable - offset).
result : !Array.<!string>
Each formatting stage appends its product to the result.
code »
formatSelectBlock_(parsedPatternnamedParametersignorePoundresult)
Formats select block. Only one option is selected.
Arguments:
parsedPattern : !Object
JSON object containing select block info.
namedParameters : !Object
Parameters that either influence the formatting or are used as actual data.
ignorePound : boolean
If true, treat '#' in plural messages as a literary character, else treat it as an ICU syntax character, resolving to the number (plural_variable - offset).
result : !Array.<!string>
Each formatting stage appends its product to the result.
code »
formatSimplePlaceholder_(parsedPatternnamedParametersresult)
Formats simple placeholder.
Arguments:
parsedPattern : !Object
JSON object containing placeholder info.
namedParameters : !Object
Parameters that are used as actual data.
result : !Array.<!string>
Each formatting stage appends its product to the result.
code »
format_(namedParametersignorePound) string
Formats a message.
Arguments:
namedParameters : !Object
Parameters that either influence the formatting or are used as actual data. I.e. in call to fmt.format({'NUM_PEOPLE': 5, 'NAME': 'Angela'}), object {'NUM_PEOPLE': 5, 'NAME': 'Angela'} holds positional parameters. 1st parameter could mean 5 people, which could influence plural format, and 2nd parameter is just a data to be printed out in proper position.
ignorePound : boolean
If true, treat '#' in plural messages as a literary character, else treat it as an ICU syntax character, resolving to the number (plural_variable - offset).
Returns: string  Formatted message.
code »
insertPlaceholders_(pattern) string
Replaces string literals with literal placeholders. Literals are string of the form '}...', '{...' and '#...' where ... is set of characters not containing ' Builds a dictionary so we can recover literals during format phase.
Arguments:
pattern : string
Pattern to clean up.
Returns: string  Pattern with literals replaced with placeholders.
code »
parseBlockType_(pattern) goog.i18n.MessageFormat.BlockType_
Detects which type of a block is the pattern.
Arguments:
pattern : string
Content of the block.
Returns: goog.i18n.MessageFormat.BlockType_  One of the block types.
code »
parseBlock_(pattern) !Array.<!Object>
Parses generic block.
Arguments:
pattern : string
Content of the block to parse.
Returns: !Array.<!Object>  Subblocks marked as strings, select...
code »
parseOrdinalBlock_(pattern) !Object
Parses an ordinal type of a block and produces JSON object for it. For example the input string: '{FOO, selectordinal, one {Message A}other {Message B}}' Should result in the output object: { argumentIndex: 'FOO', argumentOffest: 0, one: [ { type: 4, value: 'Message A' } ], other: [ { type: 4, value: 'Message B' } ] }
Arguments:
pattern : string
Subpattern that needs to be parsed as plural pattern.
Returns: !Object  Object with select block info.
code »
parsePattern_(pattern)
Parses input pattern into an array, for faster reformatting with different input parameters. Parsing is locale independent.
Arguments:
pattern : string
MessageFormat pattern to parse.
code »
parsePluralBlock_(pattern) !Object
Parses a plural type of a block and produces JSON object for it.
Arguments:
pattern : string
Subpattern that needs to be parsed as plural pattern.
Returns: !Object  Object with select block info.
code »
parseSelectBlock_(pattern) !Object
Parses a select type of a block and produces JSON object for it.
Arguments:
pattern : string
Subpattern that needs to be parsed as select pattern.
Returns: !Object  Object with select block info.
code »

Instance Properties

literals_ :
All encountered literals during parse stage. Indices tell us the order of replacement.
Code »
numberFormatter_ : goog.i18n.NumberFormat
Locale aware number formatter.
Code »
parsedPattern_ :
Input pattern gets parsed into objects for faster formatting.
Code »

Static Properties

goog.i18n.MessageFormat.LITERAL_PLACEHOLDER_ :
Literal strings, including '', are replaced with \uFDDF_x_ for parsing purposes, and recovered during format phase. \uFDDF is a Unicode nonprinting character, not expected to be found in the typical message.
Code »
goog.i18n.MessageFormat.ORDINAL_BLOCK_RE_ :
A regular expression to parse the ordinal block, extracting the argument index.
Code »
goog.i18n.MessageFormat.OTHER_ :
Mandatory option in both select and plural form.
Code »
goog.i18n.MessageFormat.PLURAL_BLOCK_RE_ :
A regular expression to parse the plural block, extracting the argument index and offset (if any).
Code »
goog.i18n.MessageFormat.REGEX_DOUBLE_APOSTROPHE_ :
Regular expression for looking for '' in the message.
Code »
goog.i18n.MessageFormat.REGEX_LITERAL_ :
Regular expression for looking for string literals.
Code »
goog.i18n.MessageFormat.SELECT_BLOCK_RE_ :
A regular expression to parse the select block, extracting the argument index.
Code »

Enumerations

goog.i18n.MessageFormat.BlockType_ :
Block type.
Constants:
ORDINAL
No description.
PLURAL
No description.
SELECT
No description.
SIMPLE
No description.
STRING
No description.
UNKNOWN
No description.
Code »
goog.i18n.MessageFormat.Element_ :
Marks a string and block during parsing.
Constants:
BLOCK
No description.
STRING
No description.
Code »

Package i18n

Package Reference