* 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)
| 267 | * "zh-Hans-CN" -> ["zh-Hans-CN", "zh-Hans", "zh"] |
| 268 | */ |
| 269 | function 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. |