UNPKG

@readium/shared

Version:

Shared models to be used across other Readium projects and implementations in Typescript

49 lines (48 loc) 2.04 kB
/** * Represents a string with multiple translations indexed by a BCP 47 language tag. */ export declare class LocalizedString { readonly translations: { [key: string]: string; }; static readonly UNDEFINED_LANGUAGE = "undefined"; static readonly LANGUAGE_EN = "en"; /** * translations can be a string or a collection of language/translation pairs, * for a single string the language is assumed to be undefined */ constructor(translations: string | { [key: string]: string; }); /** * Parses a [LocalizedString] from its RWPM JSON representation. * * "anyOf": [ * { * "type": "string" * }, * { * "description": "The language in a language map must be a valid BCP 47 tag.", * "type": "object", * "patternProperties": { * "^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?<extension>[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?<privateUse>x(-[A-Za-z0-9]{1,8})+))?)|(?<privateUse2>x(-[A-Za-z0-9]{1,8})+))$": { * "type": "string" * } * }, * "additionalProperties": false, * "minProperties": 1 * } * ] */ static deserialize(json: any): undefined | LocalizedString; serialize(): any; /** * Returns the first translation for the given [language] BCP–47 tag. * If not found, then fallback: * 1. on the undefined language * 2. on the English language * 3. the first translation found * 4. returns empty string */ getTranslation(language?: string): string; }