MCPcopy Index your code
hub / github.com/formatjs/formatjs / getFallbackCandidates

Function getFallbackCandidates

packages/intl-localematcher/abstract/utils.ts:269–281  ·  view source on GitHub ↗

* Generates fallback candidates by progressively removing subtags * e.g., "en-US" -> ["en-US", "en"] * "zh-Hans-CN" -> ["zh-Hans-CN", "zh-Hans", "zh"]

(locale: string)

Source from the content-addressed store, hash-verified

267 * "zh-Hans-CN" -> ["zh-Hans-CN", "zh-Hans", "zh"]
268 */
269function getFallbackCandidates(locale: string): string[] {
270 const candidates: string[] = []
271 let current = locale
272
273 while (current) {
274 candidates.push(current)
275 const lastDash = current.lastIndexOf('-')
276 if (lastDash === -1) break
277 current = current.substring(0, lastDash)
278 }
279
280 return candidates
281}
282
283/**
284 * Finds the best locale match using a three-tier optimization hierarchy.

Callers 1

findBestMatchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected