MCPcopy Create free account
hub / github.com/5e-bits/5e-database / getLocaleFromFilepath

Function getLocaleFromFilepath

scripts/dbUtils.ts:90–100  ·  view source on GitHub ↗
(filepath: string)

Source from the content-addressed store, hash-verified

88 * @returns The locale string or null if no locale directory is present.
89 */
90export 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.

Callers 5

updateIndexCollectionFunction · 0.90
processFileUpdateFunction · 0.90
dbUtils.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected