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,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACzD,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED,MAAM,CAAC,UAAS,MAAc;QAC7B,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAErC,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,yBAAyB,CAAC,CAAC;QACzD,CAAC;QAED,MAAM,CAAC,UAAU,CAAC;IACnB,CAAC,CAAC;AACH,CAAC,CAAC,EAAE,CAAC;AAEL;;;;;;;;;;;;GAYG;AACH,MAAM,yBAAyB,MAAc;IAC5C,MAAM,CAAC,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["// Matches an ISO 639.1/639.2 compatible language, followed by optional subtags.\nconst VALID_LOCALE_PATTERN = /^[a-z]{2,3}(-[a-z0-9\\-\\_]+)?$/i;\n\n/**\n * Retrieve a list of locales that can provide substitute for the specified locale\n * (including itself).\n *\n * For example, if 'fr-CA' is specified, then `[ 'fr', 'fr-CA' ]` is returned.\n *\n * @param locale\n * The target locale.\n *\n * @return\n * A list of locales that match the target locale.\n */\nexport function generateLocales(locale: string): string[] {\n\tconst normalized = normalizeLocale(locale);\n\tconst parts = normalized.split('-');\n\tlet current = parts[0];\n\tconst result: string[] = [current];\n\n\tfor (let i = 0; i < parts.length - 1; i += 1) {\n\t\tcurrent += '-' + parts[i + 1];\n\t\tresult.push(current);\n\t}\n\n\treturn result;\n}\n\n/**\n * Normalize a locale so that it can be converted to a bundle path.\n *\n * @param locale\n * The target locale.\n *\n * @return The normalized locale.\n */\nexport const normalizeLocale = (function() {\n\tfunction removeTrailingSeparator(value: string): string {\n\t\treturn value.replace(/(\\-|_)$/, '');\n\t}\n\n\tfunction normalize(locale: string): string {\n\t\tif (locale.indexOf('.') === -1) {\n\t\t\treturn removeTrailingSeparator(locale);\n\t\t}\n\n\t\treturn locale\n\t\t\t.split('.')\n\t\t\t.slice(0, -1)\n\t\t\t.map((part: string): string => {\n\t\t\t\treturn removeTrailingSeparator(part).replace(/_/g, '-');\n\t\t\t})\n\t\t\t.join('-');\n\t}\n\n\treturn function(locale: string): string {\n\t\tconst normalized = normalize(locale);\n\n\t\tif (!validateLocale(normalized)) {\n\t\t\tthrow new Error(`${normalized} is not a valid locale.`);\n\t\t}\n\n\t\treturn normalized;\n\t};\n})();\n\n/**\n * Validates that the provided locale at least begins with a ISO 639.1/639.2 comptabile language subtag,\n * and that any additional subtags contain only valid characters.\n *\n * While locales should adhere to the guidelines set forth by RFC 5646 (https://tools.ietf.org/html/rfc5646),\n * only the language subtag is strictly enforced.\n *\n * @param locale\n * The locale to validate.\n *\n * @return\n * `true` if the locale is valid; `false` otherwise.\n */\nexport function validateLocale(locale: string): boolean {\n\treturn VALID_LOCALE_PATTERN.test(locale);\n}\n"]}