(filepath: string)
| 88 | * @returns The locale string or null if no locale directory is present. |
| 89 | */ |
| 90 | export function getLocaleFromFilepath(filepath: string): string | null { |
| 91 | const parts = filepath.split('/'); |
| 92 | const yearIdx = parts.findIndex((p) => YEAR_DIR_PATTERN.test(p)); |
| 93 | if (yearIdx < 0) return null; |
| 94 | const localeCandidate = parts[yearIdx + 1]; |
| 95 | if (!localeCandidate || !LOCALE_PATTERN.test(localeCandidate)) return null; |
| 96 | // Exclude structural dirs that match BCP 47 syntax but are not locales. |
| 97 | // 'en' is intentionally not in TRANSLATION_SKIP_DIRS — callers check locale === 'en'. |
| 98 | if (TRANSLATION_SKIP_DIRS.has(localeCandidate)) return null; |
| 99 | return localeCandidate; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Extracts the base index name from a JSON filename. |
no outgoing calls
no test coverage detected