// Examples // {namespaces}/{lang}.json // {lang}/{namespace}/**/*.json // something/{lang}/{namespace}/**/*.* export function ParsePathMatcher(pathMatcher: string, exts = '') { let regstr = pathMatcher .replace(/\./g, '\\.') .replace('.*', '..*') .replace('*\\.', '.*\\.') .replace(/\/?\*\*\//g, '(?:.*/|^)') .replace('{locale}', '(?[\\w-_]+)') .replace('{locale?}', '(?[\\w-_]*?)') .replace('{namespace}', '(?[^/\\\\]+)') .replace('{namespace?}', '(?[^/\\\\]*?)') .replace('{namespaces}', '(?.+)') .replace('{namespaces?}', '(?.*?)') .replace('{ext}', `(?${exts})`) regstr = `^${regstr}$` return new RegExp(regstr) } export function ReplaceLocale(filepath: string, pathMatcher: string, locale: string, exts = '') { let regstr = pathMatcher .replace(/\./g, '\\.') .replace('.*', '..*') .replace('*\\.', '.*\\.') .replace(/\/?\*\*\//g, '(?:.*/|^)') .replace('{locale}', ')[\\w-_]+(') .replace('{namespace}', '(?:[^/\\\\]+)') .replace('{namespace?}', '(?:[^/\\\\]*?)') .replace('{namespaces}', '(?:.+)') .replace('{namespaces?}', '(?:.*?)') .replace('{ext}', `(?${exts})`) regstr = `^(${regstr})$` return filepath.replace(new RegExp(regstr), `$1${locale}$2`) }