laravel-i18n-react
Version:
A Vite plugin to load Laravel localization files and provide them to React applications.
31 lines (30 loc) • 1.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = resolver;
const recognizer_1 = __importDefault(require("./recognizer"));
/**
* Resolver the language file.
*
* @param files
* @param locale
*/
function resolver(files, locale) {
const { isJsonLocale, isPhpLocale, getJsonFile, getPhpFile } = (0, recognizer_1.default)(files);
const jsonLocale = isJsonLocale(locale) ? files[getJsonFile(locale)] : undefined;
const phpLocale = isPhpLocale(locale) ? files[getPhpFile(locale)] : undefined;
const getType = (obj) => Object.prototype.toString.call(obj);
if (['[object Promise]', '[object Module]'].includes(getType(jsonLocale)) ||
['[object Promise]', '[object Module]'].includes(getType(phpLocale))) {
return [jsonLocale ? jsonLocale : { default: {} }, phpLocale ? phpLocale : { default: {} }];
}
if (getType(jsonLocale) === '[object Object]' || getType(phpLocale) === '[object Object]') {
return [{ default: jsonLocale || {} }, { default: phpLocale || {} }];
}
if (getType(jsonLocale) === '[object Function]' || getType(phpLocale) === '[object Function]') {
return [jsonLocale ? jsonLocale() : { default: {} }, phpLocale ? phpLocale() : { default: {} }];
}
return [{ default: {} }, { default: {} }];
}