laravel-i18n-react
Version:
A Vite plugin to load Laravel localization files and provide them to React applications.
39 lines (38 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = recognizer;
/**
*
* @param files
*/
function recognizer(files) {
const jsonLocales = new Set();
const phpLocales = new Set();
const jsonFileLocales = {};
const phpFileLocales = {};
Object.keys(files).forEach((file) => {
const match = file.match(/.*\/(php_)?(.*)\.json$/);
if (match) {
const [, isPhp, locale] = match;
if (isPhp) {
phpLocales.add(locale);
phpFileLocales[locale] = file;
}
else {
jsonLocales.add(locale);
jsonFileLocales[locale] = file;
}
}
});
const locales = Array.from(new Set([...jsonLocales, ...phpLocales])).sort();
return {
isLocale: (locale) => locales.includes(locale),
getLocales: () => locales,
isJsonLocale: (locale) => jsonLocales.has(locale),
getJsonLocales: () => Array.from(jsonLocales).sort(),
isPhpLocale: (locale) => phpLocales.has(locale),
getPhpLocales: () => Array.from(phpLocales).sort(),
getJsonFile: (locale) => jsonFileLocales[locale],
getPhpFile: (locale) => phpFileLocales[locale]
};
}