Class: shaka.util.LanguageUtils

A set of language utility functions.

Constructor

new LanguageUtils()

A set of language utility functions.

Source:

Members

(private, static, constant, non-null) isoMap_ :Map.<string, string>

A map from 3-letter language codes (ISO 639-2) to 2-letter language codes (ISO 639-1) for all languages which have both in the registry.
Type:
  • Map.<string, string>
Source:

(static) MatchType :number

A match type for fuzzy-matching logic.
Type:
  • number
Properties:
Name Value Type Description
EXACT 0 number Accepts an exact match.
BASE_LANGUAGE_OKAY 1 number Accepts a less-specific version of the preferred sublanguage.
OTHER_SUB_LANGUAGE_OKAY 2 number Accepts a different sublanguage of the preferred base language.
Source:

Methods

(static) getLanguageForText(stream) → {string}

Get the normalized language of the given text stream. Will return 'und' if a language is not found on the text stream. This should always be used to get the language from a text stream.
Parameters:
Name Type Description
stream shaka.extern.Stream
Source:
Returns:
Type
string

(static) getLanguageForVariant(variant) → {string}

Get the normalized language of the given variant. This will look through the variant to find the language that represents the content in the variant. Will return 'und' if no language can be found. This should always be used to get the language from a variant.
Parameters:
Name Type Description
variant shaka.extern.Variant
Source:
Returns:
Type
string

(static) match(fuzz, preference, candidate) → {boolean}

Compares two language tags as defined by RFC 5646 and ISO 639. The comparison takes sublanguages into account via the |fuzz| parameter. The caller is expected to normalize the inputs first.
Parameters:
Name Type Description
fuzz shaka.util.LanguageUtils.MatchType What kind of match is acceptable.
preference string The user's preferred language tag.
candidate string An available language tag.
Source:
See:
  • shaka.util.LanguageUtils.normalize()
  • IETF RFC 5646
  • ISO 639
Returns:
Type
boolean

(static) normalize(code) → {string}

Normalize the language tag. Normalize the locales so that they appears as one of these two schemes: 1. ab 2. ab-XY Where "ab" is the language and "XY" is the region. RFC 5646 specifies that language tags are case insensitive and that the shortest representation of the base language should always be used. As part of normalization we will: - Convert language to lower-case - Convert 3-letter language codes (ISO 639-2) to 2-letter language codes (ISO 639-1). If the 3-letter code is not recognized, it will be left in its 3-letter form. - Convert region to upper-case.
Parameters:
Name Type Description
code string
Source:
See:
  • IETF RFC 5646
  • ISO 639
Returns:
Type
string